|
@ -1,11 +1,9 @@ |
|
|
from datetime import datetime |
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
from django.contrib import messages |
|
|
from django.core.urlresolvers import reverse_lazy |
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
|
|
from django.http import HttpResponseRedirect |
|
|
from django.http import HttpResponseRedirect |
|
|
from django.shortcuts import redirect |
|
|
from django.shortcuts import redirect |
|
|
from django.views.generic import CreateView, FormView, ListView |
|
|
from django.views.generic import CreateView, FormView, ListView, UpdateView |
|
|
|
|
|
|
|
|
from compilacao.views import IntegracaoTaView |
|
|
from compilacao.views import IntegracaoTaView |
|
|
from crud.base import Crud, make_pagination |
|
|
from crud.base import Crud, make_pagination |
|
@ -24,13 +22,8 @@ LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') |
|
|
|
|
|
|
|
|
class NormaPesquisaView(FormView): |
|
|
class NormaPesquisaView(FormView): |
|
|
template_name = "norma/pesquisa.html" |
|
|
template_name = "norma/pesquisa.html" |
|
|
|
|
|
success_url = "normajuridica:norma_pesquisa" |
|
|
def get_success_url(self): |
|
|
form_class = NormaJuridicaPesquisaForm |
|
|
return reverse('normajuridica:norma_pesquisa') |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
|
form = NormaJuridicaPesquisaForm() |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
def post(self, request, *args, **kwargs): |
|
|
form = NormaJuridicaPesquisaForm(request.POST) |
|
|
form = NormaJuridicaPesquisaForm(request.POST) |
|
@ -120,74 +113,49 @@ class PesquisaNormaListView(ListView): |
|
|
class NormaIncluirView(CreateView): |
|
|
class NormaIncluirView(CreateView): |
|
|
template_name = "norma/normajuridica_incluir.html" |
|
|
template_name = "norma/normajuridica_incluir.html" |
|
|
form_class = NormaJuridicaForm |
|
|
form_class = NormaJuridicaForm |
|
|
|
|
|
success_url = reverse_lazy('normajuridica:list') |
|
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
def form_valid(self, form): |
|
|
return reverse('normajuridica:list') |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
|
form = NormaJuridicaForm() |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
|
form = self.get_form() |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
|
norma = form.save(commit=False) |
|
|
norma = form.save(commit=False) |
|
|
|
|
|
norma.timestamp = datetime.now() |
|
|
if form.cleaned_data['tipo_materia']: |
|
|
if form.cleaned_data['tipo_materia']: |
|
|
try: |
|
|
|
|
|
materia = MateriaLegislativa.objects.get( |
|
|
materia = MateriaLegislativa.objects.get( |
|
|
tipo_id=form.cleaned_data['tipo_materia'], |
|
|
tipo_id=form.data['tipo_materia'], |
|
|
numero=form.cleaned_data['numero_materia'], |
|
|
numero=form.data['numero_materia'], |
|
|
ano=form.cleaned_data['ano_materia']) |
|
|
ano=form.data['ano_materia']) |
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
msg = 'Matéria adicionada não existe!' |
|
|
|
|
|
messages.add_message(request, messages.INFO, msg) |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
else: |
|
|
|
|
|
norma.materia = materia |
|
|
norma.materia = materia |
|
|
norma.timestamp = datetime.now() |
|
|
|
|
|
norma.save() |
|
|
norma.save() |
|
|
return HttpResponseRedirect(self.get_success_url()) |
|
|
return HttpResponseRedirect(self.get_success_url()) |
|
|
else: |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NormaEditView(CreateView): |
|
|
class NormaEditView(UpdateView): |
|
|
template_name = "norma/normajuridica_incluir.html" |
|
|
template_name = "norma/normajuridica_incluir.html" |
|
|
form_class = NormaJuridicaForm |
|
|
form_class = NormaJuridicaForm |
|
|
|
|
|
model = NormaJuridica |
|
|
|
|
|
success_url = reverse_lazy('normajuridica:list') |
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
def get_initial(self): |
|
|
norma = NormaJuridica.objects.get(id=self.kwargs['pk']) |
|
|
data = super(NormaEditView, self).get_initial() |
|
|
form = NormaJuridicaForm(instance=norma) |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
|
norma = NormaJuridica.objects.get(id=self.kwargs['pk']) |
|
|
norma = NormaJuridica.objects.get(id=self.kwargs['pk']) |
|
|
form = NormaJuridicaForm(instance=norma, data=request.POST) |
|
|
if norma.materia: |
|
|
|
|
|
data.update({ |
|
|
if form.is_valid(): |
|
|
'tipo_materia': norma.materia.tipo, |
|
|
if form.data['tipo_materia']: |
|
|
'numero_materia': norma.materia.numero, |
|
|
try: |
|
|
'ano_materia': norma.materia.ano, |
|
|
|
|
|
}) |
|
|
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
def form_valid(self, form): |
|
|
|
|
|
norma = form.save(commit=False) |
|
|
|
|
|
norma.timestamp = datetime.now() |
|
|
|
|
|
if form.cleaned_data['tipo_materia']: |
|
|
materia = MateriaLegislativa.objects.get( |
|
|
materia = MateriaLegislativa.objects.get( |
|
|
tipo_id=form.data['tipo_materia'], |
|
|
tipo_id=form.data['tipo_materia'], |
|
|
numero=form.data['numero_materia'], |
|
|
numero=form.data['numero_materia'], |
|
|
ano=form.data['ano_materia']) |
|
|
ano=form.data['ano_materia']) |
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
msg = 'Matéria adicionada não existe!' |
|
|
|
|
|
messages.add_message(request, messages.INFO, msg) |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
else: |
|
|
|
|
|
norma.materia = materia |
|
|
norma.materia = materia |
|
|
norma = form.save(commit=False) |
|
|
|
|
|
norma.timestamp = datetime.now() |
|
|
|
|
|
norma.save() |
|
|
norma.save() |
|
|
return HttpResponseRedirect(self.get_success_url()) |
|
|
return HttpResponseRedirect(self.get_success_url()) |
|
|
else: |
|
|
|
|
|
return self.render_to_response({'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
|
|
return reverse('normajuridica:list') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NormaTaView(IntegracaoTaView): |
|
|
class NormaTaView(IntegracaoTaView): |
|
|