Commit a221108f authored by Nicolas Joyard's avatar Nicolas Joyard

Include birthdate in slugs

Needed because names are not unique (already 2 cases of 2 meps with the same name)
parent c37e9159
......@@ -135,10 +135,11 @@ class FranceDataImporter(GenericImporter):
return
changed = False
slug = slugify(
slug = slugify('%s-%s' % (
rep_json['nom'] if 'nom' in rep_json
else rep_json['prenom'] + " " + rep_json['nom_de_famille']
)
else rep_json['prenom'] + " " + rep_json['nom_de_famille'],
_parse_date(rep_json["date_naissance"])
))
try:
representative = Representative.objects.get(slug=slug)
......
......@@ -10,7 +10,7 @@
"full_name": "Bernard Roman",
"photo": "http://www.nosdeputes.fr/depute/photo/bernard-roman",
"birth_date": "1952-07-15",
"slug": "bernard-roman"
"slug": "bernard-roman-1952-07-15"
},
"model": "representatives.representative",
"pk": 1
......@@ -26,7 +26,7 @@
"full_name": "David Assouline",
"photo": "http://www.nossenateurs.fr/senateur/photo/david-assouline",
"birth_date": "1959-06-16",
"slug": "david-assouline"
"slug": "david-assouline-1959-06-16"
},
"model": "representatives.representative",
"pk": 2
......
......@@ -91,10 +91,11 @@ class ParltrackImporter(GenericImporter):
return
changed = False
slug = slugify(
slug = slugify('%s-%s' % (
mep_json["Name"]["full"] if 'full' in mep_json["Name"]
else mep_json["Name"]["sur"] + " " + mep_json["Name"]["family"]
)
else mep_json["Name"]["sur"] + " " + mep_json["Name"]["family"],
_parse_date(mep_json["Birth"]["date"])
))
try:
representative = Representative.objects.get(slug=slug)
except Representative.DoesNotExist:
......
......@@ -10,7 +10,7 @@
"birth_place": "Gries",
"full_name": "Hubert PIRKER",
"birth_date": "1948-10-03",
"slug": "hubert-pirker"
"slug": "hubert-pirker-1948-10-03"
},
"model": "representatives.representative",
"pk": 1
......@@ -26,7 +26,7 @@
"birth_place": "H\u00e4ls\u00f6",
"full_name": "Olle LUDVIGSSON",
"birth_date": "1948-10-28",
"slug": "olle-ludvigsson"
"slug": "olle-ludvigsson-1948-10-28"
},
"model": "representatives.representative",
"pk": 2
......
......@@ -6,6 +6,19 @@ import datetime
from django.db import connection, migrations, models
def update_slugs(apps, schema_editor):
"""
Include birthdate in slugs
"""
# Get model managers
Representative = apps.get_model("representatives", "Representative")
for rep in Representative.objects.all():
rep.slug = '%s-%s' % (rep.slug, rep.birth_date)
rep.save()
def create_parl_websites(apps, schema_editor):
"""
Prepare for remote_id removal by creating WebSite entities from it.
......@@ -73,6 +86,8 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_slugs),
migrations.RunPython(create_parl_websites),
migrations.RemoveField(
......
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