Browse Source

Fix #1939 #1958 (#1978)

* Fix #1958

* Fix #1939 #1958

Corrige erro de inicialização em formulários

Co-authored-by: edwardoliveira <edwardr@senado.gov.br>
pull/1979/head
João Pedro Sconetto 7 years ago
committed by Edward
parent
commit
b8e3484ff5
  1. 20
      sapl/audiencia/views.py
  2. 46
      sapl/materia/views.py
  3. 22
      sapl/norma/views.py
  4. 11
      sapl/protocoloadm/views.py
  5. 41
      sapl/sessao/views.py

20
sapl/audiencia/views.py

@ -1,15 +1,10 @@
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.db.models import F
from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import ListView from django.views.generic import UpdateView
from sapl.comissoes.forms import ParticipacaoCreateForm, ParticipacaoEditForm from sapl.crud.base import RP_DETAIL, RP_LIST, Crud
from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, MasterDetailCrud
from sapl.materia.models import MateriaLegislativa
from .forms import AudienciaForm from .forms import AudienciaForm
from .models import (AudienciaPublica, TipoAudienciaPublica) from .models import AudienciaPublica
def index(request): def index(request):
return HttpResponse("Audiência Pública") return HttpResponse("Audiência Pública")
@ -36,10 +31,11 @@ class AudienciaCrud(Crud):
form_class = AudienciaForm form_class = AudienciaForm
def get_initial(self): def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id initial = super(UpdateView, self).get_initial()
self.initial['numero_materia'] = self.object.materia.numero initial['tipo_materia'] = self.object.materia.tipo.id
self.initial['ano_materia'] = self.object.materia.ano initial['numero_materia'] = self.object.materia.numero
return self.initial initial['ano_materia'] = self.object.materia.ano
return initial
class DeleteView(Crud.DeleteView): class DeleteView(Crud.DeleteView):
pass pass

46
sapl/materia/views.py

@ -17,7 +17,7 @@ from django.shortcuts import get_object_or_404, redirect
from django.template import RequestContext, loader from django.template import RequestContext, loader
from django.utils import formats, timezone from django.utils import formats, timezone
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 FormView, ListView, TemplateView, CreateView, UpdateView
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from django_filters.views import FilterView from django_filters.views import FilterView
@ -1013,18 +1013,19 @@ class TramitacaoCrud(MasterDetailCrud):
'pk': self.kwargs['pk']}) 'pk': self.kwargs['pk']})
def get_initial(self): def get_initial(self):
initial = super(CreateView, self).get_initial()
local = MateriaLegislativa.objects.get( local = MateriaLegislativa.objects.get(
pk=self.kwargs['pk']).tramitacao_set.order_by( pk=self.kwargs['pk']).tramitacao_set.order_by(
'-data_tramitacao', '-data_tramitacao',
'-id').first() '-id').first()
if local: if local:
self.initial['unidade_tramitacao_local' initial['unidade_tramitacao_local'
] = local.unidade_tramitacao_destino.pk ] = local.unidade_tramitacao_destino.pk
else: else:
self.initial['unidade_tramitacao_local'] = '' initial['unidade_tramitacao_local'] = ''
self.initial['data_tramitacao'] = timezone.now().date() initial['data_tramitacao'] = timezone.now().date()
return self.initial return initial
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -1154,9 +1155,10 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
super(MasterDetailCrud.CreateView, self).__init__(**kwargs) super(MasterDetailCrud.CreateView, self).__init__(**kwargs)
def get_initial(self): def get_initial(self):
self.initial['data'] = timezone.now().date() initial = super(CreateView, self).get_initial()
initial['data'] = timezone.now().date()
return self.initial return initial
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super( context = super(
@ -1283,10 +1285,11 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
form_class = LegislacaoCitadaForm form_class = LegislacaoCitadaForm
def get_initial(self): def get_initial(self):
self.initial['tipo'] = self.object.norma.tipo.id initial = super(UpdateView, self).get_initial()
self.initial['numero'] = self.object.norma.numero initial['tipo'] = self.object.norma.tipo.id
self.initial['ano'] = self.object.norma.ano initial['numero'] = self.object.norma.numero
return self.initial initial['ano'] = self.object.norma.ano
return initial
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@ -1319,10 +1322,11 @@ class AnexadaCrud(MasterDetailCrud):
form_class = AnexadaForm form_class = AnexadaForm
def get_initial(self): def get_initial(self):
self.initial['tipo'] = self.object.materia_anexada.tipo.id initial = super(UpdateView, self).get_initial()
self.initial['numero'] = self.object.materia_anexada.numero initial['tipo'] = self.object.materia_anexada.tipo.id
self.initial['ano'] = self.object.materia_anexada.ano initial['numero'] = self.object.materia_anexada.numero
return self.initial initial['ano'] = self.object.materia_anexada.ano
return initial
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@ -1344,16 +1348,18 @@ class MateriaAssuntoCrud(MasterDetailCrud):
form_class = MateriaAssuntoForm form_class = MateriaAssuntoForm
def get_initial(self): def get_initial(self):
self.initial['materia'] = self.kwargs['pk'] initial = super(CreateView, self).get_initial()
return self.initial initial['materia'] = self.kwargs['pk']
return initial
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = MateriaAssuntoForm form_class = MateriaAssuntoForm
def get_initial(self): def get_initial(self):
self.initial['materia'] = self.get_object().materia initial = super(UpdateView, self).get_initial()
self.initial['assunto'] = self.get_object().assunto initial['materia'] = self.get_object().materia
return self.initial initial['assunto'] = self.get_object().assunto
return initial
class MateriaLegislativaCrud(Crud): class MateriaLegislativaCrud(Crud):

22
sapl/norma/views.py

@ -7,7 +7,7 @@ from django.http import HttpResponse, JsonResponse
from django.template import RequestContext, loader from django.template import RequestContext, loader
from django.utils import timezone from django.utils import timezone
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 TemplateView, UpdateView
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from django_filters.views import FilterView from django_filters.views import FilterView
@ -51,11 +51,12 @@ class NormaRelacionadaCrud(MasterDetailCrud):
form_class = NormaRelacionadaForm form_class = NormaRelacionadaForm
def get_initial(self): def get_initial(self):
self.initial['tipo'] = self.object.norma_relacionada.tipo.id initial = super(UpdateView, self).get_initial()
self.initial['numero'] = self.object.norma_relacionada.numero initial['tipo'] = self.object.norma_relacionada.tipo.id
self.initial['ano'] = self.object.norma_relacionada.ano initial['numero'] = self.object.norma_relacionada.numero
self.initial['ementa'] = self.object.norma_relacionada.ementa initial['ano'] = self.object.norma_relacionada.ano
return self.initial initial['ementa'] = self.object.norma_relacionada.ementa
return initial
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@ -171,12 +172,13 @@ class NormaCrud(Crud):
layout_key = 'NormaJuridicaCreate' layout_key = 'NormaJuridicaCreate'
def get_initial(self): def get_initial(self):
initial = super(UpdateView, self).get_initial()
norma = NormaJuridica.objects.get(id=self.kwargs['pk']) norma = NormaJuridica.objects.get(id=self.kwargs['pk'])
if norma.materia: if norma.materia:
self.initial['tipo_materia'] = norma.materia.tipo initial['tipo_materia'] = norma.materia.tipo
self.initial['ano_materia'] = norma.materia.ano initial['ano_materia'] = norma.materia.ano
self.initial['numero_materia'] = norma.materia.numero initial['numero_materia'] = norma.materia.numero
return self.initial.copy() return initial
def recuperar_norma(request): def recuperar_norma(request):

11
sapl/protocoloadm/views.py

@ -11,7 +11,7 @@ from django.http.response import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, ListView from django.views.generic import ListView, CreateView
from django.views.generic.base import RedirectView, TemplateView from django.views.generic.base import RedirectView, TemplateView
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from django_filters.views import FilterView from django_filters.views import FilterView
@ -610,18 +610,19 @@ class TramitacaoAdmCrud(MasterDetailCrud):
form_class = TramitacaoAdmForm form_class = TramitacaoAdmForm
def get_initial(self): def get_initial(self):
initial = super(CreateView, self).get_initial()
local = DocumentoAdministrativo.objects.get( local = DocumentoAdministrativo.objects.get(
pk=self.kwargs['pk']).tramitacaoadministrativo_set.order_by( pk=self.kwargs['pk']).tramitacaoadministrativo_set.order_by(
'-data_tramitacao', '-data_tramitacao',
'-id').first() '-id').first()
if local: if local:
self.initial['unidade_tramitacao_local' initial['unidade_tramitacao_local'
] = local.unidade_tramitacao_destino.pk ] = local.unidade_tramitacao_destino.pk
else: else:
self.initial['unidade_tramitacao_local'] = '' initial['unidade_tramitacao_local'] = ''
self.initial['data_tramitacao'] = timezone.now().date() initial['data_tramitacao'] = timezone.now().date()
return self.initial return initial
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)

41
sapl/sessao/views.py

@ -16,7 +16,7 @@ from django.utils.decorators import method_decorator
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic import FormView, ListView, TemplateView from django.views.generic import FormView, ListView, TemplateView, CreateView, UpdateView
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
@ -418,14 +418,15 @@ class MateriaOrdemDiaCrud(MasterDetailCrud):
form_class = OrdemDiaForm form_class = OrdemDiaForm
def get_initial(self): def get_initial(self):
self.initial['data_ordem'] = SessaoPlenaria.objects.get( initial = super(CreateView, self).get_inital()
initial['data_ordem'] = SessaoPlenaria.objects.get(
pk=self.kwargs['pk']).data_inicio.strftime('%d/%m/%Y') pk=self.kwargs['pk']).data_inicio.strftime('%d/%m/%Y')
max_numero_ordem = OrdemDia.objects.filter( max_numero_ordem = OrdemDia.objects.filter(
sessao_plenaria=self.kwargs['pk']).aggregate( sessao_plenaria=self.kwargs['pk']).aggregate(
Max('numero_ordem'))['numero_ordem__max'] Max('numero_ordem'))['numero_ordem__max']
self.initial['numero_ordem'] = ( initial['numero_ordem'] = (
max_numero_ordem if max_numero_ordem else 0) + 1 max_numero_ordem if max_numero_ordem else 0) + 1
return self.initial return initial
def get_success_url(self): def get_success_url(self):
return reverse('sapl.sessao:ordemdia_list', return reverse('sapl.sessao:ordemdia_list',
@ -435,10 +436,11 @@ class MateriaOrdemDiaCrud(MasterDetailCrud):
form_class = OrdemDiaForm form_class = OrdemDiaForm
def get_initial(self): def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id initial = super(UpdateView, self).get_initial()
self.initial['numero_materia'] = self.object.materia.numero initial['tipo_materia'] = self.object.materia.tipo.id
self.initial['ano_materia'] = self.object.materia.ano initial['numero_materia'] = self.object.materia.numero
return self.initial initial['ano_materia'] = self.object.materia.ano
return initial
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@ -492,14 +494,15 @@ class ExpedienteMateriaCrud(MasterDetailCrud):
form_class = ExpedienteMateriaForm form_class = ExpedienteMateriaForm
def get_initial(self): def get_initial(self):
self.initial['data_ordem'] = SessaoPlenaria.objects.get( initial = super(CreateView, self).get_initial()
initial['data_ordem'] = SessaoPlenaria.objects.get(
pk=self.kwargs['pk']).data_inicio.strftime('%d/%m/%Y') pk=self.kwargs['pk']).data_inicio.strftime('%d/%m/%Y')
max_numero_ordem = ExpedienteMateria.objects.filter( max_numero_ordem = ExpedienteMateria.objects.filter(
sessao_plenaria=self.kwargs['pk']).aggregate( sessao_plenaria=self.kwargs['pk']).aggregate(
Max('numero_ordem'))['numero_ordem__max'] Max('numero_ordem'))['numero_ordem__max']
self.initial['numero_ordem'] = ( initial['numero_ordem'] = (
max_numero_ordem if max_numero_ordem else 0) + 1 max_numero_ordem if max_numero_ordem else 0) + 1
return self.initial return initial
def get_success_url(self): def get_success_url(self):
return reverse('sapl.sessao:expedientemateria_list', return reverse('sapl.sessao:expedientemateria_list',
@ -509,10 +512,11 @@ class ExpedienteMateriaCrud(MasterDetailCrud):
form_class = ExpedienteMateriaForm form_class = ExpedienteMateriaForm
def get_initial(self): def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id initial = super(UpdateView, self).get_initial()
self.initial['numero_materia'] = self.object.materia.numero initial['tipo_materia'] = self.object.materia.tipo.id
self.initial['ano_materia'] = self.object.materia.ano initial['numero_materia'] = self.object.materia.numero
return self.initial initial['ano_materia'] = self.object.materia.ano
return initial
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@ -1146,9 +1150,10 @@ class ResumoOrdenacaoView(PermissionRequiredMixin, FormView):
return reverse('sapl.base:sistema') return reverse('sapl.base:sistema')
def get_initial(self): def get_initial(self):
initial = super(ResumoOrdenacaoView, self).get_initial()
ordenacao = ResumoOrdenacao.objects.first() ordenacao = ResumoOrdenacao.objects.first()
if ordenacao: if ordenacao:
return {'primeiro': ordenacao.primeiro, initial.update({'primeiro': ordenacao.primeiro,
'segundo': ordenacao.segundo, 'segundo': ordenacao.segundo,
'terceiro': ordenacao.terceiro, 'terceiro': ordenacao.terceiro,
'quarto': ordenacao.quarto, 'quarto': ordenacao.quarto,
@ -1157,8 +1162,8 @@ class ResumoOrdenacaoView(PermissionRequiredMixin, FormView):
'setimo': ordenacao.setimo, 'setimo': ordenacao.setimo,
'oitavo': ordenacao.oitavo, 'oitavo': ordenacao.oitavo,
'nono': ordenacao.nono, 'nono': ordenacao.nono,
'decimo': ordenacao.decimo} 'decimo': ordenacao.decimo})
return self.initial.copy() return initial
def form_valid(self, form): def form_valid(self, form):
ordenacao = ResumoOrdenacao.objects.get_or_create()[0] ordenacao = ResumoOrdenacao.objects.get_or_create()[0]

Loading…
Cancel
Save