Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
memopol
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Political Memory
memopol
Commits
ca0489ec
Commit
ca0489ec
authored
Feb 09, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create the active_constituency
parent
132589d0
Pipeline
#872
canceled with stage
in 7 minutes and 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
src/representatives/api.py
src/representatives/api.py
+4
-3
src/representatives/filters.py
src/representatives/filters.py
+22
-2
No files found.
src/representatives/api.py
View file @
ca0489ec
...
@@ -32,8 +32,8 @@ from .models import (
...
@@ -32,8 +32,8 @@ from .models import (
WebSite
,
WebSite
,
)
)
from
.filters
import
ActiveMandateQueryFilterBackend
from
.filters
import
(
ActiveMandateQueryFilterBackend
,
ActiveConstituencyFilterBackend
)
class
DefaultWebPagination
(
pagination
.
PageNumberPagination
):
class
DefaultWebPagination
(
pagination
.
PageNumberPagination
):
default_web_page_size
=
10
default_web_page_size
=
10
...
@@ -59,7 +59,8 @@ class RepresentativeViewSet(viewsets.ReadOnlyModelViewSet):
...
@@ -59,7 +59,8 @@ class RepresentativeViewSet(viewsets.ReadOnlyModelViewSet):
filters
.
SearchFilter
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
,
filters
.
OrderingFilter
,
RQLFilterBackend
,
RQLFilterBackend
,
ActiveMandateQueryFilterBackend
ActiveMandateQueryFilterBackend
,
ActiveConstituencyFilterBackend
)
)
filter_fields
=
{
filter_fields
=
{
'active'
:
[
'exact'
],
'active'
:
[
'exact'
],
...
...
src/representatives/filters.py
View file @
ca0489ec
...
@@ -13,7 +13,7 @@ class ActiveMandateQueryFilterBackend(BaseFilterBackend):
...
@@ -13,7 +13,7 @@ class ActiveMandateQueryFilterBackend(BaseFilterBackend):
"""
"""
A filter which check if a mandate is active for a reprensentative
A filter which check if a mandate is active for a reprensentative
the parameter used in the query to filter is, by default
mandates_active
the parameter used in the query to filter is, by default
active_mandates
and it list a list of mandates among which one should be active.
and it list a list of mandates among which one should be active.
"""
"""
query_param
=
getattr
(
settings
,
'ACTIVE_MANDATES_PARAM'
,
'active_mandates'
)
query_param
=
getattr
(
settings
,
'ACTIVE_MANDATES_PARAM'
,
'active_mandates'
)
...
@@ -31,5 +31,25 @@ class ActiveMandateQueryFilterBackend(BaseFilterBackend):
...
@@ -31,5 +31,25 @@ class ActiveMandateQueryFilterBackend(BaseFilterBackend):
Q
(
group__name__in
=
mandates
)
|
Q
(
group__name__in
=
mandates
)
|
Q
(
group__abbreviation__in
=
mandates
)
Q
(
group__abbreviation__in
=
mandates
)
)).
distinct
()
)).
distinct
()
return
qs
return
qs
class
ActiveConstituencyFilterBackend
(
BaseFilterBackend
):
"""
A filter which check if a representative is active in a constituency
the parameter used in the query to filter is, by default, active_constituency.
"""
query_param
=
getattr
(
settings
,
'ACTIVE_CONSTITUENCY_PARAM'
,
'active_constituency'
)
def
filter_queryset
(
self
,
request
,
queryset
,
view
):
qs
=
queryset
if
self
.
query_param
in
request
.
GET
:
if
len
(
request
.
GET
[
self
.
query_params
]):
mandates
=
request
.
GET
[
self
.
query_param
].
split
(
','
)
qs
=
qs
.
filter
(
mandates__in
=
Mandate
.
objects
.
filter
(
Q
(
end_date__gte
=
datetime
.
today
)
|
Q
(
end_date__isnull
=
True
)).
filter
(
Q
(
constituency__name__in
=
mandates
)).
distinct
()
return
qs
return
qs
Write
Preview
Markdown
is supported
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