Commit 4c13ad12 authored by luxcem's avatar luxcem

Adds fixtures for countries

parent 4eae9c13
This diff is collapsed.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('representatives', '0007_auto_20150323_1017'),
]
operations = [
migrations.AddField(
model_name='representative',
name='active',
field=models.BooleanField(default=False),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
import os
from django.core import serializers
fixture_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../fixtures'))
fixture_filename = 'initial_data.json'
def load_fixture(apps, schema_editor):
fixture_file = os.path.join(fixture_dir, fixture_filename)
fixture = open(fixture_file, 'rb')
objects = serializers.deserialize('json', fixture, ignorenonexistent=True)
for obj in objects:
obj.save()
fixture.close()
def unload_fixture(apps, schema_editor):
"Brutally deleting all entries for this model..."
MyModel = apps.get_model("representatives", "Country")
MyModel.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('representatives', '0008_auto_20150422_0518'),
]
operations = [
migrations.RunPython(load_fixture, reverse_code=unload_fixture),
]
# -*- coding:utf-8 -*-
# coding: utf-8
from django.db import models
......@@ -29,6 +29,8 @@ class Representative(models.Model):
birth_date = models.DateField(blank=True, null=True)
cv = models.TextField(blank=True, null=True)
photo = models.CharField(max_length=512, null=True)
active = models.BooleanField(default=False)
def __unicode__(self):
return self.full_name
......@@ -109,3 +111,4 @@ class Mandate(models.Model):
begin_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
url = models.URLField()
......@@ -13,7 +13,7 @@ def export_a_representative(representative):
reps = {"id": representative.remote_id}
reps["personal"] = {field: getattr(representative, field) for field in PERSONAL_FIELDS}
reps["personal"]["gender"] = GENDER_DICT[representative.gender]
reps["personal"]["birth_date"] = representative.birth_date.strftime("%F") if representative.birth_date else None
reps["personal"]["birth_date"] = representative.birth_date.isoformat().split('T')[0] if representative.birth_date else None
reps["contact"] = {}
......@@ -55,9 +55,9 @@ def export_a_representative(representative):
"url_official": mandate.url,
"constituency": mandate.constituency.name,
"role": mandate.role,
"begin_date": mandate.begin_date.strftime("%F") if mandate.begin_date else None,
"end_date": mandate.end_date.strftime("%F") if mandate.end_date else None,
"current": mandate.active,
"begin_date": mandate.begin_date.isoformat().split('T')[0] if mandate.begin_date else None,
"end_date": mandate.end_date.isoformat().split('T')[0] if mandate.end_date else None,
# "current": mandate.active,
} for mandate in representative.mandate_set.all()]
return reps
......@@ -67,6 +67,10 @@ def export_all_representatives():
return [export_a_representative(representative) for representative in Representative.objects.all()]
def export_active_representatives():
return [export_a_representative(representative) for representative in Representative.objects.filter(active=True)]
def import_representatives_from_format(data, verbose=False):
reverted_gender_dict = {x[1]: x[0] for x in Representative.GENDER}
a = 0
......
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