Browse Source

Merge pull request #425 from interlegis/351-crud-documento-acessorio

Fix #351 crud documento acessorio
pull/445/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
55b8215934
  1. 21
      materia/forms.py
  2. 153
      materia/views.py
  3. 2
      protocoloadm/views.py

21
materia/forms.py

@ -119,6 +119,7 @@ class DocumentoAcessorioForm(ModelForm):
class Meta: class Meta:
model = DocumentoAcessorio model = DocumentoAcessorio
fields = ['tipo', 'nome', 'data', 'autor', 'ementa', 'arquivo'] fields = ['tipo', 'nome', 'data', 'autor', 'ementa', 'arquivo']
widgets = {'autor': forms.HiddenInput()}
widgets = {'autor': forms.HiddenInput()} widgets = {'autor': forms.HiddenInput()}
@ -155,6 +156,26 @@ class RelatoriaForm(ModelForm):
return cleaned_data return cleaned_data
class Meta:
model = Relatoria
fields = ['data_designacao_relator', 'comissao', 'parlamentar',
'data_destituicao_relator', 'tipo_fim_relatoria']
widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})}
def clean(self):
cleaned_data = self.cleaned_data
try:
comissao = Comissao.objects.get(id=self.initial['comissao'])
except ObjectDoesNotExist:
msg = _('A localização atual deve ser uma comissão.')
raise ValidationError(msg)
else:
cleaned_data['comissao'] = comissao
return cleaned_data
class TramitacaoForm(ModelForm): class TramitacaoForm(ModelForm):

153
materia/views.py

@ -57,7 +57,34 @@ ProposicaoCrud = Crud.build(Proposicao, '')
StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao')
UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao') UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao')
RelatoriaCrud = MasterDetailCrud.build(Relatoria, 'materia', '')
class RelatoriaCrud(MasterDetailCrud):
model = Relatoria
parent_field = 'materia'
help_path = ''
class CreateView(MasterDetailCrud.CreateView):
form_class = RelatoriaForm
def get_initial(self):
materia = MateriaLegislativa.objects.get(id=self.kwargs['pk'])
loc_atual = Tramitacao.objects.filter(
materia=materia).last()
if loc_atual is None:
localizacao = 0
else:
comissao = loc_atual.unidade_tramitacao_destino.comissao
if comissao:
localizacao = comissao.pk
else:
localizacao = 0
return {'comissao': localizacao}
class UpdateView(MasterDetailCrud.UpdateView):
form_class = RelatoriaForm
class RelatoriaCrud(MasterDetailCrud): class RelatoriaCrud(MasterDetailCrud):
@ -128,6 +155,39 @@ class TramitacaoCrud(MasterDetailCrud):
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
def montar_row_autor():
autor_row = crispy_layout_mixin.to_row(
[('autor', 0),
(Button('pesquisar',
'Pesquisar Autor',
css_class='btn btn-primary btn-sm'), 2),
(Button('limpar',
'Limpar Autor',
css_class='btn btn-primary btn-sm'), 10)])
return autor_row
def montar_helper_documento_acessorio(self):
autor_row = montar_row_autor()
self.helper = FormHelper()
self.helper.layout = crispy_layout_mixin.SaplFormLayout(
*self.get_layout())
# Adiciona o novo campo 'autor' e mecanismo de busca
self.helper.layout[0][0].append(HTML(sapl.utils.autor_label))
self.helper.layout[0][0].append(HTML(sapl.utils.autor_modal))
self.helper.layout[0][1] = autor_row
# Remove botões que estão fora do form
self.helper.layout[1].pop()
# Adiciona novos botões dentro do form
self.helper.layout[0][3][0].insert(1, form_actions(more=[
HTML('<a href="{{ view.cancel_url }}"'
' class="btn btn-inverse">Cancelar</a>')]))
class DocumentoAcessorioCrud(MasterDetailCrud): class DocumentoAcessorioCrud(MasterDetailCrud):
model = DocumentoAcessorio model = DocumentoAcessorio
parent_field = 'materia' parent_field = 'materia'
@ -140,32 +200,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
form_class = DocumentoAcessorioForm form_class = DocumentoAcessorioForm
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
autor_row = crispy_layout_mixin.to_row( montar_helper_documento_acessorio(self)
[('autor', 0),
(Button('pesquisar',
'Pesquisar Autor',
css_class='btn btn-primary btn-sm'), 2),
(Button('limpar',
'Limpar Autor',
css_class='btn btn-primary btn-sm'), 10)])
self.helper = FormHelper()
self.helper.layout = crispy_layout_mixin.SaplFormLayout(
*self.get_layout())
# Adiciona o novo campo 'autor' e mecanismo de busca
self.helper.layout[0][0].append(HTML(sapl.utils.autor_label))
self.helper.layout[0][0].append(HTML(sapl.utils.autor_modal))
self.helper.layout[0][1] = autor_row
# Remove botões que estão fora do form
self.helper.layout[1].pop()
# Adiciona novos botões dentro do form
self.helper.layout[0][3][0].insert(1, form_actions(more=[
HTML('<a href="{{ view.cancel_url }}"'
' class="btn btn-inverse">Cancelar</a>')]))
super(CreateView, self).__init__(*args, **kwargs) super(CreateView, self).__init__(*args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -177,32 +212,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
form_class = DocumentoAcessorioForm form_class = DocumentoAcessorioForm
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
autor_row = crispy_layout_mixin.to_row( montar_helper_documento_acessorio(self)
[('autor', 0),
(Button('pesquisar',
'Pesquisar Autor',
css_class='btn btn-primary btn-sm'), 2),
(Button('limpar',
'Limpar Autor',
css_class='btn btn-primary btn-sm'), 10)])
self.helper = FormHelper()
self.helper.layout = crispy_layout_mixin.SaplFormLayout(
*self.get_layout())
# Adiciona o novo campo 'autor' e mecanismo de busca
self.helper.layout[0][0].append(HTML(sapl.utils.autor_label))
self.helper.layout[0][0].append(HTML(sapl.utils.autor_modal))
self.helper.layout[0][1] = autor_row
# Remove botões que estão fora do form
self.helper.layout[1].pop()
# Adiciona novos botões dentro do form
self.helper.layout[0][3][0].insert(1, form_actions(more=[
HTML('<a href="{{ view.cancel_url }}"'
' class="btn btn-inverse">Cancelar</a>')]))
super(UpdateView, self).__init__(*args, **kwargs) super(UpdateView, self).__init__(*args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -258,7 +268,6 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
self.initial['tipo'] = self.object.norma.tipo.id self.initial['tipo'] = self.object.norma.tipo.id
self.initial['numero'] = self.object.norma.numero self.initial['numero'] = self.object.norma.numero
self.initial['ano'] = self.object.norma.ano self.initial['ano'] = self.object.norma.ano
return self.initial return self.initial
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@ -316,42 +325,6 @@ class MateriaLegislativaCrud(Crud):
list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao'] list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao']
class DocumentoAcessorioView(CreateView):
template_name = "materia/documento_acessorio.html"
form_class = DocumentoAcessorioForm
def get(self, request, *args, **kwargs):
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
docs = DocumentoAcessorio.objects.filter(
materia_id=kwargs['pk']).order_by('data')
form = DocumentoAcessorioForm()
return self.render_to_response(
{'object': materia,
'form': form,
'docs': docs})
def post(self, request, *args, **kwargs):
form = self.get_form()
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
docs_list = DocumentoAcessorio.objects.filter(
materia_id=kwargs['pk'])
if form.is_valid():
documento_acessorio = form.save(commit=False)
documento_acessorio.materia = materia
documento_acessorio.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form,
'object': materia,
'docs': docs_list})
def get_success_url(self):
pk = self.kwargs['pk']
return reverse('materia:documento_acessorio', kwargs={'pk': pk})
class AcompanhamentoConfirmarView(TemplateView): class AcompanhamentoConfirmarView(TemplateView):
def get_redirect_url(self): def get_redirect_url(self):

2
protocoloadm/views.py

@ -4,7 +4,7 @@ from datetime import date, datetime
from braces.views import FormValidMessageMixin from braces.views import FormValidMessageMixin
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import Max, Q from django.db.models import Q, Max
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _

Loading…
Cancel
Save