Browse Source

Add form to PreposicaoView

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
9d9412e344
  1. 19
      materia/migrations/0012_auto_20151124_1328.py
  2. 4
      materia/models.py
  3. 59
      materia/views.py
  4. 4
      templates/materia/proposicao.html

19
materia/migrations/0012_auto_20151124_1328.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('materia', '0011_proposicao_texto_original'),
]
operations = [
migrations.AlterField(
model_name='proposicao',
name='autor',
field=models.ForeignKey(null=True, to='materia.Autor', blank=True),
),
]

4
materia/models.py

@ -46,7 +46,7 @@ class Origem(models.Model):
def get_materia_media_path(instance, subpath, filename):
return './materia/%s/%s/%s' % (instance.numero, subpath, filename)
return './materia/%s/%s/%s' % (instance, subpath, filename)
def texto_upload_path(instance, filename):
@ -425,7 +425,7 @@ class TipoProposicao(models.Model):
class Proposicao(models.Model):
autor = models.ForeignKey(Autor)
autor = models.ForeignKey(Autor, null=True, blank=True)
tipo = models.ForeignKey(TipoProposicao, verbose_name=_('Tipo'))
# XXX data_envio was not null, but actual data said otherwise!!!
data_envio = models.DateTimeField(

59
materia/views.py

@ -1,4 +1,4 @@
from datetime import date
from datetime import date, datetime
import sapl
from comissoes.models import Comissao, Composicao
@ -1699,14 +1699,10 @@ class AutoriaEditView(GenericView):
class ProposicaoForm(ModelForm):
tipo = forms.ChoiceField(required=True,
label='Tipo',
choices=get_tipos_proposicao(),
widget=forms.Select(
attrs={'class': 'selector'}))
descricao = forms.CharField(
label='Descrição', required=True)
label='Descrição', required=True,
widget=forms.Textarea())
tipo_materia = forms.ChoiceField(required=False,
label='Matéria Vinculada',
@ -1725,6 +1721,15 @@ class ProposicaoForm(ModelForm):
fields = ['tipo',
'descricao',
'texto_original']
exclude = ['autor',
'data_envio',
'data_recebimento',
'data_devolucao',
'justificativa_devolucao',
'numero_proposicao',
'status',
'materia',
'documento']
def __init__(self, *args, **kwargs):
@ -1743,17 +1748,13 @@ class ProposicaoForm(ModelForm):
Column(
ButtonHolder(
Submit('sumbmit', 'Salvar',
css_class='button primary')
), css_class='columns large-2'))
css_class='button primary')
), css_class='columns large-2'))
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset('Incluir Proposição',
row1,
row2,
row3,
row4,
)
row1, row2, row3, row4)
)
super(ProposicaoForm, self).__init__(
*args, **kwargs)
@ -1767,6 +1768,32 @@ class ProposicaoView(FormMixin, GenericView):
def get(self, request, *args, **kwargs):
form = ProposicaoForm()
return self.render_to_response({'form': form})
return self.render_to_response(
{'form': form})
def post(self, request, *args, **kwargs):
form = ProposicaoForm(request.POST)
if form.is_valid():
proposicao = form.save(commit=False)
if 'texto_original' in request.FILES:
proposicao.texto_original = request.FILES['texto_original']
try:
materia = MateriaLegislativa.objects.get(
tipo_id=int(form.data['tipo_materia']),
ano=int(form.data['ano_materia']),
numero=int(form.data['numero_materia']))
except ObjectDoesNotExist:
return self.render_to_response(
{'form': form,
'error': 'Matéria adiconada não existe!'})
else:
proposicao.autor = materia.autoria_set.first().autor
proposicao.materia = materia
proposicao.data_envio = datetime.now()
proposicao.save()
return self.form_valid(form)
else:
self.render_to_response({'form': form})

4
templates/materia/proposicao.html

@ -1,6 +1,8 @@
{% extends "crud/form.html" %}
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
{% if error %} <h5 align="center"><font color="#FF0000">{{ error }}</font></h5> {% endif %}
{% crispy form %}
{% endblock %}
Loading…
Cancel
Save