1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-04-12 17:51
from __future__ import unicode_literals
from django.db import migrations
def add_import_group(apps, schema_editor):
Group = apps.get_model('auth', 'Group')
ContentType = apps.get_model('contenttypes', 'ContentType')
ProfileType = apps.get_model('ishtar_common', 'ProfileType')
Permission = apps.get_model('auth', 'Permission')
gp, created = Group.objects.get_or_create(
name="Import : ajout/modification/suppression")
content_type, created = ContentType.objects.get_or_create(
model='import', app_label='ishtar_common')
for perm, name in (('add_import', "Can add Import"),
('change_import', "Can change Import"),
('delete_import', "Can delete Import")):
p, created = Permission.objects.get_or_create(
codename=perm, name=name, content_type=content_type)
gp.permissions.add(p)
pt, created = ProfileType.objects.get_or_create(
txt_idx="administrator",
defaults={
'label':"Administrateur", 'comment': "", 'available':True
}
)
# add all existing groups to administrator
current_groups = list([g.pk for g in pt.groups.all()])
for gp in Group.objects.all():
if gp.pk not in current_groups:
pt.groups.add(gp)
class Migration(migrations.Migration):
dependencies = [
('ishtar_common', '0043_remove_persontype_groups'),
]
operations = [
migrations.RunPython(add_import_group),
]
|