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

Improvement of representatives pages

parent 27d3dfe5
- load representatives_extras - load representatives_extras
- load humanize
.representative .representative
...@@ -30,4 +31,5 @@ ...@@ -30,4 +31,5 @@
%th Biography %th Biography
%td %td
Born in {{ representative.birth_place }} the Born in {{ representative.birth_place }} the
{{ representative.birth_date }} ({{ representative.get_gender_display }}) {{ representative.birth_date|naturalday:'d/m/Y' }}
({{ representative.get_gender_display }})
-# List representatives' groups -# List representatives' groups
- extends 'base.html' - extends 'base.html'
- load by_group_url - load representatives_extras
- block content - block content
%table.table %table.table
......
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
%td %td
%a{:href => "{{ mandate|by_group_url }}"} %a{:href => "{{ mandate|by_group_url }}"}
{{ mandate.group.name }} ({{ mandate.group.abbreviation }}) {{ mandate.group.name }} ({{ mandate.group.abbreviation }})
%td= mandate.begin_date %td= mandate.begin_date|mandate_date:'d/m/Y'
%td= mandate.end_date %td= mandate.end_date|mandate_date:'d/m/Y'
%td= mandate.constituency.name %td= mandate.constituency.name
.positions .positions
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
%table.table.table-condensed %table.table.table-condensed
- for position in representative.positions.published.all - for position in representative.positions.published.all
%tr.position %tr.position
%td= position.datetime|naturalday:"d/m/Y" %td= position.datetime|naturalday:'d/m/Y'
%td %td
%a{:href => '{% url "positions:position-detail" position.pk %}'} %a{:href => '{% url "positions:position-detail" position.pk %}'}
=position.text|truncatewords:8 =position.text|truncatewords:8
......
from django import template
from django.core.urlresolvers import reverse
from representatives.models import Mandate, Group
register = template.Library()
@register.filter
def by_group_url(group):
if isinstance(group, Mandate):
group = group.group
if not isinstance(group, Group):
return ''
kwargs = {'group_kind': group.kind}
if group.abbreviation:
kwargs['group'] = group.abbreviation
else:
kwargs['group'] = group.name
# kwargs['group_id'] = group.id
return reverse(
'legislature:representative-index',
kwargs=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>
"""
This file contains all templatetags used by the representative app
"""
from django import template from django import template
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.contrib.humanize.templatetags.humanize import naturalday
from representatives.models import Mandate, Group from representatives.models import Mandate, Group
register = template.Library() register = template.Library()
@register.filter
def mandate_date(date, arg=None):
if date.year == 9999:
return 'present'
else:
return naturalday(date, arg)
@register.filter @register.filter
def position_icon(position): def position_icon(position):
if position == 'for': if position == 'for':
...@@ -43,9 +76,9 @@ def score_label(score): ...@@ -43,9 +76,9 @@ def score_label(score):
@register.filter @register.filter
def country_flag(country): def country_flag(country):
return mark_safe('{} <span class="flag-icon flag-icon-{}"></span>'.format( return mark_safe('<span class="flag-icon flag-icon-{code}"></span> {name}'.format(
country.name, name=country.name,
country.code.lower() code=country.code.lower()
)) ))
......
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