create_groups.py 2.55 KB
# -*- 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()
    observers = Group.objects.create(name=u'Obserwator')
    lexicographers = Group.objects.create(name=u'Leksykograf')
    superlexicographers = Group.objects.create(name=u'Superleksykograf')
    patternmakers = Group.objects.create(name=u'Wzorzysta')
    managers = Group.objects.create(name=u'Wydawca')
    admins = Group.objects.create(name=u'Administrator')

    observers.permissions.add(get_permission('view_lexeme'))
    #observers.permissions.add(get_permission('add_comment'))
    observers.permissions.add(get_permission('view_pattern'))
    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'))
    superlexicographers.permissions.add(get_permission('view_lexeme'))
    superlexicographers.permissions.add(get_permission('change_lexeme'))
    superlexicographers.permissions.add(get_permission('export_lexemes'))
    superlexicographers.permissions.add(get_permission('lexeme_priority'))
    superlexicographers.permissions.add(get_permission('view_pattern'))
    # 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'))
    managers.permissions.add(get_permission('manage_vocabulary'))
    managers.permissions.add(get_permission('view_lexeme'))
    managers.permissions.add(get_permission('view_all_lexemes'))
    managers.permissions.add(get_permission('view_pattern'))
    managers.permissions.add(get_permission('add_user'))
    managers.permissions.add(get_permission('export_lexemes'))
    # zarządzanie rolami użytkowników:
    managers.permissions.add(get_permission('change_group'))
    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'))