Commit 01b175ca authored by Nicolas Joyard's avatar Nicolas Joyard

Add chamber abbreviation and chamber templatetag

parent eea37506
......@@ -97,7 +97,8 @@ class FranceDataImporter(GenericImporter):
self.france = Country.objects.get(name="France")
self.variant = FranceDataVariants[variant]
self.chamber, _ = Chamber.objects.get_or_create(
name=self.variant['chamber'], country=self.france)
name=self.variant['chamber'],
abbreviation=self.variant['abbreviation'], country=self.france)
self.ch_constituency, _ = Constituency.objects.get_or_create(
name=self.variant['chamber'], country=self.france)
......
......@@ -207,7 +207,8 @@
{
"fields": {
"country": 1095,
"name": "Assembl\u00e9e nationale"
"name": "Assembl\u00e9e nationale",
"abbreviation": "AN"
},
"model": "representatives.chamber",
"pk": 1
......@@ -215,7 +216,8 @@
{
"fields": {
"country": 1095,
"name": "S\u00e9nat"
"name": "S\u00e9nat",
"abbreviation": "SEN"
},
"model": "representatives.chamber",
"pk": 2
......
......@@ -201,6 +201,7 @@ def _get_an_delegations(json):
FranceDataVariants = {
"AN": {
"chamber": u"Assemblée nationale",
"abbreviation": "AN",
"remote_id_field": "url_an",
"mail_domain": "@assemblee-nationale.fr",
"off_city": "Paris",
......@@ -260,6 +261,7 @@ FranceDataVariants = {
"SEN": {
"chamber": u"Sénat",
"abbreviation": "SEN",
"remote_id_field": "url_institution",
"mail_domain": "@senat.fr",
"off_city": "Paris",
......
......@@ -66,7 +66,7 @@ class ParltrackImporter(GenericImporter):
'countries': {c.name: c.pk for c in Country.objects.all()},
}
self.ep_chamber, _ = Chamber.objects.get_or_create(
name='European Parliament')
name='European Parliament', abbreviation='EP')
self.ep_constituency, _ = Constituency.objects.get_or_create(
name='European Parliament')
self.ep_group, _ = Group.objects.get_or_create(
......
......@@ -126,7 +126,8 @@
{
"fields": {
"country": null,
"name": "European Parliament"
"name": "European Parliament",
"abbreviation": "EP"
},
"model": "representatives.chamber",
"pk": 1
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('representatives', '0014_chamber'),
]
operations = [
migrations.AddField(
model_name='chamber',
name='abbreviation',
field=models.CharField(default=b'', max_length=10, db_index=True, blank=True),
),
]
......@@ -170,8 +170,13 @@ class Chamber(HashableModel):
"""
name = models.CharField(max_length=255)
country = models.ForeignKey('Country', null=True, related_name='chambers')
abbreviation = models.CharField(max_length=10, blank=True, default='',
db_index=True)
hashable_fields = ['name', 'country']
hashable_fields = ['name', 'country', 'abbreviation']
def __unicode__(self):
return u'{} [{}]'.format(self.name, self.abbreviation)
class Group(HashableModel, TimeStampedModel):
......
......@@ -13,6 +13,15 @@ def country_flag(country):
code=country.code.lower()))
@register.filter
def chamber_icon(chamber):
return mark_safe(
u'<span class="chamber-icon ' +
u'chamber-icon-{abbr}"></span> {name}'.format(
name=chamber.name,
abbr=chamber.abbreviation.lower()))
@register.filter
def mandate_date(date, arg=None):
if date.year == 9999:
......
......@@ -23,7 +23,8 @@ class RepresentativeViewMixin(object):
Prefetch Mandates with their Group and Constituency with Country.
"""
mandates = Mandate.objects.order_by(
'-end_date').select_related('constituency__country', 'group')
'-end_date').select_related('constituency__country', 'group',
'group__chamber')
return queryset.prefetch_related(
models.Prefetch('mandates', queryset=mandates))
......
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