Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TAlone
memopol
Commits
6febaf6d
Commit
6febaf6d
authored
Mar 17, 2015
by
luxcem
Browse files
adds urls and view for filtering representatives by mandates
parent
ea8f7449
Changes
7
Hide whitespace changes
Inline
Side-by-side
memopol_representatives/templates/memopol_representatives/list.haml
View file @
6febaf6d
...
...
@@ -3,6 +3,9 @@
-
block
content
-
include
'memopol_representatives/search.html'
%p
Number of representatives: {{ representative_num }}
%table
-
for
representative
in
representatives
%tr
...
...
memopol_representatives/templates/memopol_representatives/search.html
View file @
6febaf6d
<form
action=
"
{% url 'representatives:index' %}
"
method=
"get"
>
<form
action=
""
method=
"get"
>
{% csrf_token %}
<label
for=
"search"
>
Search :
</label>
<input
id=
"search"
type=
"text"
name=
"search"
>
...
...
memopol_representatives/templates/memopol_representatives/view.html
View file @
6febaf6d
{% extends 'base.html' %}
{% load by_mandate_url %}
{% block content %}
...
...
@@ -9,26 +10,17 @@
</p>
<h1>
{{ representative.full_name }}
</h1>
{% for mandate in representative.mandate_set.all %}
{% if mandate.group.kind == "group" and mandate.active %}
<h3>
{{ mandate.role }} of {{ mandate.group.name }}
</h3>
{% endif %}
{% endfor %}
<p>
<strong>
<a
href=
"{{ representative.current_group|by_mandate_url }}"
>
{{ representative.current_group.role }} of {{ representative.current_group.group.name }}
</a>
</strong>
</p>
<p>
Born in {{ representative.birth_place }} the {{ representative.birth_date }} ({{ representative.get_gender_display }})
</p>
<p>
{{ representative.country.name }}
</p>
<h2
style=
"clear: both"
>
Committees
</h2>
{% for mandate in representative.mandate_set.all %}
{% if mandate.group.kind == "committee" and mandate.active %}
<p>
{{ mandate.role }} of {{ mandate.group.name }}
(
<a
href=
"{% url 'representatives:committee' mandate.group.abbreviation %}"
>
{{ mandate.group.abbreviation }}
</a>
)
</p>
{% endif %}
{% endfor %}
<h2
style=
"clear: both"
>
Mandates
</h2>
{% for mandate in representative.active_mandates %}
<div
class=
"mandate"
>
...
...
@@ -40,7 +32,10 @@
</h3>
<p>
{{ mandate.begin_date }} to {{ mandate.end_date }}
<br>
<strong>
{{ mandate.group.kind }}
</strong>
:
<em>
{{ mandate.group.name }} ({{ mandate.group.abbreviation }})
</em>
<br>
<a
href=
"{{ mandate|by_mandate_url }}"
>
<strong>
{{ mandate.group.kind }}
</strong>
:
<em>
{{ mandate.group.name }} ({{ mandate.group.abbreviation }})
</em>
</a>
<br>
Constituency : {{ mandate.constituency.name }}
<br>
</p>
</div>
...
...
memopol_representatives/templatetags/__init__.py
0 → 100644
View file @
6febaf6d
memopol_representatives/templatetags/by_mandate_url.py
0 → 100644
View file @
6febaf6d
from
django
import
template
from
django.core.urlresolvers
import
reverse
register
=
template
.
Library
()
@
register
.
filter
def
by_mandate_url
(
mandate
):
kwargs
=
{
'mandate_kind'
:
mandate
.
group
.
kind
}
if
mandate
.
group
.
abbreviation
:
kwargs
[
'mandate_abbr'
]
=
mandate
.
group
.
abbreviation
else
:
kwargs
[
'mandate_name'
]
=
mandate
.
group
.
name
return
reverse
(
'representatives:listby'
,
kwargs
=
kwargs
)
memopol_representatives/urls.py
View file @
6febaf6d
...
...
@@ -5,6 +5,11 @@ from memopol_representatives import views
urlpatterns
=
patterns
(
''
,
url
(
r
'^$'
,
views
.
index
,
name
=
'index'
),
url
(
r
'^committee/(?P<committee>\w{4})$'
,
views
.
committee
,
name
=
'committee'
),
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
'^view/(?P<num>\d+)$'
,
views
.
view
,
name
=
'view'
),
)
memopol_representatives/views.py
View file @
6febaf6d
...
...
@@ -6,59 +6,57 @@ from representatives.models import Representative
def
index
(
request
):
context
=
{}
if
request
.
GET
.
get
(
'search'
):
search
=
request
.
GET
.
get
(
'search'
)
representative_list
=
Representative
.
objects
.
filter
(
Q
(
full_name__icontains
=
search
)
|
Q
(
country__name__icontains
=
search
)
)
queries_without_page
=
request
.
GET
.
copy
()
if
'page'
in
queries_without_page
:
del
queries_without_page
[
'page'
]
context
[
'queries'
]
=
queries_without_page
else
:
representative_list
=
Representative
.
objects
.
all
()
representative_list
=
_filter_by_search
(
request
,
Representative
.
objects
.
all
()
)
paginator
=
Paginator
(
representative_list
,
50
)
return
_render_list
(
request
,
representative_list
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
representatives
=
paginator
.
page
(
page
)
except
PageNotAnInteger
:
representatives
=
paginator
.
page
(
1
)
except
EmptyPage
:
representatives
=
paginator
.
page
(
paginator
.
num_pages
)
context
[
'representatives'
]
=
representatives
return
render
(
request
,
'memopol_representatives/list.html'
,
context
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
)
if
mandate_abbr
:
representative_list
=
representative_list
.
filter
(
mandate__group__abbreviation
=
mandate_abbr
,
mandate__active
=
True
)
if
mandate_name
:
representative_list
=
representative_list
.
filter
(
Q
(
mandate__group__name__icontains
=
mandate_name
),
mandate__active
=
True
)
# Select distinct representatives and filter by search
representative_list
=
list
(
set
(
_filter_by_search
(
request
,
representative_list
)
))
def
committee
(
request
,
committee
):
context
=
{}
if
request
.
GET
.
get
(
'search'
):
search
=
request
.
GET
.
get
(
'search'
)
representative_list
=
Representative
.
objects
.
filter
(
mandate__group__kind
=
'committee'
,
mandate__group__abbreviation
=
committee
).
filter
(
Q
(
full_name__icontains
=
search
)
)
queries_without_page
=
request
.
GET
.
copy
()
if
'page'
in
queries_without_page
:
del
queries_without_page
[
'page'
]
context
[
'queries'
]
=
queries_without_page
return
_render_list
(
request
,
representative_list
)
def
_filter_by_search
(
request
,
representative_list
):
"""
Return a representative_list filtered by
the representative name provided in search form
"""
search
=
request
.
GET
.
get
(
'search'
)
if
search
:
return
representative_list
.
filter
(
Q
(
full_name__icontains
=
search
)
)
else
:
representative_list
=
list
(
set
(
Representative
.
objects
.
filter
(
mandate__group__kind
=
'committee'
,
mandate__group__abbreviation
=
committee
).
all
()))
return
representative_list
paginator
=
Paginator
(
representative_list
,
50
)
def
_render_list
(
request
,
representative_list
,
num_by_page
=
50
):
"""
Render a paginated list of representatives
"""
paginator
=
Paginator
(
representative_list
,
num_by_page
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
representatives
=
paginator
.
page
(
page
)
...
...
@@ -67,7 +65,14 @@ def committee(request, committee):
except
EmptyPage
:
representatives
=
paginator
.
page
(
paginator
.
num_pages
)
context
=
{}
queries_without_page
=
request
.
GET
.
copy
()
if
'page'
in
queries_without_page
:
del
queries_without_page
[
'page'
]
context
[
'queries'
]
=
queries_without_page
context
[
'representatives'
]
=
representatives
context
[
'representative_num'
]
=
paginator
.
count
return
render
(
request
,
'memopol_representatives/list.html'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment