Advertisement
Mochinov

Untitled

Feb 25th, 2021
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.39 KB | None | 0 0
  1. def get_list_locations(request):
  2.     account = Account.objects.get(user=request.user)
  3.     street = request.GET.get('street', '')
  4.     number_building = request.GET.get('num', '')
  5.     sub_polyclinic = request.GET.get('bra', '')
  6.     polyclinic = account.polyclinic.get()
  7.     if sub_polyclinic == '':
  8.         sub_polyclinic = Subdivision_Polyclinic.objects.get(polyclinic = account.polyclinic.get())
  9.         sub_polyclinic = sub_polyclinic.branch
  10.     location = Location.objects.select_related('subdivision_polyclinics', 'polyclinic')
  11.  
  12.     if street:
  13.         locations = location.filter(street__icontains = street)
  14.     if number_building:
  15.         locations = location.filter(building__icontains = number_building)
  16.     if sub_polyclinic:
  17.         locations = location.filter(subdivision_polyclinics__branch=sub_polyclinic)
  18.     if not locations:
  19.         locations = location.filter(chek_building = False,subdivision_polyclinics__branch=sub_polyclinic, polyclinic__id = polyclinic.id)
  20.     locations_json = []
  21.     for i in locations:
  22.         if(chek_write(i.polyclinic.id)):
  23.             locations_json.append({'polyclinic': str(i.polyclinic.name),'building': str(i.building), 'branch': i.subdivision_polyclinics.name_sub,
  24.                                     'street': str(i.street),'zone': str(i.zone), 'email': str(i.polyclinic.email),
  25.                                     'contact': str(i.polyclinic.contact), 'recording': set_or_redirect(i)})
  26.     return HttpResponse(json.dumps(locations_json), content_type='application/json')
  27.  
  28. ====================== Твой код ==================================
  29. def get_list_locations(request):
  30.     account = Account.objects.get(user=request.user)
  31.     street = request.GET.get('street', '')
  32.     number_building = request.GET.get('num', '')
  33.     sub_polyclinic = request.GET.get('bra', '')
  34.     polyclinic = account.polyclinic.get()
  35.     if sub_polyclinic == '':
  36.         sub_polyclinic = Subdivision_Polyclinic.objects.get(polyclinic = account.polyclinic.get())
  37.         sub_polyclinic = sub_polyclinic.branch
  38.     location = Location.objects.select_related('subdivision_polyclinics', 'polyclinic')
  39.     if len(number_building) == 0:
  40.         locations = location.filter(
  41.             street__icontains=street,
  42.             subdivision_polyclinics__branch=sub_polyclinic,
  43.             polyclinic__id = polyclinic.id)
  44.     else:
  45.         locations = location.filter(
  46.             Q (street__icontains=street)
  47.             & Q (building__icontains=number_building)
  48.             & Q (subdivision_polyclinics__branch=sub_polyclinic)
  49.             & Q (polyclinic__id = polyclinic.id))
  50.         if not locations:
  51.             locations = location.filter(
  52.                 street__icontains=street,
  53.                 chek_building = False,
  54.                 subdivision_polyclinics__branch=sub_polyclinic,
  55.                 polyclinic__id = polyclinic.id)
  56.    
  57.     locations_json = []
  58.     for i in locations:
  59.         if(chek_write(i.polyclinic.id)):
  60.             locations_json.append({'polyclinic': str(i.polyclinic.name),'building': str(i.building), 'branch': i.subdivision_polyclinics.name_sub,
  61.                                     'street': str(i.street),'zone': str(i.zone), 'email': str(i.polyclinic.email),
  62.                                     'contact': str(i.polyclinic.contact), 'recording': set_or_redirect(i)})
  63.     return HttpResponse(json.dumps(locations_json), content_type='application/json')
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement