From bad6638e4cdcdbabbcb0d543a0f51f7017e8b226 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Sat, 2 Dec 2017 15:56:09 -0200 Subject: [PATCH] =?UTF-8?q?adiciona=20try=20except=20para=20incompatibilid?= =?UTF-8?q?ade=20de=20vers=C3=B5es=20do=20django?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/rules/apps.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sapl/rules/apps.py b/sapl/rules/apps.py index f599db55d..3b6e9d271 100644 --- a/sapl/rules/apps.py +++ b/sapl/rules/apps.py @@ -1,15 +1,15 @@ from builtins import LookupError -import django -import reversion from django.apps import apps from django.contrib.auth import get_user_model from django.contrib.auth.management import _get_all_permissions from django.core import exceptions from django.db import models, router from django.db.utils import DEFAULT_DB_ALIAS -from django.utils.translation import ugettext_lazy as _ from django.utils.translation import string_concat +from django.utils.translation import ugettext_lazy as _ +import django +import reversion from sapl.rules import (SAPL_GROUP_ADMINISTRATIVO, SAPL_GROUP_COMISSOES, SAPL_GROUP_GERAL, SAPL_GROUP_MATERIA, SAPL_GROUP_NORMA, @@ -78,7 +78,19 @@ def create_proxy_permissions( ctype = ContentType.objects.db_manager(using).get_for_model(klass) ctypes.add(ctype) - for perm in _get_all_permissions(klass._meta, ctype): + + # FIXME: Retirar try except quando sapl passar a usar django 1.11 + try: + # Função não existe mais em Django 1.11 + # como sapl ainda não foi para Django 1.11 + # esta excessão foi adicionada para caso o + # Sapl esteja rodando em um projeto 1.11 não ocorra erros + _all_perms_of_klass = _get_all_permissions(klass._meta, ctype) + except: + # Nova função usada em projetos com Django 1.11 e o sapl é uma app + _all_perms_of_klass = _get_all_permissions(klass._meta) + + for perm in _all_perms_of_klass: searched_perms.append((ctype, perm)) # Find all the Permissions that have a content_type for a model we're