2017-09-05 14:41:13 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
|
|
|
|
|
|
def clubs_to_gestion(apps, schema_editor):
|
|
|
|
Association = apps.get_model('gestion', 'Association')
|
|
|
|
Membership = apps.get_model('gestion', 'ClubUser')
|
|
|
|
OldClub = apps.get_model('cof', 'Club')
|
|
|
|
NewClub = apps.get_model('gestion', 'Club')
|
|
|
|
|
|
|
|
cof_assoc = Association.objects.get(name='COF')
|
|
|
|
|
|
|
|
memberships = []
|
|
|
|
|
|
|
|
for oldclub in OldClub.objects.all():
|
|
|
|
newclub = NewClub.objects.create(
|
|
|
|
name=oldclub.name,
|
|
|
|
description=oldclub.description,
|
|
|
|
association=cof_assoc,
|
|
|
|
)
|
|
|
|
|
|
|
|
members = oldclub.membres.values_list('id', flat=True)
|
|
|
|
respos = oldclub.respos.values_list('id', flat=True)
|
|
|
|
|
|
|
|
for user in members:
|
|
|
|
memberships.append(
|
|
|
|
Membership(
|
|
|
|
club=newclub,
|
|
|
|
user_id=user,
|
|
|
|
has_paid=True,
|
|
|
|
is_respo=user in respos,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
Membership.objects.bulk_create(memberships)
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
"""
|
|
|
|
This migration focus on migrating clubs data to the 'gestion' app.
|
|
|
|
"""
|
|
|
|
|
|
|
|
dependencies = [
|
2017-10-26 11:06:17 +02:00
|
|
|
('cof', '0014_move_profile'),
|
2017-09-05 14:41:13 +02:00
|
|
|
('gestion', '0002_create_cof_bds'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
# Move clubs from cof to gestion.
|
|
|
|
migrations.RunPython(clubs_to_gestion),
|
|
|
|
|
|
|
|
# Delete legacy Club model.
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='club',
|
|
|
|
name='membres',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='club',
|
|
|
|
name='respos',
|
|
|
|
),
|
|
|
|
migrations.DeleteModel(
|
|
|
|
name='Club',
|
|
|
|
),
|
|
|
|
]
|