create_groups.py
1.61 KB
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
# -*- coding: utf-8 -*-
from django.contrib.auth.models import Permission, Group
from django.core.management.base import BaseCommand
class Command(BaseCommand):
args = 'none'
help = 'Creates default groups'
def handle(self, **options):
create_groups()
def get_permission(codename):
return Permission.objects.get(codename=codename)
def create_groups():
Group.objects.all().delete()
lexicographers = Group.objects.create(name=u'Leksykograf')
patternmakers = Group.objects.create(name=u'Wzorzysta')
admins = Group.objects.create(name=u'Administrator')
lexicographers.permissions.add(get_permission('view_lexeme'))
lexicographers.permissions.add(get_permission('change_lexeme'))
lexicographers.permissions.add(get_permission('export_lexemes'))
lexicographers.permissions.add(get_permission('view_pattern'))
lexicographers.permissions.add(get_permission('manage_vocabulary'))
lexicographers.permissions.add(get_permission('export_lexemes'))
# może dokonywać zmian w Banku błędów
# może dokonywać zmian w zakładce Etykiety
patternmakers.permissions.add(get_permission('view_pattern'))
patternmakers.permissions.add(get_permission('change_pattern'))
# zarządzanie rolami użytkowników:
admins.permissions.add(get_permission('add_user'))
admins.permissions.add(get_permission('change_group'))
admins.permissions.add(get_permission('create_admin'))
admins.permissions.add(get_permission('manage_vocabulary'))
admins.permissions.add(get_permission('manage_all_vocabularies'))
admins.permissions.add(get_permission('view_all_lexemes'))