2017-02-10 20:10:45 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-02-23 12:58:10 +01:00
|
|
|
from django.contrib.auth.models import Group
|
2017-02-10 20:10:45 +01:00
|
|
|
from django.db import migrations, models
|
|
|
|
|
|
|
|
|
|
|
|
def create_profile(apps, schema_editor):
|
|
|
|
CofProfile = apps.get_model("cof", "CofProfile")
|
|
|
|
Profile = apps.get_model("gestion", "Profile")
|
|
|
|
for p in CofProfile.objects.all():
|
|
|
|
profile = Profile.objects.create(
|
|
|
|
id=p.id,
|
|
|
|
user=p.user,
|
|
|
|
login_clipper=p.login_clipper,
|
|
|
|
phone=p.phone,
|
|
|
|
occupation=p.occupation,
|
|
|
|
departement=p.departement,
|
|
|
|
comments=p.comments
|
|
|
|
)
|
|
|
|
p.profile = profile
|
|
|
|
p.save()
|
|
|
|
|
|
|
|
|
2017-02-11 23:05:51 +01:00
|
|
|
def preserve_perms(apps, schema_editor):
|
2017-02-22 19:28:34 +01:00
|
|
|
# from django.contrib.auth.management import create_permissions
|
2017-02-11 23:05:51 +01:00
|
|
|
|
2017-02-22 19:28:34 +01:00
|
|
|
# apps.models_module = True
|
|
|
|
# create_permissions(apps, verbosity=0)
|
|
|
|
# apps.models_module = None
|
2017-02-11 23:05:51 +01:00
|
|
|
|
|
|
|
CofProfile = apps.get_model("cof", "CofProfile")
|
2017-02-22 19:28:34 +01:00
|
|
|
# memberp = Permission.objects.get(codename='member')
|
|
|
|
# burop = Permission.objects.get(codename='buro')
|
2017-02-11 23:05:51 +01:00
|
|
|
|
|
|
|
# creates the groups for COF members and
|
|
|
|
member = Group.objects.create(name='cof_members')
|
|
|
|
buro = Group.objects.create(name='cof_buro')
|
|
|
|
|
|
|
|
# associate permissions to the respective groups.
|
2017-02-22 19:28:34 +01:00
|
|
|
# buro.permissions = [burop, memberp]
|
|
|
|
# member.permissions = [memberp]
|
2017-02-11 23:05:51 +01:00
|
|
|
|
|
|
|
for cofp in CofProfile.objects.filter(is_cof=True):
|
|
|
|
cofp.profile.user.groups.add(member)
|
|
|
|
for cofp in CofProfile.objects.filter(is_buro=True):
|
|
|
|
cofp.profile.user.groups.add(buro)
|
|
|
|
|
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
def remove_profile(apps, schema_editor):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2017-02-11 23:05:51 +01:00
|
|
|
fuckup_perms = remove_profile
|
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('gestion', '0001_initial'),
|
|
|
|
('cof', '0008_py3'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RenameField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
old_name='mailing_cof',
|
|
|
|
new_name='mailing',
|
|
|
|
),
|
|
|
|
migrations.AddField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='profile',
|
|
|
|
field=models.OneToOneField(
|
2017-02-22 19:28:34 +01:00
|
|
|
on_delete=models.CASCADE,
|
2017-02-10 20:10:45 +01:00
|
|
|
to='gestion.Profile',
|
|
|
|
null=True,
|
|
|
|
related_name='cof'
|
|
|
|
),
|
|
|
|
preserve_default=False,
|
|
|
|
),
|
2017-02-11 23:05:51 +01:00
|
|
|
migrations.AlterModelOptions(
|
|
|
|
name='cofprofile',
|
|
|
|
options={
|
|
|
|
'permissions': (('member', 'Is a COF member'),
|
2017-02-18 13:00:21 +01:00
|
|
|
('buro', 'Is part of COF staff')),
|
2017-02-11 23:05:51 +01:00
|
|
|
'verbose_name': 'Profil COF',
|
|
|
|
'verbose_name_plural': 'Profils COF'},
|
|
|
|
),
|
2017-02-10 20:10:45 +01:00
|
|
|
migrations.RunPython(create_profile, remove_profile),
|
2017-02-11 23:05:51 +01:00
|
|
|
migrations.AlterField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='profile',
|
|
|
|
field=models.OneToOneField(
|
2017-02-22 19:28:34 +01:00
|
|
|
on_delete=models.CASCADE,
|
2017-02-11 23:05:51 +01:00
|
|
|
to='gestion.Profile',
|
|
|
|
related_name='cof'
|
|
|
|
),
|
|
|
|
),
|
2017-02-10 20:10:45 +01:00
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='comments',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='departement',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='login_clipper',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='occupation',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='phone',
|
|
|
|
),
|
2017-02-11 23:05:51 +01:00
|
|
|
migrations.RunPython(preserve_perms, fuckup_perms),
|
|
|
|
migrations.RemoveField(
|
2017-02-10 20:10:45 +01:00
|
|
|
model_name='cofprofile',
|
2017-02-11 23:05:51 +01:00
|
|
|
name='is_cof',
|
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='is_buro',
|
2017-02-10 20:10:45 +01:00
|
|
|
),
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='cofprofile',
|
|
|
|
name='user',
|
|
|
|
),
|
|
|
|
]
|