Commit 2b4bf0bb authored by luxcem's avatar luxcem

updates representatives

parent 0c951424
......@@ -34,9 +34,9 @@ from representatives.utils import import_representatives
class Command(BaseCommand):
def handle(self, *args, **options):
compotista_server = getattr(settings,
'REPRESENTATIVES_COMPOTISTA_SERVER',
'COMPOTISTA_SERVER',
'http://compotista.mm.staz.be')
url = compotista_server + "/latest/"
url = compotista_server + 'export/latest/'
print('Import representatives from %s' % url)
stream = BytesIO(urlopen(url))
import_representatives(JSONParser().parse(stream))
stream = BytesIO(urlopen(url).read())
import_representatives(JSONParser().parse(stream), True)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('representatives', '0010_auto_20150527_1401'),
]
operations = [
migrations.AlterField(
model_name='phone',
name='address',
field=models.ForeignKey(to='representatives.Address', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='phone',
name='number',
field=models.CharField(max_length=255, null=True),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('representatives', '0011_auto_20150528_1608'),
]
operations = [
migrations.AlterField(
model_name='phone',
name='number',
field=models.CharField(max_length=255, null=True, blank=True),
preserve_default=True,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('representatives', '0012_auto_20150528_1611'),
]
operations = [
migrations.AlterField(
model_name='website',
name='url',
field=models.CharField(max_length=2048, null=True, blank=True),
preserve_default=True,
),
]
......@@ -72,7 +72,7 @@ class Email(Contact):
class WebSite(Contact):
url = models.URLField()
url = models.CharField(max_length=2048, blank=True, null=True)
kind = models.CharField(max_length=255, blank=True, null=True)
......@@ -90,7 +90,7 @@ class Address(Contact):
class Phone(Contact):
number = models.CharField(max_length=255)
number = models.CharField(max_length=255, blank=True, null=True)
kind = models.CharField(max_length=255, blank=True, null=True)
address = models.ForeignKey(Address, null=True)
......
......@@ -23,13 +23,19 @@ from representatives.models import Representative
from representatives.serializers import RepresentativeDetailSerializer
# Import a representative
def import_a_representative(data):
def import_a_representative(data, verbose=False):
serializer = RepresentativeDetailSerializer(data=data)
serializer.is_valid()
return serializer.save()
def import_representatives(data):
return [import_a_representative(r_data) for r_data in data]
if serializer.is_valid():
representative = serializer.save()
if verbose:
print(representative)
return representative
else:
print(data)
raise Exception(serializer.errors)
def import_representatives(data, verbose=False):
return [import_a_representative(r_data, verbose) for r_data in data]
# Export
def export_a_representative(representative):
......
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