Commit a5c24a90 authored by Arnaud Fabre's avatar Arnaud Fabre
Browse files

update memopol for link between representatives and vote

parent bfb601aa
...@@ -116,10 +116,10 @@ p { ...@@ -116,10 +116,10 @@ p {
li { li {
text-decoration: none; text-decoration: none;
list-style: outside none none; list-style: inside;
} }
.panel.callout { .panel. {
background: none repeat scroll 0% 0% #5B8EDC; background: none repeat scroll 0% 0% #5B8EDC;
color: #FFF; color: #FFF;
border-color: #2284A1; border-color: #2284A1;
......
%ul.nav-bar %ul.nav-bar
%li %li
%a{href: "{% url 'legislature:representatives_index' %}"} %a{href: "{% url 'legislature:representative_index' %}"}
Representatives Representatives
%li %li
%em By : %em By :
%li %li
%a{href: "{% url 'legislature:groups_by_kind' 'country' %}"} %a{href: "{% url 'legislature:group_index' kind='country' %}"}
Countries Countries
%li %li
%a{href: "{% url 'legislature:groups_by_kind' 'group' %}"} %a{href: "{% url 'legislature:group_index' kind='group' %}"}
Parties Parties
%li %li
%a{href: "{% url 'legislature:groups_by_kind' 'delegation' %}"} %a{href: "{% url 'legislature:group_index' kind='delegation' %}"}
Delegations Delegations
%li %li
%a{href: "{% url 'legislature:groups_by_kind' 'committee' %}"} %a{href: "{% url 'legislature:group_index' kind='committee' %}"}
Committees Committees
%ul.nav-bar %ul.nav-bar
%li %li
%a{href: "{% url 'votes:votes_index' %}"} %a{href: "{% url 'votes:dossier_index' %}"}
Votes Votes
%li
%em By :
-# Pagination block display pagination for the `object_list`
`object_list` could be generated with core.view_utils.render_paginate_list
.pagination
%span.step-links
- if object_list.has_previous
%a{'href': '?={queries.urlencode}&page=={object_list.previous_page_number}'} previous
%span.current
Page ={object_list.number} of ={object_list.paginator.num_pages}
- if object_list.has_next
%a{'href': '?={queries.urlencode}&page=={object_list.next_page_number}'} next
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
.row .row
.large-8.columns .large-8.columns
%p %p
Actually Memopol is actually reachable only in <b>reduced functionality mode</b>. By the way, you could access to <a href="/representatives">the actual list of MEPs</a>. Actually Memopol is reachable only in <b>reduced functionality mode</b>.
By the way, you could access to <a href="{% url 'legislature:representative_index' %}">the actual list of MEPs</a>.
%p %p
You can help on building the new Memopol by <a href="https://wiki.laquadrature.net/Projects/Memopol/Roadmap">coding, translating, de signing, funding, etc...</a>. You can help on building the new Memopol by <a href="https://wiki.laquadrature.net/Projects/Memopol/Roadmap">coding, translating, de signing, funding, etc...</a>.
%p %p
......
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from __future__ import absolute_import
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render
def render_paginate_list(request, object_list, template_name, num_by_page=30):
"""
Render a paginated list of representatives
"""
paginator = Paginator(object_list, num_by_page)
page = request.GET.get('page')
try:
objects = paginator.page(page)
except PageNotAnInteger:
objects = paginator.page(1)
except EmptyPage:
objects = paginator.page(paginator.num_pages)
context = {}
queries_without_page = request.GET.copy()
if 'page' in queries_without_page:
del queries_without_page['page']
context['queries'] = queries_without_page
context['object_list'] = objects
context['object_count'] = paginator.count
return render(
request,
template_name,
context
)
...@@ -7,7 +7,7 @@ from django.db import models, migrations ...@@ -7,7 +7,7 @@ from django.db import models, migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('representatives', '0003_auto_20150625_1151'), ('representatives', '0003_auto_20150702_1827'),
] ]
operations = [ operations = [
......
...@@ -32,10 +32,6 @@ from core.utils import create_child_instance_from_parent ...@@ -32,10 +32,6 @@ from core.utils import create_child_instance_from_parent
class MemopolRepresentative(Representative): class MemopolRepresentative(Representative):
# parent_identifier = 'fingerprint'
# representative_finger = models.CharField(max_length=255, unique=True)
country = models.ForeignKey(Country, null=True) country = models.ForeignKey(Country, null=True)
score = models.IntegerField(default=0) score = models.IntegerField(default=0)
...@@ -81,13 +77,6 @@ class MemopolRepresentative(Representative): ...@@ -81,13 +77,6 @@ class MemopolRepresentative(Representative):
self.country = None self.country = None
self.save() self.save()
@cached_property
def votes(self):
return Vote.objects.filter(
representative_remote_id = self.remote_id
)
def active_mandates(self): def active_mandates(self):
return self.mandates.filter( return self.mandates.filter(
end_date__gte=datetime.now() end_date__gte=datetime.now()
...@@ -108,7 +97,7 @@ class MemopolRepresentative(Representative): ...@@ -108,7 +97,7 @@ class MemopolRepresentative(Representative):
def create_memopolrepresentative_from_representative(instance, **kwargs): def create_memopolrepresentative_from_representative(instance, **kwargs):
memopol_representative = create_child_instance_from_parent(MemopolRepresentative, instance) memopol_representative = create_child_instance_from_parent(MemopolRepresentative, instance)
memopol_representative.update_country() memopol_representative.update_country()
memopol_representative.save()
@receiver(post_save, sender=Mandate) @receiver(post_save, sender=Mandate)
def update_memopolrepresentative_country(instance, created, **kwargs): def update_memopolrepresentative_country(instance, created, **kwargs):
......
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from datetime import datetime from datetime import datetime
from django.http import Http404
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q from django.db.models import Q
...@@ -7,22 +27,19 @@ from django.db.models import Q ...@@ -7,22 +27,19 @@ from django.db.models import Q
from representatives.models import Group from representatives.models import Group
from legislature.models import MemopolRepresentative from legislature.models import MemopolRepresentative
def retrieve(request, pk=None, name=None):
def representatives_index(request): if pk:
representative_list = _filter_by_search( representative = get_object_or_404(
request, MemopolRepresentative,
MemopolRepresentative.objects.filter( id=pk
active=True
)
) )
return _render_list(request, representative_list) elif name:
def representative_by_name(request, name):
representative = get_object_or_404( representative = get_object_or_404(
MemopolRepresentative, MemopolRepresentative,
full_name=name full_name=name
) )
else:
return Http404()
return render( return render(
request, request,
...@@ -30,16 +47,6 @@ def representative_by_name(request, name): ...@@ -30,16 +47,6 @@ def representative_by_name(request, name):
{'representative': representative} {'representative': representative}
) )
def representative_view(request, id):
representative = get_object_or_404(MemopolRepresentative, pk=id)
return render(
request,
'legislature/representative_view.html',
{'representative': representative}
)
def representatives_by_group(request, group_kind, group_abbr=None, def representatives_by_group(request, group_kind, group_abbr=None,
group_name=None, search=None, group_id=None): group_name=None, search=None, group_id=None):
if group_id: if group_id:
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
%h1= representative.full_name %h1= representative.full_name
%h2 %h2
SCORE : {{ representative.extra.score }} SCORE : {{ representative.score }}
%p %p
%strong %strong
%a{:href => "{{ representative.current_group_mandate|by_group_url }}"} %a{:href => "{{ representative.current_group_mandate|by_group_url }}"}
...@@ -25,8 +24,19 @@ ...@@ -25,8 +24,19 @@
%p= representative.country.name %p= representative.country.name
-# Mandates -# Mandates
%div{:style => "clear: both"}
%h2 Votes
%ul
- for vote in representative.votes.all
%li
={vote.proposal.recommendation.title} -
={vote.position}
(recommendation: ={vote.proposal.recommendation.recommendation})
%h2{:style => "clear: both"} Mandates %h2 Mandates
- for mandate in representative.active_mandates - for mandate in representative.active_mandates
.mandate .mandate
......
- extends 'base.html'
- load by_group_url
- block content
- include 'legislature/search.html'
%p
Number of representatives: {{ object_count }}
%table
- for representative in object_list
%tr
%td
%a{'href': "{% url 'legislature:representative_detail' name=representative.slug %}"}
%img{'src': '={representative.photo}', 'width': '80'}/
%td
%a{'href': "{% url 'legislature:representative_detail' name=representative.slug %}"}
={representative.full_name}
%td
%a{'href': "{% url 'legislature:representative_index' group_kind='country' group=representative.country.code %}"}
={representative.country.name}
%td
%a{'href': "{{ representative.current_group_mandate|by_group_url }}"}
={representative.current_group_mandate.group.abbreviation}
%td
={representative.score}
- include "core/blocks/pagination.html"
- extends 'base.html'
- block content
- include 'legislature/search.html'
%p
Number of representatives: {{ representative_num }}
%table
- for representative in representatives
%tr
- include 'legislature/representative_block.html'
.pagination
%span.step-links
- if representatives.has_previous
%a{'href': '?={queries.urlencode}&page=={representatives.previous_page_number}'} previous
%span.current
Page ={representatives.number} of ={representatives.paginator.num_pages}
- if representatives.has_next
%a{'href': '?={queries.urlencode}&page=={representatives.next_page_number}'} next
...@@ -17,13 +17,13 @@ def by_group_url(group): ...@@ -17,13 +17,13 @@ def by_group_url(group):
kwargs = {'group_kind': group.kind} kwargs = {'group_kind': group.kind}
if group.abbreviation: if group.abbreviation:
kwargs['search'] = group.abbreviation kwargs['group'] = group.abbreviation
else: else:
kwargs['search'] = group.name kwargs['group'] = group.name
kwargs['group_id'] = group.id # kwargs['group_id'] = group.id
return reverse( return reverse(
'legislature:representatives_by_group', 'legislature:representative_index',
kwargs=kwargs kwargs=kwargs
) )
from django.conf.urls import patterns, url from django.conf.urls import url
from . import views from views import representative
from views import group
urlpatterns = patterns( urlpatterns = [
'', # List of groups by group kind
url( url(
r'^representatives/?$', r'^groups/(?P<kind>\w+)?$',
views.representatives_index, group.index,
name='representatives_index' name='group_index'
), ),
# Representative detail by representative name
url( url(
r'^representatives/view/(?P<num>\d+)$', r'^(?P<name>[-\w]+)$',
views.representative_view, representative.detail,
name='representative_view' name='representative_detail'
), ),
# Representative detail by representative pk
url( url(
r'^representatives/(?P<group_kind>\w+)/(?P<search>.+)/(?P<group_id>\d+)?$', r'^(?P<pk>\d+)$',
views.representatives_by_group, representative.detail,
name='representatives_by_group' name='representative_detail'
), ),
# List of representatives by group kind and group name or pk
url( url(
r'^representatives/(?P<name>.+)$', r'^(?P<group_kind>\w+)/(?P<group>.+)$',
views.representative_by_name, representative.index,
name='representative_view_by_name' name='representative_index'
), ),
# List all representatives by default
url( url(
r'^groups/(?P<kind>\w+)$', r'',
views.groups_by_kind, representative.index,
name='groups_by_kind' name='representative_index'
) ),
) ]
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render
def render_paginate_list(request, object_list, template_name, num_by_page=30):
"""
Render a paginated list of representatives
"""
paginator = Paginator(object_list, num_by_page)
page = request.GET.get('page')
try:
objects = paginator.page(page)
except PageNotAnInteger:
objects = paginator.page(1)
except EmptyPage:
objects = paginator.page(paginator.num_pages)
context = {}
queries_without_page = request.GET.copy()
if 'page' in queries_without_page:
del queries_without_page['page']
context['queries'] = queries_without_page
context['object_list'] = objects
context['object_count'] = paginator.count
return render(
request,
template_name,
context
)
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from datetime import datetime
from django.shortcuts import render
from representatives.models import Group
def index(request, kind=None):
groups = Group.objects.filter(
mandates__end_date__gte=datetime.now()
)
if kind:
groups = groups.filter(
kind=kind
)
print(groups)
groups = groups.distinct().order_by('name')
return render(
request,
'legislature/groups_list.html',
{'groups': groups}
)
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from __future__ import absolute_import
from datetime import datetime
from django.db.models import Q
from django.shortcuts import render, get_object_or_404
from django.http import Http404