2017-03-18 21:48:17 +01:00
|
|
|
# -*- 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):
|
2017-04-05 01:00:41 +02:00
|
|
|
# Fetching the models that have be moved from cof to gestion
|
2017-03-18 21:48:17 +01:00
|
|
|
model_names = [
|
2017-04-05 01:00:41 +02:00
|
|
|
"Event", "EventCommentField", "EventCommentValue", "EventOption",
|
2017-03-18 21:48:17 +01:00
|
|
|
"EventOptionChoice", "EventRegistration"
|
|
|
|
]
|
|
|
|
models = [
|
|
|
|
(apps.get_model("cof", name), apps.get_model("gestion", name))
|
|
|
|
for name in model_names
|
|
|
|
]
|
2017-04-05 01:00:41 +02:00
|
|
|
|
2017-04-11 03:48:39 +02:00
|
|
|
# The old Event.location field becomes a table: we need to create an entry
|
|
|
|
# in this table for each value of the old `location` field.
|
|
|
|
OldEvent, NewEvent = models[0]
|
|
|
|
Location = apps.get_model("gestion", "Location")
|
2017-05-14 16:47:07 +02:00
|
|
|
locations = set() # A set to prevent duplicate entries
|
2017-04-11 03:48:39 +02:00
|
|
|
events = []
|
|
|
|
for event in OldEvent.objects.values():
|
2017-05-14 16:47:07 +02:00
|
|
|
locations.add(event["location"])
|
2017-04-11 03:48:39 +02:00
|
|
|
events.append(event)
|
2017-05-14 16:47:07 +02:00
|
|
|
Location.objects.bulk_create([Location(name=name) for name in locations])
|
2017-04-11 03:48:39 +02:00
|
|
|
map_loc = {
|
|
|
|
loc.name: loc
|
|
|
|
for loc in Location.objects.all()
|
|
|
|
}
|
|
|
|
for event in events:
|
|
|
|
event["location"] = map_loc[event["location"]]
|
|
|
|
NewEvent.objects.bulk_create([
|
|
|
|
NewEvent(**event)
|
|
|
|
for event in events
|
|
|
|
])
|
2017-03-18 21:48:17 +01:00
|
|
|
|
2017-04-11 03:48:39 +02:00
|
|
|
# Do not forget to link all the existing event to the COF group
|
2017-04-05 01:00:41 +02:00
|
|
|
cof = apps.get_model("auth", "Group").objects.get(name="cof_buro")
|
|
|
|
for event in NewEvent.objects.all():
|
|
|
|
event.associations.add(cof)
|
|
|
|
|
2017-04-11 03:48:39 +02:00
|
|
|
# Migrating the other models is straigtforward
|
|
|
|
for OldModel, NewModel in models[1:]:
|
|
|
|
NewModel.objects.bulk_create([
|
|
|
|
NewModel(**values)
|
|
|
|
for values in OldModel.objects.values()
|
|
|
|
])
|
|
|
|
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
def restore_events(apps, schema_editor):
|
2017-04-11 03:48:39 +02:00
|
|
|
# TODO?
|
2017-03-18 21:48:17 +01:00
|
|
|
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 = [
|
2017-04-11 03:48:39 +02:00
|
|
|
migrations.CreateModel(
|
|
|
|
name='Location',
|
|
|
|
fields=[
|
|
|
|
(
|
|
|
|
'id',
|
|
|
|
models.AutoField(
|
|
|
|
auto_created=True,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
verbose_name='ID'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'name',
|
|
|
|
models.CharField(max_length=200, verbose_name='Lieu')
|
|
|
|
),
|
|
|
|
],
|
|
|
|
options={
|
|
|
|
'verbose_name': 'lieu',
|
|
|
|
'verbose_name_plural': 'lieux',
|
|
|
|
},
|
|
|
|
),
|
2017-03-18 21:48:17 +01:00
|
|
|
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')),
|
2017-04-11 03:48:39 +02:00
|
|
|
('location', models.ForeignKey(
|
|
|
|
on_delete=django.db.models.deletion.PROTECT,
|
|
|
|
to='gestion.Location'
|
|
|
|
)),
|
2017-04-05 01:00:41 +02:00
|
|
|
('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')),
|
2017-03-18 21:48:17 +01:00
|
|
|
('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='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),
|
|
|
|
]
|