# Generated by Django 2.1.7 on 2019-07-28 18:08

from django.db import migrations


def migrate(apps, schema_editor):
    """Read self-organized workshop requests from workshops.WorkshopRequest
    model and migrate them to extrequests.SelfOrganizedSubmission model."""
    WorkshopRequest = apps.get_model('workshops', 'WorkshopRequest')
    SelfOrganizedSubmission = apps.get_model('extrequests',
                                             'SelfOrganizedSubmission')

    self_org_wr = WorkshopRequest.objects.filter(organization_type='self')

    for wr in self_org_wr:
        sos = SelfOrganizedSubmission.objects.create(
            created_at=wr.created_at,
            last_updated_at=wr.last_updated_at,
            state=wr.state,
            assigned_to=wr.assigned_to,
            event=wr.event,

            personal=wr.personal,
            family=wr.family,
            email=wr.email,
            institution=wr.institution,
            institution_other_name=wr.institution_other_name,
            institution_other_URL=wr.institution_other_URL,
            institution_department=wr.institution_department,

            workshop_format='',
            workshop_format_other='Migration from WorkshopRequest; question absent',
            workshop_url=wr.self_organized_github,
            workshop_types_other='',
            workshop_types_other_explain='',
            country=wr.country,
            language=wr.language,

            public_event=wr.public_event,
            public_event_other=wr.public_event_other,
            additional_contact=wr.additional_contact,

            data_privacy_agreement=wr.data_privacy_agreement,
            code_of_conduct_agreement=wr.code_of_conduct_agreement,
            host_responsibilities=wr.host_responsibilities,
        )
        sos.workshop_types.set(wr.requested_workshop_types.all())

    self_org_wr.delete()


class Migration(migrations.Migration):

    dependencies = [
        ('extrequests', '0005_auto_20190728_1118'),
    ]

    operations = [
        migrations.RunPython(migrate),
    ]
