Added a migration to provide plain-name aliases where they are missing, as we expect those for the person profile URLs.
- Legacy-Id: 11319
This commit is contained in:
parent
f7ea6a3376
commit
f384a134c4
32
ietf/person/migrations/0013_add_plain_name_aliases.py
Normal file
32
ietf/person/migrations/0013_add_plain_name_aliases.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
from ietf.person.name import name_parts
|
||||
|
||||
def plain_name(self):
|
||||
prefix, first, middle, last, suffix = name_parts(self.name)
|
||||
if not first and last:
|
||||
return None
|
||||
return u" ".join([first, last])
|
||||
|
||||
def add_plain_name_aliases(apps, schema_editor):
|
||||
Person = apps.get_model('person','Person')
|
||||
Alias = apps.get_model('person','Alias')
|
||||
for person in Person.objects.all():
|
||||
name = plain_name(person)
|
||||
if name and not Alias.objects.filter(name=name):
|
||||
print("Created alias %-24s for %s" % (name, person.name))
|
||||
alias = Alias(name=name, person=person)
|
||||
alias.save()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('person', '0012_auto_20160606_0823'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_plain_name_aliases),
|
||||
]
|
Loading…
Reference in a new issue