diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 0c3f54ca9..65ecdcfec 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -183,17 +183,21 @@ def resolve_urls_inplace(menu, pk, rm, context): as funcionalidades diretas do MasterDetailCrud, como: - visualização de detalhes, adição, edição, remoção. """ - if 'view' in context: - view = context['view'] - if hasattr(view, '__class__') and\ - hasattr(view.__class__, 'crud'): - urls = view.__class__.crud.get_urls() - for u in urls: - if (u.name == url_name or - 'urls_extras' in menu and - u.name in menu['urls_extras']): - menu['active'] = 'active' - break + try: + if 'view' in context: + view = context['view'] + if hasattr(view, 'crud'): + urls = view.crud.get_urls() + for u in urls: + if (u.name == url_name or + 'urls_extras' in menu and + u.name in menu['urls_extras']): + menu['active'] = 'active' + break + except: + url_active = menu.get('url', '') + logger.warning( + f'Não foi possível definir se url {url_active} é a url ativa.') elif 'check_permission' in menu and not context[ 'request'].user.has_perm(menu['check_permission']): menu['active'] = '' diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 94637d9d7..5dbc713dc 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -263,18 +263,18 @@ class CrudBaseMixin(CrispyLayoutFormMixin): self.model_name_set = getattr( obj.model, obj.model_set).field.model._meta.model_name - if hasattr(self, 'permission_required') and self.permission_required: - if hasattr(obj, 'public'): - self.permission_required = list( - set(self.permission_required) - set(obj.public)) - else: - obj.public = [] + if not hasattr(obj, 'public'): + obj.public = [] - self.permission_required = tuple(( - self.permission(pr) for pr in self.permission_required)) + if hasattr(self, 'permission_required') and self.permission_required: - else: - obj.public = [] + self.permission_required = tuple( + ( + self.permission(pr) for pr in ( + set(self.permission_required) - set(obj.public) + ) + ) + ) @classmethod def url_name(cls, suffix): @@ -460,7 +460,8 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): # URL padrão para primeira coluna da listagem url = self.resolve_url( ACTION_DETAIL, args=(obj.id,)) if i == 0 else None - # gera URL para matéria a partir de fk_urlify_for_list em layouts.yaml + # gera URL para matéria a partir de fk_urlify_for_list em + # layouts.yaml if i > 0 and func is not None: url = getattr(self, func)(obj, name)[0] @@ -495,7 +496,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): if m: ss = get_field_display(m, n[-1])[1] ss = ( - ('
' if '