Advertisement
Foxscotch

relatively fortunate code

Oct 19th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. @require_http_methods(['GET'])
  2. def list_filter(request):
  3.     conversions = {'date': 'date',
  4.                    'plant': 'plant',
  5.                    'model': 'part__model__name',
  6.                    'part': 'part__number',
  7.                    'defect': 'defects__name',
  8.                    'qty': 'quantity',
  9.                    'shift': 'shift',
  10.                    'station': 'station',
  11.                    'rej_by': 'rejected_by',
  12.                    'location': 'location',
  13.                    'dispo': 'evaluation__disposition'}
  14.     rejections = Rejection.objects.all()
  15.     get_is_useful = False
  16.     for param, val in request.GET.lists():
  17.         if param in conversions:
  18.             get_is_useful = True
  19.             rejections = rejections.filter(**{conversions[param] + '__in': val})
  20.     if get_is_useful:
  21.         title = get_title('Filter')
  22.         context = {'rejections': rejections,
  23.                    'title': title}
  24.         return render(request, 'defective/taglist.html', context)
  25.     else:
  26.         models = Model.objects.all()
  27.         parts = Part.objects.all()
  28.         defects = Defect.objects.all()
  29.         context = {'models': models,
  30.                    'parts': parts,
  31.                    'defects': defects,
  32.                    'rej': Rejection,
  33.                    'eval': Evaluation,
  34.                    'title': get_title('Filter')}
  35.         return render(request, 'defective/filterform.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement