diff --git a/compilacao/migrations/0030_auto_20151203_1117.py b/compilacao/migrations/0030_auto_20151203_1117.py new file mode 100644 index 000000000..4daa1e950 --- /dev/null +++ b/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='+'), + ), + ] diff --git a/norma/migrations/0008_normajuridica_texto_integral.py b/norma/migrations/0008_normajuridica_texto_integral.py new file mode 100644 index 000000000..9f44184ad --- /dev/null +++ b/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), + ), + ] diff --git a/norma/models.py b/norma/models.py index d718c3c0d..66aefee18 100644 --- a/norma/models.py +++ b/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')) diff --git a/norma/views.py b/norma/views.py index c8546c4b8..ea6225f55 100644 --- a/norma/views.py +++ b/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() diff --git a/parlamentares/urls.py b/parlamentares/urls.py index 91f8a87f9..5b1b2f98e 100644 --- a/parlamentares/urls.py +++ b/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, diff --git a/parlamentares/views.py b/parlamentares/views.py index 2794e0d39..5c97e0456 100644 --- a/parlamentares/views.py +++ b/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, diff --git a/templates/norma/normajuridica_incluir.html b/templates/norma/normajuridica_incluir.html index cef528f57..15a058275 100644 --- a/templates/norma/normajuridica_incluir.html +++ b/templates/norma/normajuridica_incluir.html @@ -3,9 +3,6 @@ {% load crispy_forms_tags %} {% block detail_content %} -
- {% csrf_token %} - {% if error %}
{{ error }}
{% endif %} - {% crispy form %} -
+ {% if error %}
{{ error }}
{% endif %} + {% crispy form %} {% endblock %} \ No newline at end of file