Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
django-representatives
Commits
a221108f
Commit
a221108f
authored
Jul 14, 2016
by
Nicolas Joyard
Browse files
Include birthdate in slugs
Needed because names are not unique (already 2 cases of 2 meps with the same name)
parent
c37e9159
Changes
5
Hide whitespace changes
Inline
Side-by-side
representatives/contrib/francedata/import_representatives.py
View file @
a221108f
...
...
@@ -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
)
...
...
representatives/contrib/francedata/tests/representatives_expected.json
View file @
a221108f
...
...
@@ -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
...
...
representatives/contrib/parltrack/import_representatives.py
View file @
a221108f
...
...
@@ -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
:
...
...
representatives/contrib/parltrack/tests/representatives_expected.json
View file @
a221108f
...
...
@@ -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
\u
00e4ls
\u
00f6"
,
"full_name"
:
"Olle LUDVIGSSON"
,
"birth_date"
:
"1948-10-28"
,
"slug"
:
"olle-ludvigsson"
"slug"
:
"olle-ludvigsson
-1948-10-28
"
},
"model"
:
"representatives.representative"
,
"pk"
:
2
...
...
representatives/migrations/0020_rep_unique_slug_remove_remoteid.py
View file @
a221108f
...
...
@@ -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
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment