Browse Source

Usa CreateView para CriarDocumentoProtocolo

pull/222/head
Marcio Mazza 9 years ago
parent
commit
cb98a8b2e0
  1. 7
      protocoloadm/models.py
  2. 32
      protocoloadm/views.py
  3. 7
      templates/protocoloadm/criar_documento.html

7
protocoloadm/models.py

@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _
from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao
from sapl.utils import YES_NO_CHOICES, make_choices from sapl.utils import YES_NO_CHOICES, make_choices
from uuid import uuid4
class TipoDocumentoAdministrativo(models.Model): class TipoDocumentoAdministrativo(models.Model):
@ -17,12 +18,8 @@ class TipoDocumentoAdministrativo(models.Model):
return self.descricao return self.descricao
def get_docadm_media_path(instance, subpath, filename):
return './docadm/%s/%s/%s' % (instance, subpath, filename)
def texto_upload_path(instance, filename): def texto_upload_path(instance, filename):
return get_docadm_media_path(instance, 'DocAdm', filename) return '/'.join([instance._meta.model_name, str(uuid4()), filename])
class DocumentoAdministrativo(models.Model): class DocumentoAdministrativo(models.Model):

32
protocoloadm/views.py

@ -1,7 +1,6 @@
from datetime import date, datetime from datetime import date, datetime
from re import sub from re import sub
import sapl
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -10,13 +9,15 @@ from django.http import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
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.generic import DetailView, ListView from django.views.generic import CreateView, DetailView, ListView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from vanilla import GenericView
import sapl
from materia.models import Proposicao, TipoMateriaLegislativa from materia.models import Proposicao, TipoMateriaLegislativa
from sapl.crud import build_crud from sapl.crud import build_crud
from sapl.utils import create_barcode from sapl.utils import create_barcode
from vanilla import GenericView
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoForm, ProposicaoSimpleForm, DocumentoAdministrativoForm, ProposicaoSimpleForm,
@ -324,33 +325,18 @@ def criar_documento(protocolo):
return doc return doc
class CriarDocumentoProtocolo(FormMixin, GenericView): class CriarDocumentoProtocolo(CreateView):
template_name = "protocoloadm/criar_documento.html" template_name = "protocoloadm/criar_documento.html"
form_class = DocumentoAdministrativoForm
def get(self, request, *args, **kwargs): def get_initial(self):
numero = self.kwargs['pk'] numero = self.kwargs['pk']
ano = self.kwargs['ano'] ano = self.kwargs['ano']
protocolo = Protocolo.objects.get(ano=ano, numero=numero) protocolo = Protocolo.objects.get(ano=ano, numero=numero)
form = DocumentoAdministrativoForm( return criar_documento(protocolo)
initial=criar_documento(protocolo))
return self.render_to_response({
'form': form})
def post(self, request, *args, **kwargs):
form = DocumentoAdministrativoForm(request.POST)
if form.is_valid():
doc = form.save(commit=False)
if 'texto_integral' in request.FILES:
doc.texto_integral = request.FILES['texto_integral']
doc.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form})
def get_success_url(self): def get_success_url(self):
return reverse('detail_doc_adm', kwargs={ return reverse('detail_doc_adm', kwargs={'pk': self.object.pk})
'pk': self.kwargs['pk']})
class ProtocoloMostrarView(TemplateView): class ProtocoloMostrarView(TemplateView):

7
templates/protocoloadm/criar_documento.html

@ -1,7 +0,0 @@
{% extends "crud/form.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
{% endblock detail_content %}
Loading…
Cancel
Save