From 35d24f9b5af9942fab8d925a39f37f41c455a32b Mon Sep 17 00:00:00 2001 From: Leandro Roberto Silva Date: Thu, 21 Mar 2019 13:26:50 -0300 Subject: [PATCH] Fix #2559 reordenacao materia em sessao (#2646) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add sequencial_regimental no model tipo de matéria legislativa * applica pep * converte TipoMateriaCrud para classe * inclui hooks no crud list * altera ordering de TipoMateriaLegislativa * define layout diferente para detail e list * define estratégia para iniciar sequencia em tipos já existentes * add template custom para listagem de tipo de matérias * altera call hook * impl a reordenação no list dos tipos de matéria * add file migrate * autopep in sessao/views.py * ref views functions acionadas pelo botão 'Ajustar Ordenação' --- sapl/api/views.py | 20 ++- sapl/crud/base.py | 12 +- ...materialegislativa_sequencia_regimental.py | 21 +++ .../migrations/0043_auto_20190320_1749.py | 19 +++ sapl/materia/models.py | 41 +++++- sapl/materia/views.py | 93 +++++++++--- sapl/sessao/views.py | 139 ++++++++++-------- sapl/templates/materia/layouts.yaml | 6 +- .../materia/tipomaterialegislativa_list.html | 55 +++++++ 9 files changed, 322 insertions(+), 84 deletions(-) create mode 100644 sapl/materia/migrations/0042_tipomaterialegislativa_sequencia_regimental.py create mode 100644 sapl/materia/migrations/0043_auto_20190320_1749.py create mode 100644 sapl/templates/materia/tipomaterialegislativa_list.html diff --git a/sapl/api/views.py b/sapl/api/views.py index 335797ecf..d291d56ec 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -22,7 +22,7 @@ from sapl.api.forms import SaplFilterSetMixin from sapl.api.permissions import SaplModelPermissions from sapl.api.serializers import ChoiceSerializer from sapl.base.models import Autor, AppConfig, DOC_ADM_OSTENSIVO -from sapl.materia.models import Proposicao +from sapl.materia.models import Proposicao, TipoMateriaLegislativa from sapl.parlamentares.models import Parlamentar from sapl.utils import models_with_gr_for_model, choice_anos_com_sessaoplenaria @@ -348,6 +348,23 @@ class _ProposicaoViewSet(SaplSetViews['materia']['proposicao']): return qs +class _TipoMateriaLegislativaViewSet(SaplSetViews['materia']['tipomaterialegislativa']): + + @action(detail=True, methods=['POST']) + def change_position(self, request, *args, **kwargs): + result = { + 'status': 200, + 'message': 'OK' + } + d = request.data + if 'pos_ini' in d and 'pos_fim' in d: + if d['pos_ini'] != d['pos_fim']: + pk = kwargs['pk'] + TipoMateriaLegislativa.objects.reposicione(pk, d['pos_fim']) + + return Response(result) + + class _DocumentoAdministrativoViewSet(SaplSetViews['protocoloadm']['documentoadministrativo']): class DocumentoAdministrativoPermission(SaplModelPermissions): @@ -426,6 +443,7 @@ class _SessaoPlenariaViewSet( SaplSetViews['base']['autor'] = _AutorViewSet.build_class_with_actions() SaplSetViews['materia']['proposicao'] = _ProposicaoViewSet +SaplSetViews['materia']['tipomaterialegislativa'] = _TipoMateriaLegislativaViewSet SaplSetViews['parlamentares']['parlamentar'] = _ParlamentarViewSet diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 5fa4f70e5..0dc11ea5c 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -2,7 +2,6 @@ import logging from braces.views import FormMessagesMixin from crispy_forms.bootstrap import FieldWithButtons, StrictButton -from sapl.crispy_layout_mixin import SaplFormHelper from crispy_forms.layout import Field, Layout from django import forms from django.conf.urls import url @@ -25,6 +24,7 @@ from django.views.generic.base import ContextMixin from django.views.generic.list import MultipleObjectMixin from sapl.crispy_layout_mixin import CrispyLayoutFormMixin, get_field_display +from sapl.crispy_layout_mixin import SaplFormHelper from sapl.rules.map_rules import (RP_ADD, RP_CHANGE, RP_DELETE, RP_DETAIL, RP_LIST) from sapl.settings import BASE_DIR @@ -449,18 +449,28 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): if not n: s += '
' continue + m = obj n = n.split('__') for f in n[:-1]: m = getattr(m, f) if not m: break + + ss = '' if m: ss = get_field_display(m, n[-1])[1] ss = ( ('
' if '