GetTogether/events/migrations/0015_populate_searchable_uri.py

26 lines
872 B
Python

# Generated by Django 2.0 on 2018-03-11 06:32
from django.db import migrations
import hashlib
def gen_event_uris(apps, schema_editor):
Event = MyModel = apps.get_model('events', 'Event')
Searchable = MyModel = apps.get_model('events', 'Searchable')
for searchable in Searchable.objects.all():
md5 = hashlib.md5()
federation_url = searchable.event_url.split('/')
federation_node = '/'.join(federation_url[:3])
federation_id = '/'.join(federation_url[:5])
md5.update(bytes(federation_id, 'utf8'))
searchable.event_uri = federation_node + '/' + md5.hexdigest()
searchable.save()
class Migration(migrations.Migration):
dependencies = [
('events', '0014_add_searchable_uri'),
]
operations = [
migrations.RunPython(gen_event_uris, reverse_code=migrations.RunPython.noop)
]