Commit 22fa8be1 authored by luxcem's avatar luxcem

updates search urls

parent b51b963f
......@@ -9,11 +9,11 @@ def by_mandate_url(mandate):
kwargs = {'mandate_kind': mandate.group.kind}
if mandate.group.abbreviation:
kwargs['mandate_abbr'] = mandate.group.abbreviation
kwargs['search'] = mandate.group.abbreviation
else:
kwargs['mandate_name'] = mandate.group.name
kwargs['search'] = mandate.group.name
return reverse(
'representatives:listby',
'representatives:list',
kwargs=kwargs
)
......@@ -5,11 +5,7 @@ from memopol_representatives import views
urlpatterns = patterns(
'',
url(r'^$', views.index, name='index'),
url(r'^committee/(?P<mandate_abbr>\w{4})$',
views.by_mandate, {'mandate_kind': 'committee'}, name='committee'),
url(r'^listby/(?P<mandate_kind>\w+)/a/(?P<mandate_abbr>.+)$',
views.by_mandate, name='listby'),
url(r'^listby/(?P<mandate_kind>\w+)/n/(?P<mandate_name>.+)$',
views.by_mandate, name='listby'),
url(r'^l/(?P<mandate_kind>\w+)/(?P<search>.+)$',
views.by_mandate, name='list'),
url(r'^view/(?P<num>\d+)$', views.view, name='view'),
)
......@@ -14,19 +14,26 @@ def index(request):
return _render_list(request, representative_list)
def by_mandate(request, mandate_kind, mandate_abbr=None, mandate_name=None):
representative_list = Representative.objects.filter(
mandate__group__kind=mandate_kind,
mandate__active=True
)
def by_mandate(request, mandate_kind, mandate_abbr=None, mandate_name=None, search=None):
if mandate_abbr:
representative_list = representative_list.filter(
representative_list = Representative.objects.filter(
mandate__group__abbreviation=mandate_abbr,
mandate__group__kind=mandate_kind,
mandate__active=True
)
if mandate_name:
representative_list = representative_list.filter(
elif mandate_name:
representative_list = Representative.objects.filter(
Q(mandate__group__name__icontains=mandate_name),
mandate__group__kind=mandate_kind,
mandate__active=True
)
elif search:
representative_list = Representative.objects.filter(
Q(mandate__group__abbreviation__icontains=search) |
Q(mandate__group__name__icontains=search),
mandate__group__kind=mandate_kind,
mandate__active=True
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment