Browse Source

Стилистические изменения в search_view

develop
Golikov Ivan 3 years ago
parent
commit
38f07fd275
1 changed files with 25 additions and 21 deletions
  1. +25
    -21
      journal/views.py

+ 25
- 21
journal/views.py View File

@@ -85,27 +85,31 @@ def search_view(request):
template = 'journal/search.html'
search_input = request.GET.get('search_input', '').strip()

if search_input != "":
if re.match('\d+', search_input):
pbxport_set = PBXPort.objects.filter(subscriber_number=search_input)
context['number_crosspath'] = pbxport_to_crosspath(pbxport_set)

room_number_pattern = r'(^|\D+){}(\D+|$)'.format(search_input)
phone_set = Phone.objects.filter(location__room__room__iregex=room_number_pattern)
pbxport_set = PBXPort.objects.filter(pk__in=phone_set.values('main_source'))
context['room_crosspath'] = pbxport_to_crosspath(pbxport_set)
else:
subscriber_set = Subscriber.objects.order_by(
'last_name').filter(
last_name__icontains=search_input)

subscriber_crosspath = {}
for subscriber in subscriber_set:
phone_set = subscriber.phones.all().values('main_source')
pbxport_set = PBXPort.objects.filter(pk__in=phone_set)
if pbxport_set:
subscriber_crosspath[subscriber] = pbxport_to_crosspath(pbxport_set)
context['subscriber_crosspath'] = subscriber_crosspath
if re.match(r'\d+', search_input):
pbxport_set = PBXPort.objects.filter(subscriber_number=search_input)
context['number_crosspath'] = pbxport_to_crosspath(pbxport_set)

room_number_pattern = r'(^|\D+){}(\D+|$)'.format(search_input)
phone_set = Phone.objects.filter(location__room__room__iregex=room_number_pattern)
pbxport_set = PBXPort.objects.filter(pk__in=phone_set.values('main_source'))

context['room_crosspath'] = pbxport_to_crosspath(pbxport_set)

elif search_input != '':
subscriber_set = Subscriber.objects.order_by(
'last_name').filter(
last_name__icontains=search_input)

subscriber_crosspath = {}

for subscriber in subscriber_set:
phone_set = subscriber.phones.all().values('main_source')
pbxport_set = PBXPort.objects.filter(pk__in=phone_set)

if pbxport_set:
subscriber_crosspath[subscriber] = pbxport_to_crosspath(pbxport_set)

context['subscriber_crosspath'] = subscriber_crosspath

return render(request, template, context)



Loading…
Cancel
Save