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
Anthony
memopol
Commits
202c4051
Commit
202c4051
authored
Jun 10, 2016
by
Nicolas Joyard
Browse files
Enable choosing active legislature/all data on rep list
parent
1f7ddd61
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/templates/core/blocks/active-filter.haml
0 → 100644
View file @
202c4051
Display :
-
if
active_only
current legislature only /
%a
{
'href'
:
'?active_only=0'
}
all data
-
else
%a
{
'href'
:
'?active_only=1'
}
current legislature only
=
"/ all data"
\ No newline at end of file
core/templates/core/blocks/pagination.haml
View file @
202c4051
...
...
@@ -37,6 +37,11 @@
%div
.count
Number of results : {{ paginator.count }}
-
if
active_only
!=
None
%br
-
include
'core/blocks/active-filter.html'
%br
Number of displayed results :
{{ paginator.per_page }}
...
...
core/views.py
View file @
202c4051
...
...
@@ -4,6 +4,33 @@ from django import http
import
unicodecsv
as
csv
class
ActiveLegislatureMixin
(
object
):
"""
Mixin for views that can switch between active legislature and all data
"""
default_active_only
=
True
def
get
(
self
,
*
args
,
**
kwargs
):
self
.
set_active_only
()
return
super
(
ActiveLegislatureMixin
,
self
).
get
(
*
args
,
**
kwargs
)
def
set_active_only
(
self
):
if
'active_only'
in
self
.
request
.
GET
:
self
.
request
.
session
[
'active_only'
]
=
\
self
.
request
.
GET
[
'active_only'
]
==
'1'
elif
'active_only'
not
in
self
.
request
.
session
:
self
.
request
.
session
[
'active_only'
]
=
self
.
default_active_only
def
get_active_only
(
self
):
return
self
.
request
.
session
[
'active_only'
]
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
ActiveLegislatureMixin
,
self
).
get_context_data
(
**
kwargs
)
c
[
'active_only'
]
=
self
.
get_active_only
()
return
c
class
PaginationMixin
(
object
):
pagination_limits
=
(
12
,
24
,
48
,
96
)
...
...
memopol/views/representative_list.py
View file @
202c4051
# coding: utf-8
from
core.views
import
GridListMixin
,
PaginationMixin
,
CSVDownloadMixin
from
core.views
import
GridListMixin
,
PaginationMixin
,
CSVDownloadMixin
,
\
ActiveLegislatureMixin
import
datetime
...
...
@@ -14,11 +15,11 @@ from .representative_mixin import RepresentativeViewMixin
class
RepresentativeList
(
CSVDownloadMixin
,
GridListMixin
,
PaginationMixin
,
RepresentativeViewMixin
,
generic
.
ListView
):
RepresentativeViewMixin
,
ActiveLegislatureMixin
,
generic
.
ListView
):
csv_name
=
'meps.csv'
queryset
=
Representative
.
objects
.
filter
(
active
=
True
).
select_related
(
'score'
)
queryset
=
Representative
.
objects
.
select_related
(
'score'
)
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
RepresentativeList
,
self
).
get_context_data
(
**
kwargs
)
...
...
@@ -66,6 +67,8 @@ class RepresentativeList(CSVDownloadMixin, GridListMixin, PaginationMixin,
def
get_queryset
(
self
):
qs
=
super
(
RepresentativeList
,
self
).
get_queryset
()
if
self
.
get_active_only
():
qs
=
qs
.
filter
(
active
=
True
)
qs
=
self
.
group_filter
(
qs
)
qs
=
self
.
search_filter
(
qs
)
qs
=
self
.
prefetch_for_representative_country_and_main_mandate
(
qs
)
...
...
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