Browse Source

Fix #1353

pull/1374/merge
LeandroRoberto 7 years ago
parent
commit
c114b1ac7a
  1. 55
      sapl/materia/forms.py
  2. 14
      sapl/materia/urls.py
  3. 66
      sapl/materia/views.py
  4. 4
      sapl/templates/materia/autoria_list.html
  5. 51
      sapl/templates/materia/autoria_multicreate_form.html
  6. 7
      sapl/templates/materia/layouts.yaml

55
sapl/materia/forms.py

@ -14,20 +14,20 @@ from django.core.urlresolvers import reverse
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.forms import ModelForm, ModelChoiceField, widgets from django.forms import ModelForm, ModelChoiceField, widgets
from django.forms.fields import BooleanField
from django.forms.forms import Form from django.forms.forms import Form
from django.forms.widgets import Select, HiddenInput from django.forms.models import ModelMultipleChoiceField
from django.forms.widgets import Select, CheckboxSelectMultiple, HiddenInput
from django.utils import six from django.utils import six
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.html import format_html from django.utils.html import format_html
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django_filters.filterset import STRICTNESS from django_filters.filterset import STRICTNESS
from jedi.evaluate import instance
import django_filters import django_filters
from sapl.base.models import Autor, TipoAutor from sapl.base.models import Autor, TipoAutor
from sapl.comissoes.models import Comissao from sapl.comissoes.models import Comissao
from sapl.compilacao.forms import error_messages
from sapl.compilacao.models import (STATUS_TA_IMMUTABLE_PUBLIC, from sapl.compilacao.models import (STATUS_TA_IMMUTABLE_PUBLIC,
STATUS_TA_PRIVATE) STATUS_TA_PRIVATE)
from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column,
@ -735,6 +735,55 @@ class AutoriaForm(ModelForm):
return cd return cd
class AutoriaMultiCreateForm(Form):
tipo_autor = ModelChoiceField(label=_('Tipo Autor'),
required=False,
queryset=TipoAutor.objects.all(),
empty_label=_('Selecione'),)
data_relativa = forms.DateField(
widget=forms.HiddenInput(), required=False)
autor = ModelMultipleChoiceField(
queryset=Autor.objects.all(),
label=_('Possiveis Autores'),
required=False,
widget=CheckboxSelectMultiple)
autores = ModelMultipleChoiceField(
queryset=Autor.objects.all(),
required=False,
widget=HiddenInput)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
row1 = to_row([('tipo_autor', 12), ])
row2 = to_row([('autor', 12), ])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
_('Autorias'), row1, row2, 'data_relativa', 'autores',
form_actions(save_label='Incluir Autores Selecionados')))
self.fields['autor'].choices = []
def clean(self):
cd = super().clean()
if 'autores' in self.errors:
del self.errors['autores']
if 'autor' not in cd or not cd['autor'].exists():
raise ValidationError(
_('Ao menos um autor deve ser selecionado para inclusão'))
return cd
class AcessorioEmLoteFilterSet(django_filters.FilterSet): class AcessorioEmLoteFilterSet(django_filters.FilterSet):
filter_overrides = {models.DateField: { filter_overrides = {models.DateField: {

14
sapl/materia/urls.py

@ -2,8 +2,7 @@ from django.conf.urls import include, url
from sapl.materia.views import (AcompanhamentoConfirmarView, from sapl.materia.views import (AcompanhamentoConfirmarView,
AcompanhamentoExcluirView, AcompanhamentoExcluirView,
AcompanhamentoMateriaView, AcompanhamentoMateriaView, AnexadaCrud,
AdicionarVariasAutorias, AnexadaCrud,
AssuntoMateriaCrud, AutoriaCrud, AssuntoMateriaCrud, AutoriaCrud,
ConfirmarProposicao, CriarProtocoloMateriaView, ConfirmarProposicao, CriarProtocoloMateriaView,
DespachoInicialCrud, DocumentoAcessorioCrud, DespachoInicialCrud, DocumentoAcessorioCrud,
@ -21,11 +20,12 @@ from sapl.materia.views import (AcompanhamentoConfirmarView,
TipoFimRelatoriaCrud, TipoMateriaCrud, TipoFimRelatoriaCrud, TipoMateriaCrud,
TipoProposicaoCrud, TramitacaoCrud, TipoProposicaoCrud, TramitacaoCrud,
TramitacaoEmLoteView, UnidadeTramitacaoCrud, TramitacaoEmLoteView, UnidadeTramitacaoCrud,
proposicao_texto, recuperar_materia) proposicao_texto, recuperar_materia,
AutoriaMultiCreateView)
from . import receivers
from .apps import AppConfig from .apps import AppConfig
from . import receivers
app_name = AppConfig.name app_name = AppConfig.name
@ -60,9 +60,9 @@ urlpatterns_materia = [
AcompanhamentoExcluirView.as_view(), AcompanhamentoExcluirView.as_view(),
name='acompanhar_excluir'), name='acompanhar_excluir'),
url(r'^materia/(?P<pk>\d+)/adicionar-varias-autorias/', url(r'^materia/(?P<pk>\d+)/autoria/multicreate',
AdicionarVariasAutorias.as_view(), AutoriaMultiCreateView.as_view(),
name='adicionar_varias_autorias'), name='autoria_multicreate'),
url(r'^materia/acessorio-em-lote', DocumentoAcessorioEmLoteView.as_view(), url(r'^materia/acessorio-em-lote', DocumentoAcessorioEmLoteView.as_view(),
name='acessorio_em_lote'), name='acessorio_em_lote'),

66
sapl/materia/views.py

@ -16,7 +16,7 @@ from django.db.models import Q
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from django.http.response import Http404, HttpResponseRedirect from django.http.response import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.utils import formats from django.utils import formats, deprecation
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, ListView, TemplateView, UpdateView from django.views.generic import CreateView, ListView, TemplateView, UpdateView
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
@ -37,7 +37,7 @@ from sapl.crud.base import (ACTION_CREATE, ACTION_DELETE, ACTION_DETAIL,
from sapl.materia.forms import (AnexadaForm, ConfirmarProposicaoForm, from sapl.materia.forms import (AnexadaForm, ConfirmarProposicaoForm,
LegislacaoCitadaForm, AutoriaForm, ProposicaoForm, LegislacaoCitadaForm, AutoriaForm, ProposicaoForm,
TipoProposicaoForm, TramitacaoForm, TipoProposicaoForm, TramitacaoForm,
TramitacaoUpdateForm) TramitacaoUpdateForm, AutoriaMultiCreateForm)
from sapl.materia.models import Autor from sapl.materia.models import Autor
from sapl.norma.models import LegislacaoCitada from sapl.norma.models import LegislacaoCitada
from sapl.parlamentares.models import Parlamentar from sapl.parlamentares.models import Parlamentar
@ -1086,13 +1086,16 @@ class AutoriaCrud(MasterDetailCrud):
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL] public = [RP_LIST, RP_DETAIL]
list_field_names = ['autor', 'autor__tipo__descricao', 'primeiro_autor']
class CreateView(MasterDetailCrud.CreateView): class LocalBaseMixin():
form_class = AutoriaForm form_class = AutoriaForm
@property @property
def layout_key(self): def layout_key(self):
return 'AutoriaCreate' return None
class CreateView(LocalBaseMixin, MasterDetailCrud.CreateView):
def get_initial(self): def get_initial(self):
initial = super().get_initial() initial = super().get_initial()
@ -1101,12 +1104,7 @@ class AutoriaCrud(MasterDetailCrud):
initial['autor'] = [] initial['autor'] = []
return initial return initial
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(LocalBaseMixin, MasterDetailCrud.UpdateView):
form_class = AutoriaForm
@property
def layout_key(self):
return 'AutoriaUpdate'
def get_initial(self): def get_initial(self):
initial = super().get_initial() initial = super().get_initial()
@ -1117,6 +1115,46 @@ class AutoriaCrud(MasterDetailCrud):
return initial return initial
class AutoriaMultiCreateView(FormView):
form_class = AutoriaMultiCreateForm
template_name = 'materia/autoria_multicreate_form.html'
@classmethod
def get_url_regex(cls):
return r'^(?P<pk>\d+)/%s/multicreate' % cls.model._meta.model_name
@property
def layout_key(self):
return None
def get_initial(self):
initial = super().get_initial()
self.materia = MateriaLegislativa.objects.get(id=self.kwargs['pk'])
initial['data_relativa'] = self.materia.data_apresentacao
initial['autores'] = self.materia.autores.all()
return initial
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = '%s <small>(%s)</small>' % (
_('Adicionar Várias Autorias'), self.materia)
return context
def get_success_url(self):
messages.add_message(
self.request, messages.SUCCESS,
_('Autorias adicionadas com sucesso.'))
return reverse(
'sapl.materia:autoria_list', kwargs={'pk': self.materia.pk})
def form_valid(self, form):
autores_selecionados = form.cleaned_data['autor']
for autor in autores_selecionados:
Autoria.objects.create(materia=self.materia, autor=autor)
return FormView.form_valid(self, form)
class DespachoInicialCrud(MasterDetailCrud): class DespachoInicialCrud(MasterDetailCrud):
model = DespachoInicial model = DespachoInicial
parent_field = 'materia' parent_field = 'materia'
@ -1694,10 +1732,10 @@ class TramitacaoEmLoteView(PrimeiraTramitacaoEmLoteView):
context['primeira_tramitacao'] = False context['primeira_tramitacao'] = False
if ('tramitacao__status' in qr and if ('tramitacao__status' in qr and
'tramitacao__unidade_tramitacao_destino' in qr and 'tramitacao__unidade_tramitacao_destino' in qr and
qr['tramitacao__status'] and qr['tramitacao__status'] and
qr['tramitacao__unidade_tramitacao_destino'] qr['tramitacao__unidade_tramitacao_destino']
): ):
lista = filtra_tramitacao_destino_and_status( lista = filtra_tramitacao_destino_and_status(
qr['tramitacao__status'], qr['tramitacao__status'],
qr['tramitacao__unidade_tramitacao_destino']) qr['tramitacao__unidade_tramitacao_destino'])

4
sapl/templates/materia/autoria_list.html

@ -6,8 +6,8 @@
{% block more_buttons %} {% block more_buttons %}
{% if perms|get_add_perm:view %} {% if perms|get_add_perm:view %}
<a href="{% url 'sapl.materia:adicionar_varias_autorias' root_pk %}" class="btn btn-default"> <a href="{% url 'sapl.materia:autoria_multicreate' root_pk %}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar Várias Autorias {% endblocktrans %} {% trans "Adicionar Várias Autorias" %}
</a> </a>
{% endif %} {% endif %}

51
sapl/templates/materia/autoria_multicreate_form.html

@ -0,0 +1,51 @@
{% extends "crud/form.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load common_tags %}
{% block extra_js %}
<script language="Javascript">
$(document).ready(function() {
var autores_pre_cadastrados = $.parseJSON($("#id_autores").val());
$("#id_tipo_autor").change(function() {
var tipo_selecionado = $("#id_tipo_autor").val();
$("#id_autor option").remove()
if (tipo_selecionado !== '') {
var json_data = {
tipo : tipo_selecionado,
data_relativa : $("#id_data_relativa").val()
}
$.getJSON("/api/autor/possiveis", json_data, function(data){
$("#div_id_autor .controls").html('');
if (data) {
var results = data;
$.each(results, function(idx, obj) {
if (autores_pre_cadastrados.indexOf(obj.value) !== -1)
return ;
$('<input/>')
.attr('type', 'checkbox')
.attr('name','autor')
.attr('id', 'id_autor_'+idx)
.attr('value', obj.value)
.appendTo(
$('<label/>').text(obj.text)
.appendTo(
$('<div class="checkbox">')
.appendTo($("#div_id_autor .controls")
)
)
)
});
$('[type=checkbox]').checkbox();
}
});
}
});
$("#id_tipo_autor").trigger('change');
});
</script>
{% endblock %}

7
sapl/templates/materia/layouts.yaml

@ -61,13 +61,6 @@ Autoria:
{% trans 'Autoria' %}: {% trans 'Autoria' %}:
- autor primeiro_autor - autor primeiro_autor
AutoriaCreate:
{% trans 'Autoria' %}:
- tipo_autor autor primeiro_autor
AutoriaUpdate:
{% trans 'Autoria' %}:
- tipo_autor autor primeiro_autor
DocumentoAcessorio: DocumentoAcessorio:
{% trans 'Documento Acessório' %}: {% trans 'Documento Acessório' %}:

Loading…
Cancel
Save