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
7792105c
Commit
7792105c
authored
Aug 09, 2016
by
Nicolas Joyard
Browse files
Pass flake8
parent
50a7c4c2
Changes
9
Hide whitespace changes
Inline
Side-by-side
memopol/context_processors.py
View file @
7792105c
...
...
@@ -3,7 +3,8 @@ from representatives.models import Group
def
search_form_options
(
request
):
d
=
{}
# Note: Those queries needs to be eval in the template so that we can cache it efficiently
# Note: Those queries needs to be eval in the template so that we can cache
# it efficiently
d
[
'countries'
]
=
Group
.
objects
.
filter
(
kind
=
'country'
)
d
[
'parties'
]
=
Group
.
objects
.
filter
(
kind
=
'group'
)
...
...
memopol/filters.py
View file @
7792105c
...
...
@@ -63,7 +63,8 @@ class RepresentativeFilter(FilterSet):
class
Meta
:
model
=
Representative
fields
=
[
'search'
,
'chamber'
,
'country'
,
'party'
,
'delegation'
,
'committee'
]
fields
=
[
'search'
,
'chamber'
,
'country'
,
'party'
,
'delegation'
,
'committee'
]
def
search_filter
(
self
,
qs
,
value
):
if
len
(
value
)
==
0
:
...
...
memopol/settings.py
View file @
7792105c
...
...
@@ -200,8 +200,6 @@ TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
TEMPLATE_LOADERS
=
(
'django.template.loaders.filesystem.Loader'
,
'django.template.loaders.app_directories.Loader'
,
#'hamlpy.template.loaders.HamlPyFilesystemLoader',
#'hamlpy.template.loaders.HamlPyAppDirectoriesLoader',
)
"""
...
...
memopol/templatetags/memopol_tags.py
View file @
7792105c
...
...
@@ -96,7 +96,7 @@ def country_flag(country):
def
chamber_icon
(
chamber
):
url
=
static
(
'images/chamber-%s.png'
%
cssify
(
chamber
.
abbreviation
))
return
mark_safe
(
u
'<span class="chamber-icon" style="background-image: url({url})">
'
u
'<span class="chamber-icon" style="background-image: url({url})">'
u
'</span>'
.
format
(
name
=
chamber
.
name
,
url
=
url
))
...
...
@@ -185,4 +185,3 @@ def position_icon(position):
@
register
.
filter
def
cast_str
(
val
):
return
str
(
val
)
memopol/tests/test_dossiers_detail.py
View file @
7792105c
...
...
@@ -22,10 +22,10 @@ class DossierDetailTest(UrlGetTestMixin, TestCase):
self
.
client
.
get
(
self
.
url
)
def
test_title_display
(
self
):
self
.
assertHtmlInResult
(
"<h1 class='text-center'>Dossier Resolution on the Anti-Counterfeiting Trade Agreement (ACTA)</h1>"
)
self
.
assertHtmlInResult
(
"<h1 class='text-center'>Dossier Resolution on the Anti-Counterfeiting Trade Agreement (ACTA)</h1>"
)
# noqa
def
test_date_display
(
self
):
self
.
assertHtmlInResult
(
"<p class='lead text-center'>Last updated Dec. 27, 2015</p>"
)
self
.
assertHtmlInResult
(
"<p class='lead text-center'>Last updated Dec. 27, 2015</p>"
)
# noqa
def
test_description_display
(
self
):
self
.
assertExpectedHtmlInResult
()
...
...
memopol/tests/test_dossiers_list.py
View file @
7792105c
...
...
@@ -16,16 +16,16 @@ class DossiersListTest(UrlGetTestMixin, TestCase):
self
.
client
.
get
(
self
.
url
)
with
self
.
assertNumQueries
(
2
):
resp
=
self
.
client
.
get
(
self
.
url
)
self
.
client
.
get
(
self
.
url
)
def
test_page_title
(
self
):
self
.
assertHtmlInResult
(
'<p class="lead text-center">1 dossier.</p>'
)
def
test_dossier_title
(
self
):
self
.
assertHtmlInResult
(
'<h4 class="text-center">Resolution on the Anti-Counterfeiting Trade Agreement (ACTA)</h4>'
)
self
.
assertHtmlInResult
(
'<h4 class="text-center">Resolution on the Anti-Counterfeiting Trade Agreement (ACTA)</h4>'
)
# noqa
def
test_dossier_age
(
self
):
self
.
assertHtmlInResult
(
'<p class="text-center">Last updated Dec. 27, 2015</p>'
)
self
.
assertHtmlInResult
(
'<p class="text-center">Last updated Dec. 27, 2015</p>'
)
# noqa
def
test_dossier_votes
(
self
):
self
.
assertHtmlInResult
(
'<span class="badge">106</span>'
)
memopol/views.py
View file @
7792105c
...
...
@@ -6,7 +6,7 @@ from django.utils.http import urlencode
from
core.views
import
GridListMixin
,
PaginationMixin
,
CSVDownloadMixin
from
representatives
import
views
as
representatives_views
from
representatives.models
import
Representative
from
representatives_votes
import
views
as
representatives_
votes_views
from
representatives_votes
import
views
as
votes_views
from
representatives_votes.models
import
Dossier
,
Proposal
from
representatives_positions.forms
import
PositionForm
from
representatives_recommendations.models
import
ScoredVote
...
...
@@ -15,11 +15,13 @@ from representatives_recommendations.models import ScoredVote
class
PaginationFormMixin
(
PaginationMixin
):
"""
Only add an searchparameters to the context to make it easy to paginate
without duplicating the 'page' parameter and keeping the form's GET parameters.
without duplicating the 'page' parameter and keeping the form's GET
parameters.
"""
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
PaginationFormMixin
,
self
).
get_context_data
(
**
kwargs
)
params
=
[(
k
,
v
)
for
k
,
v
in
self
.
request
.
GET
.
iteritems
()
if
k
!=
'page'
]
params
=
[(
k
,
v
)
for
k
,
v
in
self
.
request
.
GET
.
iteritems
()
if
k
!=
'page'
]
c
[
'searchparameters'
]
=
urlencode
(
dict
(
params
))
return
c
...
...
@@ -28,7 +30,8 @@ class RepresentativeList(CSVDownloadMixin,
GridListMixin
,
PaginationFormMixin
,
representatives_views
.
RepresentativeList
):
queryset
=
Representative
.
objects
.
filter
(
active
=
True
).
select_related
(
'score'
)
queryset
=
Representative
.
objects
.
filter
(
active
=
True
).
select_related
(
'score'
)
csv_name
=
'meps.csv'
def
get_csv_results
(
self
,
context
,
**
kwargs
):
...
...
@@ -63,8 +66,8 @@ class RepresentativeDetail(representatives_views.RepresentativeDetail):
qs
=
super
(
RepresentativeDetail
,
self
).
get_queryset
()
votes
=
(
ScoredVote
.
objects
.
filter
(
proposal__in
=
Proposal
.
objects
.
exclude
(
recommendation
=
None
))
.
select_related
(
'proposal__recommendation'
)
.
select_related
(
'proposal__dossier'
))
.
select_related
(
'proposal__recommendation'
)
.
select_related
(
'proposal__dossier'
))
qs
=
qs
.
prefetch_related
(
models
.
Prefetch
(
'votes'
,
queryset
=
votes
))
return
qs
...
...
@@ -77,7 +80,7 @@ class RepresentativeDetail(representatives_views.RepresentativeDetail):
return
c
class
DossierList
(
PaginationFormMixin
,
representatives_
votes_views
.
DossierList
):
class
DossierList
(
PaginationFormMixin
,
votes_views
.
DossierList
):
queryset
=
Dossier
.
objects
.
filter
(
proposals__recommendation__isnull
=
False
)
def
get_queryset
(
self
):
...
...
@@ -85,12 +88,12 @@ class DossierList(PaginationFormMixin, representatives_votes_views.DossierList):
return
qs
.
annotate
(
votes_count
=
Count
(
'proposals__votes'
))
class
DossierDetail
(
representatives_
votes_views
.
DossierDetail
):
class
DossierDetail
(
votes_views
.
DossierDetail
):
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
DossierDetail
,
self
).
get_context_data
(
**
kwargs
)
c
[
'proposals'
]
=
(
c
[
'dossier'
].
proposals
.
filter
(
recommendation__isnull
=
False
)
.
select_related
(
'recommendation'
)
)
c
[
'proposals'
]
=
c
[
'dossier'
].
proposals
.
filter
(
recommendation__isnull
=
False
)
.
select_related
(
'recommendation'
)
# Note: this is a bit of a hack, we feed the RelatedManager with
# the prefetch_related with a clause, so that representative.votes.all
...
...
@@ -101,6 +104,7 @@ class DossierDetail(representatives_votes_views.DossierDetail):
c
[
'representatives'
]
=
(
Representative
.
objects
.
filter
(
votes__proposal__in
=
c
[
'proposals'
])
.
distinct
()
.
prefetch_related
(
models
.
Prefetch
(
'votes'
,
queryset
=
votes
)))
.
prefetch_related
(
models
.
Prefetch
(
'votes'
,
queryset
=
votes
)))
return
c
representatives_positions/templatetags/representatives_positions_tags.py
View file @
7792105c
...
...
@@ -17,12 +17,12 @@ def regroup_by_age(positions):
[]]
# This month
for
position
in
positions
:
index
=
0
if
position
.
datetime
+
timedelta
(
30
)
>=
date
.
today
():
index
=
3
if
position
.
datetime
+
timedelta
(
30
)
>=
date
.
today
():
index
=
3
elif
position
.
datetime
+
timedelta
(
180
)
>=
date
.
today
():
index
=
2
index
=
2
elif
position
.
datetime
+
timedelta
(
365
)
>=
date
.
today
():
index
=
1
index
=
1
timeframes
[
index
].
append
(
position
)
...
...
representatives_recommendations/templatetags/representatives_recommendations_tags.py
View file @
7792105c
...
...
@@ -26,6 +26,7 @@ def vote_glyphicon(position):
else
:
return
''
@
register
.
filter
def
vote_icon_color
(
position
,
recommendation
):
if
recommendation
:
...
...
@@ -35,4 +36,3 @@ def vote_icon_color(position, recommendation):
return
'text-danger'
else
:
return
''
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