Browse Source

Fix form and upload file in Fomulario Simplifcado (Materia)

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
53dd7538d2
  1. 20
      materia/migrations/0010_auto_20151117_1551.py
  2. 2
      materia/models.py
  3. 136
      materia/views.py
  4. 6
      templates/materia/formulario_simplificado.html

20
materia/migrations/0010_auto_20151117_1551.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import materia.models
class Migration(migrations.Migration):
dependencies = [
('materia', '0009_auto_20151029_1420'),
]
operations = [
migrations.AlterField(
model_name='materialegislativa',
name='texto_original',
field=models.FileField(verbose_name='Texto Original (PDF)', upload_to=materia.models.texto_upload_path, blank=True, null=True),
),
]

2
materia/models.py

@ -120,7 +120,7 @@ class MateriaLegislativa(models.Model):
blank=True, blank=True,
null=True, null=True,
upload_to=texto_upload_path, upload_to=texto_upload_path,
verbose_name=_('Texto original (PDF)')) verbose_name=_('Texto Original (PDF)'))
class Meta: class Meta:
verbose_name = _('Matéria Legislativa') verbose_name = _('Matéria Legislativa')

136
materia/views.py

@ -1,7 +1,8 @@
from datetime import date from datetime import date
from comissoes.models import Comissao
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit, HTML from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit
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,11 +11,9 @@ from django.shortcuts import render
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from vanilla import GenericView
from comissoes.models import Comissao
from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica
from sapl.crud import build_crud from sapl.crud import build_crud
from vanilla import GenericView
from .models import (Anexada, Autor, Autoria, DespachoInicial, from .models import (Anexada, Autor, Autoria, DespachoInicial,
DocumentoAcessorio, MateriaLegislativa, Numeracao, Orgao, DocumentoAcessorio, MateriaLegislativa, Numeracao, Orgao,
@ -246,58 +245,25 @@ class HorizontalRadioRenderer(forms.RadioSelect.renderer):
return mark_safe(u' '.join([u'%s ' % w for w in self])) return mark_safe(u' '.join([u'%s ' % w for w in self]))
class FormularioSimplificadoForm(forms.Form): class FormularioSimplificadoForm(ModelForm):
tipo_materia = forms.ChoiceField(required=True, data_apresentacao = forms.DateField(label=u'Data Apresentação',
label='Tipo Matéria', input_formats=['%d/%m/%Y'],
choices=get_tipos_materia(), required=False,
widget=forms.Select( widget=forms.DateInput(
attrs={'class': 'selector'})) format='%d/%m/%Y'))
numero_materia = forms.CharField( class Meta:
label='Núm. Matéria', required=True) model = MateriaLegislativa
fields = ['tipo',
ano_materia = forms.ChoiceField(required=True, 'numero',
label='Ano', 'ano',
choices=get_range_anos(), 'data_apresentacao',
widget=forms.Select( 'numero_protocolo',
attrs={'class': 'selector'})) 'regime_tramitacao',
'em_tramitacao',
data_materia = forms.DateField(label='Data Apresentação', 'ementa',
required=True, 'texto_original']
widget=forms.TextInput(
attrs={'class': 'dateinput'}))
numero_protocolo = forms.CharField(
label='Número de Protocolo', required=True)
regime_tramitacao = forms.ChoiceField(required=False,
label='Regime de Tramitação',
choices=get_regimes_tramitacao(),
widget=forms.Select(
attrs={'class': 'selector'}))
em_tramitacao = forms.TypedChoiceField(
coerce=lambda x: x == 'Sim',
choices=((True, 'Sim'), (False, 'Não')),
widget=forms.RadioSelect
)
ementa = forms.CharField(
label='Ementa', required=True, widget=forms.Textarea)
texto_original = forms.ChoiceField(required=False,
label='Regime de Tramitação',
choices=(
('1', 'Arquivo'),
('2', 'Proposição')),
widget=forms.RadioSelect)
arquivo = forms.FileField(required=False, label='Arquivo')
proposicao = forms.CharField(required=False, label='Proposição',
widget=forms.TextInput(
attrs={'disabled': 'True'}))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.helper = FormHelper() self.helper = FormHelper()
@ -306,17 +272,15 @@ class FormularioSimplificadoForm(forms.Form):
'Formulário Simplificado', 'Formulário Simplificado',
Fieldset( Fieldset(
'Identificação Básica', 'Identificação Básica',
'tipo_materia', 'tipo',
'numero_materia', 'numero',
'ano_materia', 'ano',
'data_materia', 'data_apresentacao',
'numero_protocolo', 'numero_protocolo',
'regime_tramitacao', 'regime_tramitacao',
'em_tramitacao', 'em_tramitacao',
'ementa', 'ementa',
'texto_original', 'texto_original'
'arquivo',
'proposicao'
), ),
ButtonHolder( ButtonHolder(
Submit('submit', 'Salvar', Submit('submit', 'Salvar',
@ -407,9 +371,7 @@ class FormularioCadastroForm(ModelForm):
class FormularioSimplificadoView(FormMixin, GenericView): class FormularioSimplificadoView(FormMixin, GenericView):
template_name = "materia/formulario_simplificado.html" template_name = "materia/formulario_simplificado.html"
model = MateriaLegislativa
def get_success_url(self): def get_success_url(self):
return reverse('formulario_simplificado') return reverse('formulario_simplificado')
@ -422,21 +384,22 @@ class FormularioSimplificadoView(FormMixin, GenericView):
form = FormularioSimplificadoForm(request.POST) form = FormularioSimplificadoForm(request.POST)
if form.is_valid: if form.is_valid:
materia = form.save(commit=False)
materia = MateriaLegislativa() if request.FILES['texto_original']:
materia.numero = request.POST['numero_materia'] materia.texto_original = request.FILES['texto_original']
materia.ano = request.POST['ano_materia']
materia.numero_protocolo = request.POST['numero_protocolo']
materia.em_tramitacao = request.POST['em_tramitacao']
materia.ementa = request.POST['ementa']
materia.tipo_id = request.POST['tipo_materia']
materia.regime_tramitacao_id = request.POST['regime_tramitacao']
materia.save() materia.save()
# materia = MateriaLegislativa()
# materia.numero = request.POST['numero_materia']
# materia.ano = request.POST['ano_materia']
# materia.numero_protocolo = request.POST['numero_protocolo']
# materia.em_tramitacao = request.POST['em_tramitacao']
# materia.ementa = request.POST['ementa']
# materia.tipo_id = request.POST['tipo_materia']
# materia.regime_tramitacao_id = request.POST['regime_tramitacao']
# materia.texto_original = request.FILES['texto_original']
# materia.save()
message = "Materia Legislativa criada com sucesso" return self.form_valid(form)
return render(request,
reverse('formulario_simplificado'),
{'form': form, 'message': message})
else: else:
return self.form_invalid(form) return self.form_invalid(form)
@ -1262,7 +1225,8 @@ class TramitacaoForm(ModelForm):
self.helper = FormHelper() self.helper = FormHelper()
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset('Incluir Tramitação', Fieldset('Incluir Tramitação',
HTML("<ul class='small-block-grid-2 medium-block-grid-2 large-block-grid-2'>"), HTML(
"<ul class='small-block-grid-2 medium-block-grid-2 large-block-grid-2'>"),
HTML("<li>"), HTML("<li>"),
'data_tramitacao', 'data_tramitacao',
HTML("</li>"), HTML("</li>"),
@ -1270,7 +1234,8 @@ class TramitacaoForm(ModelForm):
'unidade_tramitacao_local', 'unidade_tramitacao_local',
HTML("</li>"), HTML("</li>"),
HTML("</ul>"), HTML("</ul>"),
HTML("<ul class='small-block-grid-3 medium-block-grid-3 large-block-grid-3'>"), HTML(
"<ul class='small-block-grid-3 medium-block-grid-3 large-block-grid-3'>"),
HTML("<li>"), HTML("<li>"),
'status', 'status',
HTML("</li>"), HTML("</li>"),
@ -1281,12 +1246,14 @@ class TramitacaoForm(ModelForm):
'urgente', 'urgente',
HTML("</li>"), HTML("</li>"),
HTML("</ul>"), HTML("</ul>"),
HTML("<ul class='small-block-grid-1 medium-block-grid-1 large-block-grid-1'>"), HTML(
"<ul class='small-block-grid-1 medium-block-grid-1 large-block-grid-1'>"),
HTML("<li>"), HTML("<li>"),
'unidade_tramitacao_destino', 'unidade_tramitacao_destino',
HTML("</li>"), HTML("</li>"),
HTML("</ul>"), HTML("</ul>"),
HTML("<ul class='small-block-grid-3 medium-block-grid-3 large-block-grid-3'>"), HTML(
"<ul class='small-block-grid-3 medium-block-grid-3 large-block-grid-3'>"),
HTML("<li>"), HTML("<li>"),
'data_encaminhamento', 'data_encaminhamento',
HTML("</li>"), HTML("</li>"),
@ -1297,7 +1264,8 @@ class TramitacaoForm(ModelForm):
'ultima', 'ultima',
HTML("</li>"), HTML("</li>"),
HTML("</ul>"), HTML("</ul>"),
HTML("<ul class='small-block-grid-1 medium-block-grid-1 large-block-grid-1'>"), HTML(
"<ul class='small-block-grid-1 medium-block-grid-1 large-block-grid-1'>"),
HTML("<li>"), HTML("<li>"),
'texto', 'texto',
HTML("</li>"), HTML("</li>"),
@ -1452,7 +1420,7 @@ class AutoriaView(GenericView):
autoria = Autoria.objects.get( autoria = Autoria.objects.get(
autor=autor, autor=autor,
materia=materia materia=materia
) )
except ObjectDoesNotExist: except ObjectDoesNotExist:
autoria = Autoria() autoria = Autoria()
@ -1527,7 +1495,7 @@ class AutoriaEditView(GenericView):
autoria = Autoria.objects.get( autoria = Autoria.objects.get(
autor=autor, autor=autor,
materia=materia materia=materia
) )
except ObjectDoesNotExist: except ObjectDoesNotExist:
autoria = Autoria() autoria = Autoria()
@ -1563,4 +1531,4 @@ class AutoriaEditView(GenericView):
def get_success_url(self): def get_success_url(self):
pk = self.kwargs['pk'] pk = self.kwargs['pk']
return reverse('autoria', kwargs={'pk': pk}) return reverse('autoria', kwargs={'pk': pk})

6
templates/materia/formulario_simplificado.html

@ -3,9 +3,5 @@
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block detail_content %} {% block detail_content %}
<form method="POST"> {% crispy form %}
{% csrf_token %}
{% crispy form %}
</br>
</form>
{% endblock %} {% endblock %}
Loading…
Cancel
Save