Browse Source

Implemente upload file in register norma

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
eab50ec873
  1. 19
      compilacao/migrations/0030_auto_20151203_1117.py
  2. 20
      norma/migrations/0008_normajuridica_texto_integral.py
  3. 14
      norma/models.py
  4. 21
      norma/views.py
  5. 1
      parlamentares/urls.py
  6. 5
      parlamentares/views.py
  7. 7
      templates/norma/normajuridica_incluir.html

19
compilacao/migrations/0030_auto_20151203_1117.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('compilacao', '0029_auto_20151201_1611'),
]
operations = [
migrations.AlterField(
model_name='tipodispositivo',
name='relacoes_diretas_pai_filho',
field=models.ManyToManyField(to='compilacao.TipoDispositivo', through='compilacao.TipoDispositivoRelationship', related_name='+'),
),
]

20
norma/migrations/0008_normajuridica_texto_integral.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import norma.models
class Migration(migrations.Migration):
dependencies = [
('norma', '0007_auto_20151130_1632'),
]
operations = [
migrations.AddField(
model_name='normajuridica',
name='texto_integral',
field=models.FileField(null=True, verbose_name='Texto Integral', upload_to=norma.models.texto_upload_path, blank=True),
),
]

14
norma/models.py

@ -53,13 +53,25 @@ class TipoNormaJuridica(models.Model):
return self.descricao
def get_norma_media_path(instance, subpath, filename):
return './norma/%s/%s/%s' % (instance, subpath, filename)
def texto_upload_path(instance, filename):
return get_norma_media_path(instance, instance.ano, filename)
class NormaJuridica(models.Model):
ESFERA_FEDERACAO_CHOICES, ESTADUAL, FEDERAL, MUNICIPAL = make_choices(
'E', _('Estadual'),
'F', _('Federal'),
'M', _('Municipal'),
)
texto_integral = models.FileField(
blank=True,
null=True,
upload_to=texto_upload_path,
verbose_name=_('Texto Integral'))
tipo = models.ForeignKey(TipoNormaJuridica, verbose_name=_('Tipo'))
materia = models.ForeignKey(MateriaLegislativa, blank=True, null=True)
numero = models.PositiveIntegerField(verbose_name=_('Número'))

21
norma/views.py

@ -1,7 +1,6 @@
from datetime import datetime
from re import sub
import sapl
from crispy_forms.helper import FormHelper
from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit
from django import forms
@ -12,9 +11,11 @@ from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormMixin
from vanilla import GenericView
import sapl
from materia.models import MateriaLegislativa, TipoMateriaLegislativa
from sapl.crud import build_crud
from vanilla import GenericView
from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica,
TipoNormaJuridica)
@ -130,7 +131,8 @@ class NormaJuridicaForm(ModelForm):
'pagina_fim_publicacao',
'ementa',
'indexacao',
'observacao']
'observacao',
'texto_integral']
def __init__(self, *args, **kwargs):
@ -156,19 +158,22 @@ class NormaJuridicaForm(ModelForm):
('pagina_fim_publicacao', 3)])
row5 = sapl.layout.to_row(
[('ementa', 12)])
[('texto_integral', 12)])
row6 = sapl.layout.to_row(
[('indexacao', 12)])
[('ementa', 12)])
row7 = sapl.layout.to_row(
[('indexacao', 12)])
row8 = sapl.layout.to_row(
[('observacao', 12)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset('Cadastro de Norma Jurídica',
Fieldset('Identificação Básica',
row1, row2, row3, row4, row5, row6, row7),
row1, row2, row3, row4, row5, row6, row7, row8),
ButtonHolder(
Submit('submit', 'Salvar',
css_class='button primary'))
@ -188,7 +193,6 @@ class NormaIncluirView(FormMixin, GenericView):
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = NormaJuridicaForm(request.POST or None)
if form.is_valid():
norma = form.save(commit=False)
@ -216,6 +220,9 @@ class NormaIncluirView(FormMixin, GenericView):
norma.observacao = sub(
' ', ' ', strip_tags(form.cleaned_data['observacao']))
if 'texto_integral' in request.FILES:
norma.texto_integral = request.FILES['texto_integral']
norma.ementa = sub(
' ', ' ', strip_tags(form.cleaned_data['ementa']))
norma.timestamp = datetime.now()

1
parlamentares/urls.py

@ -1,4 +1,5 @@
from django.conf.urls import include, url
from parlamentares.views import (MesaDiretoraView, ParlamentaresCadastroView,
ParlamentaresEditarView, ParlamentaresView,
cargo_mesa_crud, coligacao_crud,

5
parlamentares/views.py

@ -1,6 +1,5 @@
from re import sub
import sapl
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit
from django import forms
@ -10,9 +9,11 @@ from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormMixin
from sapl.crud import build_crud
from vanilla import GenericView
import sapl
from sapl.crud import build_crud
from .models import (CargoMesa, Coligacao, ComposicaoMesa, Dependente,
Filiacao, Legislatura, Mandato, NivelInstrucao,
Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar,

7
templates/norma/normajuridica_incluir.html

@ -3,9 +3,6 @@
{% load crispy_forms_tags %}
{% block detail_content %}
<form method="POST">
{% csrf_token %}
{% if error %} <h5 align="center"><font color="#FF0000">{{ error }}</font></h5> {% endif %}
{% crispy form %}
</form>
{% if error %} <h5 align="center"><font color="#FF0000">{{ error }}</font></h5> {% endif %}
{% crispy form %}
{% endblock %}
Loading…
Cancel
Save