From 101e9c26bc99a14ec9a3db8a3d2a74e9e8515433 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Mon, 17 Oct 2016 17:31:38 -0200 Subject: [PATCH] =?UTF-8?q?Cria=20front=20e=20back=20para=20incl=20de=20Pr?= =?UTF-8?q?oposi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Conclui construção do form de inclusão de Proposições contidas pelo Autor logado, via containers do Crud, com redirecionamento para Textos Articulados mediante configuração de ativação desta rotina em configurações. --- sapl/api/forms.py | 4 + sapl/api/pagination.py | 2 +- sapl/api/permissions.py | 4 +- sapl/api/serializers.py | 25 ++-- sapl/api/urls.py | 17 +-- sapl/api/views.py | 38 ++++-- sapl/base/forms.py | 14 +- sapl/base/views.py | 9 +- sapl/crud/base.py | 26 +++- sapl/materia/forms.py | 127 ++++++++++++++++-- .../migrations/0059_auto_20161016_1333.py | 19 +++ .../migrations/0060_auto_20161017_0050.py | 22 +++ .../migrations/0061_auto_20161017_1655.py | 20 +++ sapl/materia/models.py | 5 +- sapl/materia/views.py | 50 ++++++- sapl/static/js/app.js | 2 +- .../layout/checkboxselectmultiple.html | 14 -- sapl/templates/materia/layouts.yaml | 11 -- sapl/templates/materia/proposicao_form.html | 49 ++++--- .../materia/tipoproposicao_form.html | 8 +- 20 files changed, 344 insertions(+), 122 deletions(-) create mode 100644 sapl/materia/migrations/0059_auto_20161016_1333.py create mode 100644 sapl/materia/migrations/0060_auto_20161017_0050.py create mode 100644 sapl/materia/migrations/0061_auto_20161017_1655.py delete mode 100644 sapl/templates/bootstrap3/layout/checkboxselectmultiple.html diff --git a/sapl/api/forms.py b/sapl/api/forms.py index 60c4a0465..b6593d6a0 100644 --- a/sapl/api/forms.py +++ b/sapl/api/forms.py @@ -56,3 +56,7 @@ class AutorChoiceFilterSet(SaplGenericRelationSearchFilterSet): fields = ['q', 'tipo', 'nome', ] + + def filter_q(self, queryset, value): + return SaplGenericRelationSearchFilterSet.filter_q( + self, queryset, value).order_by('nome') diff --git a/sapl/api/pagination.py b/sapl/api/pagination.py index 75941c1d3..38cd219c5 100644 --- a/sapl/api/pagination.py +++ b/sapl/api/pagination.py @@ -30,5 +30,5 @@ class StandardPagination(pagination.PageNumberPagination): 'total_pages': self.page.paginator.num_pages, 'page': self.page.number, }, - 'models': data, + 'results': data, }) diff --git a/sapl/api/permissions.py b/sapl/api/permissions.py index 1149e8196..73cdba329 100644 --- a/sapl/api/permissions.py +++ b/sapl/api/permissions.py @@ -1,4 +1,4 @@ -from rest_framework.permissions import DjangoModelPermissions +from rest_framework.permissions import DjangoModelPermissions, BasePermission class DjangoModelPermissions(DjangoModelPermissions): @@ -14,4 +14,4 @@ class DjangoModelPermissions(DjangoModelPermissions): 'PUT': ['%(app_label)s.change_%(model_name)s'], 'PATCH': ['%(app_label)s.change_%(model_name)s'], 'DELETE': ['%(app_label)s.delete_%(model_name)s'], - } + } \ No newline at end of file diff --git a/sapl/api/serializers.py b/sapl/api/serializers.py index 6add3cc58..d68dafdeb 100644 --- a/sapl/api/serializers.py +++ b/sapl/api/serializers.py @@ -2,7 +2,7 @@ from django.contrib.contenttypes.fields import GenericRel from rest_framework import serializers from sapl.base.models import Autor -from sapl.utils import SaplGenericRelation +from sapl.materia.models import MateriaLegislativa class ChoiceSerializer(serializers.Serializer): @@ -25,25 +25,30 @@ class ModelChoiceSerializer(ChoiceSerializer): return obj.id +class ModelChoiceObjectRelatedField(serializers.RelatedField): + + def to_representation(self, value): + return ModelChoiceSerializer(value).data + + class AutorChoiceSerializer(ModelChoiceSerializer): - def get_value(self, obj): - return obj.id + def get_text(self, obj): + return obj.nome class Meta: model = Autor fields = ['id', 'nome'] -class AutorObjectRelatedField(serializers.RelatedField): +class AutorSerializer(serializers.ModelSerializer): + autor_related = ModelChoiceObjectRelatedField(read_only=True) - def to_representation(self, value): - return str(value) + class Meta: + model = Autor -class AutorSerializer(serializers.ModelSerializer): - autor_related = AutorObjectRelatedField(read_only=True) +class MateriaLegislativaSerializer(serializers.ModelSerializer): class Meta: - model = Autor - fields = ['id', 'tipo', 'nome', 'object_id', 'autor_related', 'user'] + model = MateriaLegislativa \ No newline at end of file diff --git a/sapl/api/urls.py b/sapl/api/urls.py index 2bcac27ff..d65446011 100644 --- a/sapl/api/urls.py +++ b/sapl/api/urls.py @@ -1,27 +1,27 @@ from django.conf import settings from django.conf.urls import url, include +from rest_framework.routers import DefaultRouter -from sapl.api.views import AutorListView, ModelChoiceView +from sapl.api.views import AutorListView, ModelChoiceView,\ + MateriaLegislativaViewSet from .apps import AppConfig app_name = AppConfig.name -# router = DefaultRouter() - -# urlpatterns += router.urls +router = DefaultRouter() +router.register(r'materia', MateriaLegislativaViewSet) +urlpatterns_router = router.urls urlpatterns_api = [ # url(r'^$', api_root), url(r'^autor', AutorListView.as_view(), name='autor_list'), - url(r'^model/(?P\d+)$', + url(r'^model/(?P\d+)/(?P\d*)$', ModelChoiceView.as_view(), name='model_list'), - - ] if settings.DEBUG: @@ -29,5 +29,6 @@ if settings.DEBUG: url(r'^docs', include('rest_framework_docs.urls')), ] urlpatterns = [ - url(r'^api/', include(urlpatterns_api)) + url(r'^api/', include(urlpatterns_api)), + url(r'^api/', include(urlpatterns_router)) ] diff --git a/sapl/api/views.py b/sapl/api/views.py index d49f3090b..04d952131 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -5,32 +5,37 @@ from django.http import Http404 from django.utils.translation import ugettext_lazy as _ from rest_framework.filters import DjangoFilterBackend from rest_framework.generics import ListAPIView +from rest_framework.mixins import ListModelMixin, RetrieveModelMixin from rest_framework.permissions import IsAuthenticated, AllowAny -from rest_framework.generics import ListAPIView, get_object_or_404 -from rest_framework.viewsets import ModelViewSet +from rest_framework.viewsets import GenericViewSet from sapl.api.forms import AutorChoiceFilterSet from sapl.api.serializers import ChoiceSerializer, AutorSerializer,\ - AutorChoiceSerializer, ModelChoiceSerializer + AutorChoiceSerializer, ModelChoiceSerializer, MateriaLegislativaSerializer from sapl.base.models import Autor, TipoAutor +from sapl.materia.models import MateriaLegislativa from sapl.utils import SaplGenericRelation, sapl_logger class ModelChoiceView(ListAPIView): # FIXME aplicar permissão correta de usuário - permission_classes = (AllowAny,) + permission_classes = (IsAuthenticated,) serializer_class = ModelChoiceSerializer - def get_queryset(self): + def get(self, request, *args, **kwargs): + self.model = ContentType.objects.get_for_id( + self.kwargs['content_type']).model_class() - try: - ct = ContentType.objects.get_for_id(self.kwargs['content_type']) + pagination = request.GET.get('pagination', '') - except: - raise Http404 + if pagination == 'False': + self.pagination_class = None + + return ListAPIView.get(self, request, *args, **kwargs) - return ct.model_class().objects.all() + def get_queryset(self): + return self.model.objects.all() class AutorListView(ListAPIView): @@ -77,7 +82,7 @@ class AutorListView(ListAPIView): TR_AUTOR_SERIALIZER = 3 # FIXME aplicar permissão correta de usuário - permission_classes = (AllowAny,) + permission_classes = (IsAuthenticated,) queryset = Autor.objects.all() model = Autor @@ -187,3 +192,14 @@ class AutorListView(ListAPIView): if tipos.count() > 1: r.sort(key=lambda x: x[1].upper()) return r + + +class MateriaLegislativaViewSet(ListModelMixin, + RetrieveModelMixin, + GenericViewSet): + + permission_classes = (IsAuthenticated,) + serializer_class = MateriaLegislativaSerializer + queryset = MateriaLegislativa.objects.all() + filter_backends = (DjangoFilterBackend,) + filter_fields = ('numero', 'ano', 'tipo', ) diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 34cabc628..73bf92e71 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -150,26 +150,17 @@ class AutorForm(ModelForm): StrictButton( _('Filtrar'), css_class='btn-default btn-filtrar-autor', type='button')), -<<<<<<< 2a44eb455a5caa1a6edb588021e46fb34b1160e7 -======= - ->>>>>>> Alt backend de perm e pag de drf e ref layout topo css_class='hidden', data_action='create', data_application='AutorSearch', data_field='autor_related') -<<<<<<< 2a44eb455a5caa1a6edb588021e46fb34b1160e7 autor_select = Row(to_column(('tipo', 3)), Div(to_column(('nome', 5)), to_column(('cargo', 4)), css_class="div_nome_cargo"), to_column((autor_related, 9)), -======= - autor_select = Row(to_column(('tipo', 4)), - to_column(('nome', 8)), - to_column((autor_related, 8)), ->>>>>>> Alt backend de perm e pag de drf e ref layout topo + to_column((Div( Field('autor_related'), css_class='radiogroup-autor-related hidden'), @@ -204,7 +195,8 @@ class AutorForm(ModelForm): self.fields['autor_related'].choices = [ (self.instance.autor_related.pk, self.instance.autor_related)] - self.fields['q'].initial = self.instance.nome + self.fields['autor_related'].initial = self.instance.object_id + self.fields['q'].initial = '' if self.instance.user: self.fields['username'].initial = self.instance.user.username diff --git a/sapl/base/views.py b/sapl/base/views.py index 5d0a3dc25..45cb5ed8a 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -49,6 +49,7 @@ class AutorCrud(CrudAux): class BaseMixin(CrudAux.BaseMixin): list_field_names = ['tipo', 'nome', 'user__username'] + ordering = ('tipo__descricao', ) class DeleteView(CrudAux.DeleteView): @@ -65,10 +66,6 @@ class AutorCrud(CrudAux): layout_key = None form_class = AutorForm - def form_valid(self, form): - # devido a implement do form o form_valid do Crud deve ser pulado - return super(CrudAux.UpdateView, self).form_valid(form) - def get_success_url(self): # FIXME try except - testar envio de emails @@ -111,10 +108,6 @@ class AutorCrud(CrudAux): form_class = AutorForm layout_key = None - def form_valid(self, form): - # devido a implement do form o form_valid do Crud deve ser pulado - return super(CrudAux.CreateView, self).form_valid(form) - def get_success_url(self): pk_autor = self.object.id try: diff --git a/sapl/crud/base.py b/sapl/crud/base.py index a7fb95e2b..a707c6ba7 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -7,11 +7,14 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import Field, Layout from django import forms from django.conf.urls import url +from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin +from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse from django.db import models from django.db.models.fields.related import ForeignKey from django.http.response import Http404 +from django.shortcuts import redirect from django.utils.decorators import classonlymethod from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ @@ -193,6 +196,24 @@ class PermissionRequiredContainerCrudMixin(PermissionRequiredMixin): if not self.model.objects.filter(**params).exists(): raise Http404() + elif self.container_field: + container = self.container_field.split('__') + + if len(container) > 1: + # TODO: implementar caso o user for o próprio o container + container_model = getattr( + self.model, container[0]).field.related_model + + params = {} + params['__'.join( + container[1:])] = request.user.pk + + if not container_model.objects.filter(**params).exists(): + messages.error( + request, + 'O Usuário (%s) não possui registro de %s.' % ( + request.user, container_model._meta.verbose_name)) + return redirect('/') return super(PermissionRequiredMixin, self).dispatch( request, *args, **kwargs) @@ -585,7 +606,7 @@ class CrudCreateView(PermissionRequiredContainerCrudMixin, return super(CrudCreateView, self).get_context_data(**kwargs) def form_valid(self, form): - self.object = form.save(commit=False) + self.object = form.instance try: self.object.owner = self.request.user self.object.modifier = self.request.user @@ -596,6 +617,7 @@ class CrudCreateView(PermissionRequiredContainerCrudMixin, container = self.container_field.split('__') if len(container) > 1: + # TODO: implementar caso o user for próprio o container container_model = getattr( self.model, container[0]).field.related_model @@ -773,7 +795,7 @@ class CrudUpdateView(PermissionRequiredContainerCrudMixin, permission_required = (RP_CHANGE, ) def form_valid(self, form): - self.object = form.save(commit=False) + self.object = form.instance try: self.object.modifier = self.request.user except: diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 73b14b299..b61706add 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1,6 +1,9 @@ +from cProfile import label from datetime import datetime import django_filters +from crispy_forms.bootstrap import InlineRadios, InlineField, Alert,\ + InlineCheckboxes from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Row,\ Div, Field @@ -10,9 +13,10 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models, transaction from django.db.models import Max -from django.forms import ModelForm +from django.forms import ModelForm, widgets from django.utils.translation import ugettext_lazy as _ +from sapl import base from sapl.base.models import Autor from sapl.comissoes.models import Comissao from sapl.crispy_layout_mixin import form_actions, to_row, to_column,\ @@ -87,7 +91,7 @@ class UnidadeTramitacaoForm(ModelForm): return cleaned_data -class ProposicaoForm(ModelForm): +class ProposicaoOldForm(ModelForm): tipo_materia = forms.ModelChoiceField( label=_('Matéria Vinculada'), @@ -135,7 +139,7 @@ class ProposicaoForm(ModelForm): return cleaned_data def save(self, commit=False): - proposicao = super(ProposicaoForm, self).save(commit) + proposicao = super(ProposicaoOldForm, self).save(commit) if 'materia' in self.cleaned_data: proposicao.materia = self.cleaned_data['materia'] proposicao.save() @@ -784,11 +788,12 @@ class TipoProposicaoForm(ModelForm): tipo_conteudo_related_radio = ChoiceWithoutValidationField( label="Seleção de Tipo", - required=True, + required=False, widget=forms.RadioSelect()) tipo_conteudo_related = forms.IntegerField( - widget=forms.HiddenInput()) + widget=forms.HiddenInput(), + required=True) class Meta: model = TipoProposicao @@ -801,9 +806,10 @@ class TipoProposicaoForm(ModelForm): def __init__(self, *args, **kwargs): - tipo_select = Row(to_column(('descricao', 5)), - to_column(('conteudo', 7)), - to_column(('tipo_conteudo_related_radio', 12))) + tipo_select = Fieldset(TipoProposicao._meta.verbose_name, + to_column(('descricao', 5)), + to_column(('conteudo', 7)), + to_column(('tipo_conteudo_related_radio', 12))) self.helper = FormHelper() self.helper.layout = SaplFormLayout(tipo_select) @@ -840,6 +846,7 @@ class TipoProposicaoForm(ModelForm): @transaction.atomic def save(self, commit=False): + tipo_proposicao = super(TipoProposicaoForm, self).save(commit) assert tipo_proposicao.conteudo @@ -849,4 +856,108 @@ class TipoProposicaoForm(ModelForm): ).objects.get(pk=self.cleaned_data['tipo_conteudo_related']) tipo_proposicao.save() + return tipo_proposicao + + +class ProposicaoCreateForm(forms.ModelForm): + + TIPO_TEXTO_CHOICE = [ + ('D', _('Arquivo Digital')), + ('T', _('Texto Articulado')) + ] + + tipo_materia = forms.ModelChoiceField( + label=TipoMateriaLegislativa._meta.verbose_name, + required=False, + queryset=TipoMateriaLegislativa.objects.all(), + empty_label='Selecione') + + numero_materia = forms.CharField( + label='Número', required=False) + + ano_materia = forms.CharField( + label='Ano', required=False) + + tipo_texto = forms.MultipleChoiceField( + label=_('Tipo do Texto da Proposição'), + required=False, + choices=TIPO_TEXTO_CHOICE, + widget=widgets.CheckboxSelectMultiple()) + + class Meta: + model = Proposicao + fields = ['tipo', + 'descricao', + 'texto_original', + + 'tipo_materia', + 'numero_materia', + 'ano_materia', + 'tipo_texto'] + + def __init__(self, *args, **kwargs): + self.texto_articulado_proposicao = base.models.AppConfig.attr( + 'texto_articulado_proposicao') + + if not self.texto_articulado_proposicao: + self.tipo_texto = None + self.TIPO_TEXTO_CHOICE = None + if 'tipo_texto' in self.Meta.fields: + self.Meta.fields.remove('tipo_texto') + + fields = [ + to_column((Fieldset( + TipoProposicao._meta.verbose_name, Field('tipo')), 3)), + Fieldset(_('Vincular a Matéria Legislativa Existente'), + to_column(('tipo_materia', 4)), + to_column(('numero_materia', 4)), + to_column(('ano_materia', 4)) + ), + + to_column( + (Alert('teste', + css_class="ementa_materia hidden alert-info", + dismiss=False), 12)), + to_column(('descricao', 12)), + ] + + if self.texto_articulado_proposicao: + fields.append( + to_column((InlineCheckboxes('tipo_texto'), 5)),) + + fields.append( + to_column(('texto_original', 7)),) + + self.helper = FormHelper() + self.helper.layout = SaplFormLayout(*fields) + + super(ProposicaoCreateForm, self).__init__(*args, **kwargs) + + def clean_texto_original(self): + texto_original = self.cleaned_data.get('texto_original', False) + if texto_original: + if texto_original.size > MAX_DOC_UPLOAD_SIZE: + raise ValidationError("Arquivo muito grande. ( > 5mb )") + return texto_original + + def clean(self): + cd = self.cleaned_data + + tm, am, nm = (cd.get('tipo_materia', ''), + cd.get('ano_materia', ''), + cd.get('numero_materia', '')) + + if tm and am and nm: + try: + materia = MateriaLegislativa.objects.get( + tipo_id=tm, + ano=am, + numero=nm + ) + except ObjectDoesNotExist: + msg = _('Matéria Vinculada não existe!') + raise ValidationError(msg) + else: + cd['materia'] = materia + return cd diff --git a/sapl/materia/migrations/0059_auto_20161016_1333.py b/sapl/materia/migrations/0059_auto_20161016_1333.py new file mode 100644 index 000000000..8ec92f96f --- /dev/null +++ b/sapl/materia/migrations/0059_auto_20161016_1333.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-10-16 15:33 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0058_auto_20161016_0329'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='tipoproposicao', + unique_together=set([('conteudo', 'object_id')]), + ), + ] diff --git a/sapl/materia/migrations/0060_auto_20161017_0050.py b/sapl/materia/migrations/0060_auto_20161017_0050.py new file mode 100644 index 000000000..ec0cc4d8a --- /dev/null +++ b/sapl/materia/migrations/0060_auto_20161017_0050.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-10-17 02:50 +from __future__ import unicode_literals + +from django.db import migrations, models +import sapl.materia.models +import sapl.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0059_auto_20161016_1333'), + ] + + operations = [ + migrations.AlterField( + model_name='proposicao', + name='texto_original', + field=models.FileField(blank=True, null=True, upload_to=sapl.materia.models.texto_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Original'), + ), + ] diff --git a/sapl/materia/migrations/0061_auto_20161017_1655.py b/sapl/materia/migrations/0061_auto_20161017_1655.py new file mode 100644 index 000000000..cbe8a0568 --- /dev/null +++ b/sapl/materia/migrations/0061_auto_20161017_1655.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-10-17 18:55 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0060_auto_20161017_0050'), + ] + + operations = [ + migrations.AlterField( + model_name='proposicao', + name='descricao', + field=models.TextField(verbose_name='Descrição'), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 82381bc2f..20e7a8bd7 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -53,6 +53,7 @@ class TipoProposicao(models.Model): class Meta: verbose_name = _('Tipo de Proposição') verbose_name_plural = _('Tipos de Proposições') + unique_together = (('conteudo', 'object_id'), ) def __str__(self): return self.descricao @@ -460,7 +461,7 @@ class Proposicao(models.Model): data_devolucao = models.DateTimeField( blank=True, null=True, verbose_name=_('Data de Devolução')) - descricao = models.TextField(max_length=100, verbose_name=_('Descrição')) + descricao = models.TextField(verbose_name=_('Descrição')) justificativa_devolucao = models.CharField( max_length=200, blank=True, @@ -489,6 +490,8 @@ class Proposicao(models.Model): texto_original = models.FileField( upload_to=texto_upload_path, + blank=True, + null=True, verbose_name=_('Texto Original'), validators=[restringe_tipos_de_arquivo_txt]) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 5fd8349f6..4814cc101 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -30,7 +30,7 @@ from sapl.crud.base import (ACTION_CREATE, ACTION_DELETE, ACTION_DETAIL, make_pagination) from sapl.materia import apps from sapl.materia.forms import AnexadaForm, LegislacaoCitadaForm,\ - TipoProposicaoForm + TipoProposicaoForm, ProposicaoCreateForm from sapl.norma.models import LegislacaoCitada from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, autor_modal, gerar_hash_arquivo, get_base_url, @@ -41,7 +41,7 @@ from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, ConfirmarProposicaoForm, DocumentoAcessorioForm, MateriaLegislativaFilterSet, - PrimeiraTramitacaoEmLoteFilterSet, ProposicaoForm, + PrimeiraTramitacaoEmLoteFilterSet, ProposicaoOldForm, ReceberProposicaoForm, TramitacaoEmLoteFilterSet, filtra_tramitacao_destino, filtra_tramitacao_destino_and_status, @@ -325,6 +325,48 @@ class ConfirmarProposicao(PermissionRequiredMixin, CreateView): class ProposicaoCrud(Crud): + model = Proposicao + help_path = '' + container_field = 'autor__user' + + class BaseMixin(Crud.BaseMixin): + list_field_names = ['data_envio', 'descricao', + 'tipo', 'data_recebimento'] + + class ListView(Crud.ListView): + ordering = ['-data_envio', 'descricao'] + + def get_rows(self, object_list): + + for obj in object_list: + if obj.data_envio is None: + obj.data_envio = 'Em elaboração...' + else: + obj.data_envio = obj.data_envio.strftime("%d/%m/%Y %H:%M") + if obj.data_recebimento is None: + obj.data_recebimento = 'Não recebida' + else: + obj.data_recebimento = obj.data_recebimento.strftime( + "%d/%m/%Y %H:%M") + + return [self._as_row(obj) for obj in object_list] + + class CreateView(Crud.CreateView): + form_class = ProposicaoCreateForm + layout_key = None + + def get_success_url(self): + + tipo_texto = self.request.POST.get('tipo_texto', '') + + if tipo_texto != 'T': + return Crud.CreateView.get_success_url(self) + else: + return reverse('sapl.materia:proposicao_ta', + kwargs={'pk': self.object.pk}) + + +class ProposicaoOldCrud(Crud): """ TODO: Entre outros comportamento gerais, mesmo que um usuário tenha Perfil de Autor o Crud de proposição não deverá permitir acesso a @@ -339,7 +381,7 @@ class ProposicaoCrud(Crud): 'tipo', 'data_recebimento'] class CreateView(Crud.CreateView): - form_class = ProposicaoForm + form_class = ProposicaoOldForm @property def layout_key(self): @@ -366,7 +408,7 @@ class ProposicaoCrud(Crud): return {'autor': autor_id} class UpdateView(Crud.UpdateView): - form_class = ProposicaoForm + form_class = ProposicaoOldForm def get_initial(self): initial = self.initial.copy() diff --git a/sapl/static/js/app.js b/sapl/static/js/app.js index 15e744fd6..408a06029 100644 --- a/sapl/static/js/app.js +++ b/sapl/static/js/app.js @@ -104,7 +104,7 @@ function autorModal() { '{{ choice.1|unlocalize }} - - {% endfor %} - {% include 'bootstrap3/layout/help_text.html' %} - diff --git a/sapl/templates/materia/layouts.yaml b/sapl/templates/materia/layouts.yaml index bfdff08d8..6653abc84 100644 --- a/sapl/templates/materia/layouts.yaml +++ b/sapl/templates/materia/layouts.yaml @@ -77,17 +77,6 @@ TipoProposicao: - descricao conteudo - tipo_conteudo_related - - -ProposicaoCreate: - {% trans 'Proposição' %}: - - tipo data_envio - - descricao - {% trans 'Materia' %}: - - tipo_materia numero_materia ano_materia - {% trans 'Complemento' %}: - - texto_original - Proposicao: {% trans 'Proposição' %}: - tipo data_envio diff --git a/sapl/templates/materia/proposicao_form.html b/sapl/templates/materia/proposicao_form.html index 610565250..02d92a1ad 100644 --- a/sapl/templates/materia/proposicao_form.html +++ b/sapl/templates/materia/proposicao_form.html @@ -5,35 +5,34 @@ {% endblock %} diff --git a/sapl/templates/materia/tipoproposicao_form.html b/sapl/templates/materia/tipoproposicao_form.html index 333e1a185..ab950a878 100644 --- a/sapl/templates/materia/tipoproposicao_form.html +++ b/sapl/templates/materia/tipoproposicao_form.html @@ -10,20 +10,18 @@ $(document).ready(function(){ $("input[name=tipo_conteudo_related]").remove(); $('#id_conteudo').change(function(event) { var pk = this[event.target.selectedIndex].value; - - var url = '{% url 'sapl.api:model_list' 0 %}' - url = url.replace('0', pk) + var url = '{% url 'sapl.api:model_list' 0 ''%}' + url = url.replace('0', pk) + '?pagination=False' $.get(url).done(function(data) { var radios = $("#div_id_tipo_conteudo_related_radio .controls").html(''); - data.models.forEach(function (val, index) { + data.forEach(function (val, index) { var html_radio = ''; radios.append(html_radio); }); initial_select=''; - }); }); $('#id_conteudo').trigger('change');