Browse Source

Init crud documento acessório

pull/425/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
c9d78fc183
  1. 1
      materia/forms.py
  2. 72
      materia/views.py

1
materia/forms.py

@ -119,7 +119,6 @@ class DocumentoAcessorioForm(ModelForm):
class Meta:
model = DocumentoAcessorio
fields = ['tipo', 'nome', 'data', 'autor', 'ementa', 'arquivo']
widgets = {'autor': forms.HiddenInput()}
def clean_autor(self):

72
materia/views.py

@ -342,42 +342,6 @@ class MateriaLegislativaCrud(Crud):
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):
def get_redirect_url(self):
@ -413,42 +377,6 @@ class AcompanhamentoExcluirView(TemplateView):
return HttpResponseRedirect(self.get_redirect_url())
class DocumentoAcessorioEditView(CreateView):
template_name = "materia/documento_acessorio_edit.html"
form_class = DocumentoAcessorioForm
def get(self, request, *args, **kwargs):
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
documento = DocumentoAcessorio.objects.get(id=kwargs['id'])
form = DocumentoAcessorioForm(instance=documento, excluir=True)
return self.render_to_response({'object': materia, 'form': form})
def post(self, request, *args, **kwargs):
form = self.get_form()
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
documento = DocumentoAcessorio.objects.get(id=kwargs['id'])
if form.is_valid():
if 'Excluir' in request.POST:
documento.delete()
elif 'salvar' in request.POST:
documento.materia = materia
documento.tipo = form.cleaned_data['tipo']
documento.data = form.cleaned_data['data']
documento.nome = form.cleaned_data['nome']
documento.autor = form.cleaned_data['autor']
documento.ementa = form.cleaned_data['ementa']
documento.save()
return redirect(self.get_success_url())
else:
return self.render_to_response({'form': form,
'object': materia,
'doc': documento})
def get_success_url(self):
pk = self.kwargs['pk']
return reverse('materia:documento_acessorio', kwargs={'pk': pk})
def load_email_templates(templates, context={}):
emails = []

Loading…
Cancel
Save