Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
luxcem
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 @@
...
@@ -3,6 +3,9 @@
-
block
content
-
block
content
-
include
'memopol_representatives/search.html'
-
include
'memopol_representatives/search.html'
%p
Number of representatives: {{ representative_num }}
%table
%table
-
for
representative
in
representatives
-
for
representative
in
representatives
%tr
%tr
...
...
memopol_representatives/templates/memopol_representatives/search.html
View file @
6febaf6d
<form
action=
"
{% url 'representatives:index' %}
"
method=
"get"
>
<form
action=
""
method=
"get"
>
{% csrf_token %}
{% csrf_token %}
<label
for=
"search"
>
Search :
</label>
<label
for=
"search"
>
Search :
</label>
<input
id=
"search"
type=
"text"
name=
"search"
>
<input
id=
"search"
type=
"text"
name=
"search"
>
...
...
memopol_representatives/templates/memopol_representatives/view.html
View file @
6febaf6d
{% extends 'base.html' %}
{% extends 'base.html' %}
{% load by_mandate_url %}
{% block content %}
{% block content %}
...
@@ -9,26 +10,17 @@
...
@@ -9,26 +10,17 @@
</p>
</p>
<h1>
{{ representative.full_name }}
</h1>
<h1>
{{ representative.full_name }}
</h1>
<p>
{% for mandate in representative.mandate_set.all %}
<strong>
{% if mandate.group.kind == "group" and mandate.active %}
<a
href=
"{{ representative.current_group|by_mandate_url }}"
>
<h3>
{{ mandate.role }} of {{ mandate.group.name }}
</h3>
{{ representative.current_group.role }} of {{ representative.current_group.group.name }}
{% endif %}
</a>
{% endfor %}
</strong>
</p>
<p>
Born in {{ representative.birth_place }} the {{ representative.birth_date }} ({{ representative.get_gender_display }})
</p>
<p>
Born in {{ representative.birth_place }} the {{ representative.birth_date }} ({{ representative.get_gender_display }})
</p>
<p>
{{ representative.country.name }}
</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>
<h2
style=
"clear: both"
>
Mandates
</h2>
{% for mandate in representative.active_mandates %}
{% for mandate in representative.active_mandates %}
<div
class=
"mandate"
>
<div
class=
"mandate"
>
...
@@ -40,7 +32,10 @@
...
@@ -40,7 +32,10 @@
</h3>
</h3>
<p>
<p>
{{ mandate.begin_date }} to {{ mandate.end_date }}
<br>
{{ 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>
Constituency : {{ mandate.constituency.name }}
<br>
</p>
</p>
</div>
</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
...
@@ -5,6 +5,11 @@ from memopol_representatives import views
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
''
,
''
,
url
(
r
'^$'
,
views
.
index
,
name
=
'index'
),
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'
),
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
...
@@ -6,59 +6,57 @@ from representatives.models import Representative
def
index
(
request
):
def
index
(
request
):
context
=
{}
representative_list
=
_filter_by_search
(
if
request
.
GET
.
get
(
'search'
):
request
,
search
=
request
.
GET
.
get
(
'search'
)
Representative
.
objects
.
all
()
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
()
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
def
by_mandate
(
request
,
mandate_kind
,
mandate_abbr
=
None
,
mandate_name
=
None
):
return
render
(
representative_list
=
Representative
.
objects
.
filter
(
request
,
mandate__group__kind
=
mandate_kind
,
'memopol_representatives/list.html'
,
mandate__active
=
True
context
)
)
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
):
return
_render_list
(
request
,
representative_list
)
context
=
{}
if
request
.
GET
.
get
(
'search'
):
search
=
request
.
GET
.
get
(
'search'
)
def
_filter_by_search
(
request
,
representative_list
):
representative_list
=
Representative
.
objects
.
filter
(
"""
mandate__group__kind
=
'committee'
,
Return a representative_list filtered by
mandate__group__abbreviation
=
committee
the representative name provided in search form
).
filter
(
"""
Q
(
full_name__icontains
=
search
)
search
=
request
.
GET
.
get
(
'search'
)
)
if
search
:
queries_without_page
=
request
.
GET
.
copy
()
return
representative_list
.
filter
(
if
'page'
in
queries_without_page
:
Q
(
full_name__icontains
=
search
)
del
queries_without_page
[
'page'
]
)
context
[
'queries'
]
=
queries_without_page
else
:
else
:
representative_list
=
list
(
set
(
Representative
.
objects
.
filter
(
return
representative_list
mandate__group__kind
=
'committee'
,
mandate__group__abbreviation
=
committee
).
all
()))
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'
)
page
=
request
.
GET
.
get
(
'page'
)
try
:
try
:
representatives
=
paginator
.
page
(
page
)
representatives
=
paginator
.
page
(
page
)
...
@@ -67,7 +65,14 @@ def committee(request, committee):
...
@@ -67,7 +65,14 @@ def committee(request, committee):
except
EmptyPage
:
except
EmptyPage
:
representatives
=
paginator
.
page
(
paginator
.
num_pages
)
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
[
'representatives'
]
=
representatives
context
[
'representative_num'
]
=
paginator
.
count
return
render
(
return
render
(
request
,
request
,
'memopol_representatives/list.html'
,
'memopol_representatives/list.html'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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