gestioCOF/gestion/migrations/0002_create_cof_bds.py
Aurélien Delobelle 5d572b3603 Clean supportBDS migrations.
- Fix some issues and improve efficiency of some RunPython code in
migrations.
- Merge some migrations.
- To simplify, any RunPython don't get a revert function.
2017-09-05 14:41:13 +02:00

43 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from functools import partial
from django.db import migrations
def create_assoc(apps, schema_editor, assoc_name):
Association = apps.get_model('gestion', 'Association')
Group = apps.get_model('auth', 'Group')
label = assoc_name.lower()
g_buro, _ = Group.objects.get_or_create(name='{}_buro'.format(label))
g_members, _ = Group.objects.get_or_create(name='{}_members'.format(label))
assoc, _ = Association.objects.get_or_create(
name=assoc_name,
staff_group=g_buro,
members_group=g_members,
)
create_cof = partial(create_assoc, assoc_name='COF')
create_bds = partial(create_assoc, assoc_name='BDS')
class Migration(migrations.Migration):
"""
This data migration creates the Association instances and theirs related
groups for COF and BDS.
"""
dependencies = [
('gestion', '0001_initial'),
('auth', '0008_alter_user_username_max_length'),
]
operations = [
migrations.RunPython(create_cof),
migrations.RunPython(create_bds),
]