Commit a8094501 authored by Nicolas Joyard's avatar Nicolas Joyard

Finish navigation pane implementation

parent dee7cc3c
from representatives.models import Group
from representatives.models import Chamber, Group
def search_form_options(request):
......@@ -6,6 +6,7 @@ def search_form_options(request):
# Note: Those queries needs to be eval in the template so that we can cache
# it efficiently
d['chambers'] = Chamber.objects.all()
d['countries'] = Group.objects.filter(kind='country')
d['parties'] = Group.objects.filter(kind='group')
d['delegations'] = Group.objects.filter(kind='delegation')
......
# coding: utf-8
from dal.autocomplete import ModelSelect2
import datetime
from django.db.models import Q
from django.utils.text import slugify
from django_filters import FilterSet, MethodFilter, ModelChoiceFilter
from django_filters import FilterSet, MethodFilter
from representatives.models import Chamber, Group, Representative
from representatives.models import Representative
from representatives_votes.models import Dossier
from memopol_themes.models import Theme
def rep_chamber_filter(qs, value):
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) | Q(mandates__end_date__isnull=True),
mandates__group__chamber=value
)
def dossier_chamber_filter(qs, value):
return qs.filter(documents__chamber=value)
def group_filter(qs, value):
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) | Q(mandates__end_date__isnull=True),
mandates__group=value
)
class RepresentativeFilter(FilterSet):
search = MethodFilter(action='search_filter')
chamber = ModelChoiceFilter(queryset=Chamber.objects.all(),
action=rep_chamber_filter)
country = ModelChoiceFilter(queryset=Group.objects.filter(kind='country'),
action=group_filter)
party = ModelChoiceFilter(queryset=Group.objects.filter(kind='party'),
action=group_filter)
delegation = ModelChoiceFilter(
queryset=Group.objects.filter(kind='delegation'),
action=group_filter)
committee = ModelChoiceFilter(
queryset=Group.objects.filter(kind='committee'),
action=group_filter)
group = ModelChoiceFilter(queryset=Group.objects.exclude(
kind__in=['chamber', 'country']),
action=group_filter,
widget=ModelSelect2(url='group-autocomplete'),
label='Party, committee or delegation')
chamber = MethodFilter(action='chamber_filter')
country = MethodFilter(action='group_filter')
party = MethodFilter(action='group_filter')
delegation = MethodFilter(action='group_filter')
committee = MethodFilter(action='group_filter')
class Meta:
model = Representative
......@@ -72,13 +32,33 @@ class RepresentativeFilter(FilterSet):
return qs.filter(slug__icontains=slugify(value))
def chamber_filter(self, qs, value):
if len(value) == 0:
return qs
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) |
Q(mandates__end_date__isnull=True),
mandates__group__chamber=value
)
def group_filter(self, qs, value):
if len(value) == 0:
return qs
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) |
Q(mandates__end_date__isnull=True),
mandates__group=value
)
class DossierFilter(FilterSet):
search = MethodFilter(action='search_filter')
chamber = ModelChoiceFilter(queryset=Chamber.objects.all(),
action=dossier_chamber_filter)
chamber = MethodFilter(action='chamber_filter')
class Meta:
model = Dossier
......@@ -91,6 +71,12 @@ class DossierFilter(FilterSet):
return qs.filter(Q(title__icontains=value) |
Q(reference__icontains=value))
def chamber_filter(self, qs, value):
if len(value) == 0:
return qs
return qs.filter(documents__chamber=value)
class ThemeFilter(FilterSet):
......
<option value="">All</option>
---
<option value="1">
European Parliament
</option>
\ No newline at end of file
<div id="intro">
<h1 class="text-center"><span class="glyphicon glyphicon-eye-open"></span><br/>Political memory</h1>
<p class="lead text-center hidden-xs">What is Memopol ?</p>
<p class="text-justify hidden-xs">Political Memory is a tool designed by La Quadrature du Net to help citizens reach their representative and track their voting records on issues related to fundamental freedoms online.</p>
<div class="container-fluid hidden-xs">
<div class="row">
<div class="pull-right">
<a class="btn btn-default">More on our blog</a>
</div>
</div>
</div>
</div>
\ No newline at end of file
<option value="">All</option>
---
<option value="1">
European Parliament
</option>
\ No newline at end of file
<option value="">All</option>
---
<option data-url="/legislature/representative/?committee=47" value="47">
AGRI –
Committee on Agriculture and Rural Development
</option>
---
<option data-url="/legislature/representative/?committee=89" value="89">
CONT –
Committee on Budgetary Control
</option>
---
<option data-url="/legislature/representative/?committee=34" value="34">
BUDG –
Committee on Budgets
</option>
---
<option data-url="/legislature/representative/?committee=7" value="7">
LIBE –
Committee on Civil Liberties, Justice and Home Affairs
</option>
---
<option data-url="/legislature/representative/?committee=37" value="37">
AFCO –
Committee on Constitutional Affairs
</option>
---
<option data-url="/legislature/representative/?committee=20" value="20">
CULT –
Committee on Culture and Education
</option>
---
<option data-url="/legislature/representative/?committee=8" value="8">
DEVE –
Committee on Development
</option>
---
<option data-url="/legislature/representative/?committee=30" value="30">
ECON –
Committee on Economic and Monetary Affairs
</option>
---
<option data-url="/legislature/representative/?committee=3" value="3">
EMPL –
Committee on Employment and Social Affairs
</option>
---
<option data-url="/legislature/representative/?committee=55" value="55">
PECH –
Committee on Fisheries
</option>
---
<option data-url="/legislature/representative/?committee=5" value="5">
AFET –
Committee on Foreign Affairs
</option>
---
<option data-url="/legislature/representative/?committee=23" value="23">
ITRE –
Committee on Industry, Research and Energy
</option>
---
<option data-url="/legislature/representative/?committee=49" value="49">
INTA –
Committee on International Trade
</option>
---
<option data-url="/legislature/representative/?committee=9" value="9">
JURI –
Committee on Legal Affairs
</option>
---
<option data-url="/legislature/representative/?committee=6" value="6">
PETI –
Committee on Petitions
</option>
---
<option data-url="/legislature/representative/?committee=24" value="24">
REGI –
Committee on Regional Development
</option>
---
<option data-url="/legislature/representative/?committee=48" value="48">
ENVI –
Committee on the Environment, Public Health and Food Safety
</option>
---
<option data-url="/legislature/representative/?committee=58" value="58">
IMCO –
Committee on the Internal Market and Consumer Protection
</option>
---
<option data-url="/legislature/representative/?committee=68" value="68">
TRAN –
Committee on Transport and Tourism
</option>
---
<option data-url="/legislature/representative/?committee=77" value="77">
FEMM –
Committee on Women's Rights and Gender Equality
</option>
---
<option data-url="/legislature/representative/?committee=61" value="61">
CRIS –
Special Committee on the Financial, Economic and Social Crisis
</option>
---
<option data-url="/legislature/representative/?committee=50" value="50">
SURE –
Special committee on the policy challenges and budgetary resources for a sustainable European Union after 2013
</option>
---
<option data-url="/legislature/representative/?committee=4" value="4">
DROI –
Subcommittee on Human Rights
</option>
\ No newline at end of file
<option value="">All</option>
---
<option value="106">
AT –
Austria
</option>
---
<option value="98">
BE –
Belgium
</option>
---
<option value="117">
BG –
Bulgaria
</option>
---
<option value="184">
CY –
Cyprus
</option>
---
<option value="88">
CZ –
Czech Republic
</option>
---
<option value="113">
DK –
Denmark
</option>
---
<option value="126">
EE –
Estonia
</option>
---
<option value="115">
FI –
Finland
</option>
---
<option value="110">
FR –
France
</option>
---
<option value="22">
DE –
Germany
</option>
---
<option value="134">
GR –
Greece
</option>
---
<option value="85">
HU –
Hungary
</option>
---
<option value="182">
IE –
Ireland
</option>
---
<option value="100">
IT –
Italy
</option>
---
<option value="93">
LV –
Latvia
</option>
---
<option value="145">
LT –
Lithuania
</option>
---
<option value="112">
LU –
Luxembourg
</option>
---
<option value="186">
MT –
Malta
</option>
---
<option value="57">
NL –
Netherlands
</option>
---
<option value="2">
PL –
Poland
</option>
---
<option value="109">
PT –
Portugal
</option>
---
<option value="19">
RO –
Romania
</option>
---
<option value="169">
SK –
Slovakia
</option>
---
<option value="120">
SI –
Slovenia
</option>
---
<option value="91">
ES –
Spain
</option>
---
<option value="140">
SE –
Sweden
</option>
---
<option value="33">
GB –
United Kingdom
</option>
\ No newline at end of file
<option value="">All</option>
---
<option value="199">
GUE/NGL –
Confederal Group of the European United Left
</option>
---
<option value="42">
GUE/NGL –
Confederal Group of the European United Left - Nordic Green Left
</option>
---
<option value="43">
GUE/NGL –
Confederal Group of the European United Left/Nordic Green Left
</option>
---
<option value="1">
ECR –
European Conservatives and Reformists Group
</option>
---
<option value="71">
EFD –
Europe of freedom and democracy Group
</option>
---
<option value="31">
EFDD –
Europe of Freedom and Direct Democracy Group
</option>
---
<option value="128">
ENF –
Europe of Nations and Freedom Group
</option>
---
<option value="171">
EDD –
Group for a Europe of Democracies and Diversities
</option>
---
<option value="174">
ER –
Group of Independents for a Europe of Nations
</option>
---
<option value="17">
ALDE –
Group of the Alliance of Liberals and Democrats for Europe
</option>
---
<option value="162">
EDA –
Group of the European Democratic Alliance
</option>
---
<option value="144">
ELDR –
Group of the European Liberal, Democrat and Reform Party
</option>
---
<option value="104">
EPP –
Group of the European People's Party (Christian-Democratic Group)
</option>
---
<option value="18">
EPP –
Group of the European People's Party (Christian Democrats)
</option>
---
<option value="54">
PPE-DE –
Group of the European People's Party (Christian Democrats) and European Democrats
</option>
---
<option value="177">
ERA –
Group of the European Radical Alliance
</option>
---
<option value="84">
Greens/EFA –
Group of the Greens/European Free Alliance
</option>
---
<option value="67">
PSE –
Group of the Party of European Socialists
</option>
---
<option value="21">
SD –
Group of the Progressive Alliance of Socialists and Democrats in the European Parliament
</option>
---
<option value="181">
UFE –
Group Union for Europe
</option>
---
<option value="76">
IND/DEM –
Independence/Democracy Group
</option>
---
<option value="176">
LD –
Liberal and Democratic Group
</option>
---
<option value="153">
LDR –
Liberal and Democratic Reformist Group
</option>
---
<option value="32">
NI –
Non-attached Members
</option>
---
<option value="168">
SOC –
Socialist Group
</option>
---
<option value="41">
PSE –
Socialist Group in the European Parliament
</option>
---
<option value="200">
Greens/EFA –
The Green Group in the European Parliament
</option>
---
<option value="75">
UEN –
Union for Europe of the Nations Group
</option>
\ No newline at end of file
......@@ -4,9 +4,39 @@ from responsediff.test import ResponseDiffTestMixin
class NavigationPaneTest(ResponseDiffTestMixin, test.TestCase):
url = '/'
fixtures = ['smaller_sample.json']
"""
Common queries
- One for chambers
- One for countries
- One for parties
- One for committees
- One for delegations
"""
queries = 5
def selector_test(self, selector):
self.assertResponseDiffEmpty(test.Client().get(self.url), selector)
def test_intro(self):
self.selector_test('#intro')
def test_queries(self):
with self.assertNumQueries(self.queries):
test.Client().get(self.url)
def test_rep_search_chambers(self):
self.selector_test('#form-rep #chamber-rep option')
def test_rep_search_countries(self):
self.selector_test('#form-rep #country option')
def test_rep_search_parties(self):
self.selector_test('#form-rep #party option')
def test_rep_search_committee(self):
self.selector_test('#form-rep #committee option')
def test_rep_search_delegation(self):
self.selector_test('#form-rep #delegation option')
def test_dossier_search_chambers(self):
self.selector_test('#form-dossier #chamber-dossier option')
......@@ -43,5 +43,6 @@ class DossierList(PaginationMixin, SortMixin, generic.ListView):
def get_context_data(self, **kwargs):
c = super(DossierList, self).get_context_data(**kwargs)
c['view'] = 'dossier_list'
c['filter'] = self.current_filter
return c
......@@ -28,6 +28,7 @@ class RepresentativeList(CSVDownloadMixin, GridListMixin, PaginationMixin,
c = super(RepresentativeList, self).get_context_data(**kwargs)
c['filter'] = self.current_filter
c['view'] = 'representative_list'
c['object_list'] = [
self.add_representative_country_and_main_mandate(r)
for r in c['object_list']
......
This diff is collapsed.
......@@ -46,9 +46,11 @@
{% endcache %}
<hr class="hidden-xs"/>
<a href="{% url "representative-list" %}" class="btn btn-primary btn-block">
{% trans "Find a representative" %}</a>
{% trans "Check out all representatives" %}</a>
<a href="{% url "theme-list" %}" class="btn btn-primary btn-block">
{% trans "Explore themes" %}</a>
<a href="{% url "dossier-list" %}" class="btn btn-primary btn-block">
{% trans "Browse all dossiers" %}</a>
<br />
{% endblock %}
</div>
......
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