Commit 7792105c authored by Nicolas Joyard's avatar Nicolas Joyard

Pass flake8

parent 50a7c4c2
......@@ -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')
......
......@@ -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:
......
......@@ -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',
)
"""
......
......@@ -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})">&nbsp;'
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)
......@@ -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()
......
......@@ -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>')
......@@ -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
......@@ -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)
......
......@@ -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 ''
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment