Write data migrations for kaehmys

This commit is contained in:
Jan Tuomi
2018-01-28 23:22:54 +02:00
parent 661dc84973
commit ce1f4eb7c9
5 changed files with 98 additions and 4 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('webapp', '0038_auto_20180126_0031'),
('webapp', '0037_auto_20180125_2131'),
]
operations = [
+8 -1
View File
@@ -1,7 +1,7 @@
"""Translation classes."""
from modeltranslation.translator import register, TranslationOptions
from kaehmy.models import PresetRole
from kaehmy.models import PresetRole, CustomRole
@register(PresetRole)
@@ -9,3 +9,10 @@ class PresetRoleTranslationOptions(TranslationOptions):
""" Class for PresetRole translation options"""
fields = ()
@register(CustomRole)
class CustomRoleTranslationOptions(TranslationOptions):
""" Class for CustomROle translation options"""
fields = ()
+87
View File
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-01-28 19:49
from __future__ import unicode_literals
from django.db import migrations
def migrate_kaehmys(apps, schema_editor):
WebappTelegramChannel = apps.get_model('webapp', 'TelegramChannel')
KaehmyTelegramChannel = apps.get_model('kaehmy', 'TelegramChannel')
for channel in WebappTelegramChannel.objects.all():
KaehmyTelegramChannel.objects.create(
id=channel.id,
name=channel.name,
channel_id=channel.channel_id
)
WebappCustomKaehmyRole = apps.get_model('webapp', 'CustomKaehmyRole')
KaehmyCustomRole = apps.get_model('kaehmy', 'CustomRole')
for role in WebappCustomKaehmyRole.objects.all():
KaehmyCustomRole.objects.create(
id=role.id,
name=role.name,
is_board=role.is_board,
category=role.category,
name_fi=role.name_fi,
name_en=role.name_en,
)
WebappPresetKaehmyRole = apps.get_model('webapp', 'PresetKaehmyRole')
KaehmyPresetRole = apps.get_model('kaehmy', 'PresetRole')
for role in WebappPresetKaehmyRole.objects.all():
KaehmyPresetRole.objects.create(
id=role.id,
name=role.name,
is_board=role.is_board,
category=role.category,
description=role.description,
name_fi=role.name_fi,
name_en=role.name_en,
description_fi=role.description_fi,
description_en=role.description_en,
)
WebappKaehmyForm = apps.get_model('webapp', 'KaehmyForm')
KaehmyApplication = apps.get_model('kaehmy', 'Application')
for form in WebappKaehmyForm.objects.all():
application = KaehmyApplication.objects.create(
id=form.id,
name=form.name,
email=form.email,
timestamp=form.timestamp,
phone_number=form.phone_number,
year=form.year,
text=form.text,
custom_role_name=form.custom_role_name,
custom_role_is_board=form.custom_role_is_board,
)
for custom_role in form.custom_roles.all():
role = KaehmyCustomRole.objects.get(id=custom_role.id)
application.custom_roles.add(role)
for preset_role in form.preset_roles.all():
role = KaehmyPresetRole.objects.get(id=preset_role.id)
application.preset_roles.add(role)
WebappKaehmyMessage = apps.get_model('webapp', 'KaehmyMessage')
KaehmyComment = apps.get_model('kaehmy', 'Comment')
for message in WebappKaehmyMessage.objects.all():
KaehmyComment.objects.create(
id=message.id,
message=message.message,
parent=message.parent.id,
)
class Migration(migrations.Migration):
dependencies = [
('webapp', '0037_auto_20180125_2131'),
('kaehmy', '0001_initial'),
]
operations = [
migrations.RunPython(migrate_kaehmys),
]
@@ -8,7 +8,7 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('webapp', '0037_auto_20180125_2131'),
('webapp', '0038_migrate_kaehmy'),
]
operations = [
@@ -8,7 +8,7 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('webapp', '0038_auto_20180126_0031'),
('webapp', '0039_delete_kaehmy_models'),
]
operations = [