From f3034baad879fc13f8c5c77a4ecaca19056044c8 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 10 Feb 2017 10:37:24 -0200 Subject: [PATCH] =?UTF-8?q?Cria=20grupo=20e=20permiss=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/parlamentares/apps.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sapl/parlamentares/apps.py b/sapl/parlamentares/apps.py index 41f6d0b38..dd523cd49 100644 --- a/sapl/parlamentares/apps.py +++ b/sapl/parlamentares/apps.py @@ -1,8 +1,38 @@ from django import apps +from django.db.models.signals import post_migrate from django.utils.translation import ugettext_lazy as _ +from django.core.exceptions import ObjectDoesNotExist + + +def criar_grupo(permission): + from django.contrib.auth.models import Group + + g = Group.objects.get_or_create(name='Votante') + g[0].permissions.add(permission) + + +def criar_permissao(sender, **kwargs): + from django.contrib.auth.models import Permission + from django.contrib.contenttypes.models import ContentType + + try: + content_type = ContentType.objects.get( + app_label='parlamentares', + model='Votante') + except ObjectDoesNotExist: + content_type = ContentType.objects.create( + app_label='parlamentares', + model='Votante') + + p = Permission.objects.get_or_create( + name='Can Vote', codename='can_vote', content_type=content_type) + criar_grupo(p[0]) class AppConfig(apps.AppConfig): name = 'sapl.parlamentares' label = 'parlamentares' verbose_name = _('Parlamentares') + + def ready(self): + post_migrate.connect(criar_permissao, sender=self)