forked from DGNum/gestioCOF
c217b549bd
- The models are moved to the `gestion` app - A new field `associations` is added - The location and datetime fields are removed in favour of a new model `EventTimeSlot` - The old events are migrated to the new app and linked to the `cof_buro` association
159 lines
7.2 KiB
Python
159 lines
7.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.11b1 on 2017-03-18 20:02
|
|
from __future__ import unicode_literals
|
|
|
|
from django.conf import settings
|
|
from django.db import migrations, models
|
|
import django.db.models.deletion
|
|
|
|
|
|
def import_events(apps, schema_editor):
|
|
# Fetching the cof group
|
|
cof = apps.get_model("auth", "Group").objects.get(name="cof_buro")
|
|
|
|
# First we deal with Events and Timeslots
|
|
OldEvent = apps.get_model("cof", "Event")
|
|
NewEvent = apps.get_model("gestion", "Event")
|
|
TimeSlot = apps.get_model("gestion", "EventTimeSlot")
|
|
# TODO: can it be done more efficiently?
|
|
for event in OldEvent.objects.all():
|
|
new_event = NewEvent.objects.create(
|
|
title=event.title,
|
|
description=event.description,
|
|
image=event.image,
|
|
registration_open=event.registration_open,
|
|
old=event.old
|
|
)
|
|
new_event.associations.add(cof)
|
|
TimeSlot.objects.create(
|
|
event=new_event,
|
|
location=event.location,
|
|
start_date=event.start_date,
|
|
end_date=event.end_date
|
|
)
|
|
|
|
# Then we migrate the other models
|
|
model_names = [
|
|
"EventCommentField", "EventCommentValue", "EventOption",
|
|
"EventOptionChoice", "EventRegistration"
|
|
]
|
|
models = [
|
|
(apps.get_model("cof", name), apps.get_model("gestion", name))
|
|
for name in model_names
|
|
]
|
|
for OldModel, NewModel in models:
|
|
NewModel.objects.bulk_create([
|
|
NewModel(**values)
|
|
for values in OldModel.objects.values()
|
|
])
|
|
|
|
|
|
def restore_events(apps, schema_editor):
|
|
raise NotImplementedError
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
('auth', '0008_alter_user_username_max_length'),
|
|
('gestion', '0002_club_support'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='Event',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('title', models.CharField(max_length=200, verbose_name='Titre')),
|
|
('description', models.TextField(blank=True, verbose_name='Description')),
|
|
('image', models.ImageField(blank=True, null=True, upload_to='imgs/events/', verbose_name='Image')),
|
|
('registration_open', models.BooleanField(default=True, verbose_name='Inscriptions ouvertes')),
|
|
('old', models.BooleanField(default=False, verbose_name='Archiver (événement fini)')),
|
|
('associations', models.ManyToManyField(related_name='events', to='auth.Group')),
|
|
],
|
|
options={
|
|
'verbose_name': 'Événement',
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='EventTimeSlot',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('location', models.CharField(max_length=200, verbose_name='Lieu')),
|
|
('start_date', models.DateTimeField(blank=True, null=True, verbose_name='Date de début')),
|
|
('end_date', models.DateTimeField(blank=True, null=True, verbose_name='Date de fin')),
|
|
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gestion.Event')),
|
|
],
|
|
),
|
|
migrations.CreateModel(
|
|
name='EventCommentField',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('name', models.CharField(max_length=200, verbose_name='Champ')),
|
|
('fieldtype', models.CharField(choices=[('text', 'Texte long'), ('char', 'Texte court')], default='text', max_length=10, verbose_name='Type')),
|
|
('default', models.TextField(blank=True, verbose_name='Valeur par défaut')),
|
|
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commentfields', to='gestion.Event')),
|
|
],
|
|
options={
|
|
'verbose_name': 'Champ',
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='EventCommentValue',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('content', models.TextField(blank=True, null=True, verbose_name='Contenu')),
|
|
('commentfield', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='values', to='gestion.EventCommentField')),
|
|
],
|
|
),
|
|
migrations.CreateModel(
|
|
name='EventOption',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('name', models.CharField(max_length=200, verbose_name='Option')),
|
|
('multi_choices', models.BooleanField(default=False, verbose_name='Choix multiples')),
|
|
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='gestion.Event')),
|
|
],
|
|
options={
|
|
'verbose_name': 'Option des événements',
|
|
'verbose_name_plural': 'Options des événements'
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='EventOptionChoice',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('value', models.CharField(max_length=200, verbose_name='Valeur')),
|
|
('event_option', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choices', to='gestion.EventOption')),
|
|
],
|
|
options={
|
|
'verbose_name_plural': 'Choix',
|
|
'verbose_name': 'Choix',
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='EventRegistration',
|
|
fields=[
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('paid', models.BooleanField(default=False, verbose_name='A payé')),
|
|
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gestion.Event')),
|
|
('filledcomments', models.ManyToManyField(through='gestion.EventCommentValue', to='gestion.EventCommentField')),
|
|
('options', models.ManyToManyField(to='gestion.EventOptionChoice')),
|
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
|
],
|
|
options={
|
|
'verbose_name': 'Inscription',
|
|
},
|
|
),
|
|
migrations.AddField(
|
|
model_name='eventcommentvalue',
|
|
name='registration',
|
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='gestion.EventRegistration'),
|
|
),
|
|
migrations.AlterUniqueTogether(
|
|
name='eventregistration',
|
|
unique_together=set([('user', 'event')]),
|
|
),
|
|
migrations.RunPython(import_events, restore_events),
|
|
]
|