From 6c002459a310a2a661ed3da8e4ccf19f76fc9059 Mon Sep 17 00:00:00 2001 From: Edward <9326037+edwardoliveira@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:46:52 -0800 Subject: [PATCH] =?UTF-8?q?Conserta=20relatoria=20de=20mat=C3=A9rias=20(#3?= =?UTF-8?q?692)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix relatoria de matérias --- sapl/crispy_layout_mixin.py | 10 +++++++++- sapl/crud/base.py | 20 +++++++++++++++---- sapl/materia/views.py | 3 +++ sapl/templates/materia/layouts.yaml | 15 ++++++++++---- sapl/templates/norma/layouts.yaml | 2 +- sapl/templates/protocoloadm/layouts.yaml | 6 +++--- .../blocos_ata/ocorrencias_da_sessao.html | 1 - sapl/templates/sessao/layouts.yaml | 2 +- 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index b131623b9..57bc0d538 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -284,7 +284,7 @@ class CrispyLayoutFormMixin: 'text': field_display, } - def fk_urlize_for_detail(self, obj, fieldname): + def fk_urlify_for_detail(self, obj, fieldname): field = obj._meta.get_field(fieldname) value = getattr(obj, fieldname) @@ -298,6 +298,14 @@ class CrispyLayoutFormMixin: return field.verbose_name, display + def fk_urlify_for_list(self, obj, field): + value = getattr(obj, field) + return reverse( + '%s:%s_detail' % ( + value._meta.app_config.name, + value._meta.model_name), + kwargs={'pk': value.id}), + def m2m_urlize_for_detail(self, obj, fieldname): manager, fieldname = tuple(fieldname.split('__')) diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 5d6d8a3c1..94637d9d7 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -413,7 +413,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): 'composicao__periodo__data_inicio', 'composicao__periodo__data_fim')] """ r = [] - for fieldname in self.list_field_names: + for (fieldname, _) in self._parse_field_names(self.list_field_names): if not isinstance(fieldname, tuple): fieldname = fieldname, s = [] @@ -446,14 +446,26 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): r.append(s) return r + def _parse_field_names(self, field_name_list): + parsed_list = [] + for field_name in field_name_list: + field_tuple = tuple(field_name.split('|')) \ + if '|' in field_name else (field_name, None) + parsed_list.append(field_tuple) + return parsed_list + def _as_row(self, obj): r = [] - for i, name in enumerate(self.list_field_names): + for i, (name, func) in enumerate(self._parse_field_names(self.list_field_names)): + # 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 + if i > 0 and func is not None: + url = getattr(self, func)(obj, name)[0] """Caso o crud list seja para uma relação ManyToManyField""" - if url and hasattr(self, 'crud') and\ + if url and hasattr(self, 'crud') and \ hasattr(self.crud, 'is_m2m') and self.crud.is_m2m: url = url + ('?pkk=' + self.kwargs['pk'] if 'pk' in self.kwargs else '') @@ -483,7 +495,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): if m: ss = get_field_display(m, n[-1])[1] ss = ( - ('
' if '