Advertisement
Foxscotch

unfortunate code

Oct 16th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.04 KB | None | 0 0
  1. @require_http_methods(['GET'])
  2. def list_filter(request):
  3.     by_what = request.GET.get('by', '')
  4.     for_what = request.GET.getlist('for', '')
  5.     if by_what == 'date':
  6.         try:
  7.             dates = []
  8.             for date in for_what:
  9.                 dates.append(datetime.strptime(date, '%m/%d/%Y'))
  10.             rejections = Rejection.objects.filter(date__in=dates)
  11.             title = get_title('Filter by {0} on {1}'.format(by_what, for_what[0]))
  12.             context = {'rejections': rejections,
  13.                        'title': title}
  14.             return render(request, 'defective/taglist.html', context)
  15.         except ValueError:
  16.             return HttpResponseBadRequest('Invalid date format')
  17.     elif by_what == 'plant':
  18.         rejections = Rejection.objects.filter(plant__in=for_what)
  19.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  20.         context = {'rejections': rejections,
  21.                    'title': title}
  22.         return render(request, 'defective/taglist.html', context)
  23.     elif by_what == 'model':
  24.         rejections = Rejection.objects.filter(part__model__name__in=for_what)
  25.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  26.         context = {'rejections': rejections,
  27.                    'title': title}
  28.         return render(request, 'defective/taglist.html', context)
  29.     elif by_what == 'part':
  30.         rejections = Rejection.objects.filter(part__number__in=for_what)
  31.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  32.         context = {'rejections': rejections,
  33.                    'title': title}
  34.         return render(request, 'defective/taglist.html', context)
  35.     elif by_what == 'defect':
  36.         rejections = Rejection.objects.filter(defects__name__in=for_what)
  37.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  38.         context = {'rejections': rejections,
  39.                    'title': title}
  40.         return render(request, 'defective/taglist.html', context)
  41.     elif by_what == 'qty':
  42.         rejections = Rejection.objects.filter(quantity__exact=for_what)
  43.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  44.         context = {'rejections': rejections,
  45.                    'title': title}
  46.         return render(request, 'defective/taglist.html', context)
  47.     elif by_what == 'shift':
  48.         rejections = Rejection.objects.filter(shift__in=for_what)
  49.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  50.         context = {'rejections': rejections,
  51.                    'title': title}
  52.         return render(request, 'defective/taglist.html', context)
  53.     elif by_what == 'station':
  54.         rejections = Rejection.objects.filter(station__in=for_what)
  55.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  56.         context = {'rejections': rejections,
  57.                    'title': title}
  58.         return render(request, 'defective/taglist.html', context)
  59.     elif by_what == 'rej_by':
  60.         rejections = Rejection.objects.filter(rejected_by__icontains=for_what)
  61.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  62.         context = {'rejections': rejections,
  63.                    'title': title}
  64.         return render(request, 'defective/taglist.html', context)
  65.     elif by_what == 'location':
  66.         rejections = Rejection.objects.filter(location__in=for_what)
  67.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  68.         context = {'rejections': rejections,
  69.                    'title': title}
  70.         return render(request, 'defective/taglist.html', context)
  71.     elif by_what == 'dispo':
  72.         rejections = Rejection.objects.filter(evaluation__disposition__in=for_what)
  73.         title = get_title('Filter by {0} for {1}'.format(by_what, ', '.join(for_what)))
  74.         context = {'rejections': rejections,
  75.                    'title': title}
  76.         return render(request, 'defective/taglist.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement