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
|
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-06-12 19:03
from __future__ import unicode_literals
from django.contrib.auth.management import create_permissions
from django.db import migrations
from django.apps import apps as django_apps
def migrate_groups(apps, schema_editor):
# create_permissions(django_apps.get_app_config('ishtar_common'),
# verbosity=0)
Group = apps.get_model('auth', 'Group')
Permission = apps.get_model('auth', 'Permission')
ProfileType = apps.get_model('ishtar_common', 'ProfileType')
for gp in Group.objects.filter(name__startswith='Document').all():
gp.delete()
groups = [
(u"Documents : lecture", ['view_document']),
(u"Documents : ajout", ['add_document']),
(u"Documents : modification/suppression",
['change_document', 'delete_document']),
(u"Documents rattachés : lecture", ['view_own_document']),
(u"Documents rattachés : ajout", ['add_own_document']),
(u"Documents rattachés : modification/suppression",
['change_own_document', 'delete_own_document']),
]
admin = ProfileType.objects.get(txt_idx='administrator')
for name, codenames in groups:
gp = Group.objects.create(name=name)
for codename in codenames:
p = Permission.objects.get(codename=codename)
gp.permissions.add(p)
admin.groups.add(gp)
class Migration(migrations.Migration):
dependencies = [
('ishtar_common', '0057_document_cache_related_label'),
]
operations = [
migrations.RunPython(migrate_groups)
]
|