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
Political Memory
memopol
Commits
2f475d37
Commit
2f475d37
authored
Jun 10, 2016
by
Nicolas Joyard
Browse files
Disable active filter for countries and chambers
parent
c9101d25
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/views.py
View file @
2f475d37
...
...
@@ -15,6 +15,14 @@ class ActiveLegislatureMixin(object):
self
.
set_active_only
()
return
super
(
ActiveLegislatureMixin
,
self
).
get
(
*
args
,
**
kwargs
)
def
override_active_only
(
self
):
"""
Redefine this method to override active legislature selection
- return None to enable user choice
- return True or False to disable user choice and set active state
"""
return
None
def
set_active_only
(
self
):
if
'active_only'
in
self
.
request
.
GET
:
self
.
request
.
session
[
'active_only'
]
=
\
...
...
@@ -23,11 +31,16 @@ class ActiveLegislatureMixin(object):
self
.
request
.
session
[
'active_only'
]
=
self
.
default_active_only
def
get_active_only
(
self
):
return
self
.
request
.
session
[
'active_only'
]
overriden
=
self
.
override_active_only
()
if
overriden
is
None
:
return
self
.
request
.
session
[
'active_only'
]
else
:
return
overriden
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
ActiveLegislatureMixin
,
self
).
get_context_data
(
**
kwargs
)
c
[
'active_only'
]
=
self
.
get_active_only
()
if
self
.
override_active_only
()
is
None
:
c
[
'active_only'
]
=
self
.
get_active_only
()
return
c
...
...
memopol/views/group_list.py
View file @
2f475d37
...
...
@@ -12,14 +12,22 @@ from representatives.models import Group
class
GroupList
(
PaginationMixin
,
ActiveLegislatureMixin
,
generic
.
ListView
):
def
override_active_only
(
self
):
kind
=
self
.
kwargs
.
get
(
'kind'
)
if
kind
==
'chamber'
or
kind
==
'country'
:
return
False
else
:
return
None
def
get_queryset
(
self
):
qs
=
Group
.
objects
.
all
()
if
self
.
get_active_only
():
qs
=
qs
.
filter
(
models
.
Q
(
mandates__end_date__gte
=
datetime
.
date
.
today
())
|
models
.
Q
(
mandates__end_date__isnull
=
True
)
)
if
self
.
get_active_only
():
qs
=
qs
.
filter
(
models
.
Q
(
mandates__end_date__gte
=
datetime
.
date
.
today
())
|
models
.
Q
(
mandates__end_date__isnull
=
True
)
)
kind
=
self
.
kwargs
.
get
(
'kind'
,
None
)
if
kind
:
...
...
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