Browse Source

Add register NormaJuridica

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
82b70e628b
  1. 207
      norma/views.py
  2. 4
      templates/norma/normajuridica_detail.html
  3. 7
      templates/norma/normajuridica_incluir.html

207
norma/views.py

@ -1,14 +1,20 @@
from datetime import datetime 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 from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.forms import ModelForm
from django.utils.html import strip_tags
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 materia.models import MateriaLegislativa, TipoMateriaLegislativa
from materia.models import TipoMateriaLegislativa
from sapl.crud import build_crud from sapl.crud import build_crud
from vanilla import GenericView
from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica,
TipoNormaJuridica) TipoNormaJuridica)
@ -47,12 +53,6 @@ norma_crud = build_crud(
[('ementa', 12)], [('ementa', 12)],
[('indexacao', 12)], [('indexacao', 12)],
[('observacao', 12)]], [('observacao', 12)]],
[_('Assuntos (Classificação) [+]'),
[('assunto_norma_FIXME', 12)],
[('assunto_norma_FIXME', 12)],
[('assunto_norma_FIXME', 12)]],
]) ])
norma_temporario_crud = build_crud( norma_temporario_crud = build_crud(
@ -101,37 +101,9 @@ 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 NormaJuridicaForm(forms.Form): class NormaJuridicaForm(ModelForm):
tipo = forms.ChoiceField(required=True,
label='Tipo',
choices=get_tipos_norma(),
widget=forms.Select(
attrs={'class': 'selector'}))
numero = forms.CharField(label='Número', required=True)
ano = forms.CharField(label='Ano', required=True)
data = forms.DateField(label='Data', tipo_materia = forms.ChoiceField(required=False,
required=True,
input_formats=['%d/%m/%Y'],
widget=forms.TextInput(
attrs={'class': 'dateinput'}))
esfera = forms.ChoiceField(required=True,
label='Tipo',
choices=get_esferas(),
widget=forms.Select(
attrs={'class': 'selector'}))
complementar = forms.ChoiceField(required=False,
choices=[('1', 'Sim'), ('0', 'Não')],
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer),
label='Complementar')
materia = forms.ChoiceField(required=False,
label='Materia Legislativa', label='Materia Legislativa',
choices=get_tipos_materia(), choices=get_tipos_materia(),
widget=forms.Select( widget=forms.Select(
@ -141,43 +113,75 @@ class NormaJuridicaForm(forms.Form):
ano_materia = forms.CharField(label='Ano', required=False) ano_materia = forms.CharField(label='Ano', required=False)
data_publicacao = forms.DateField(label='Data Publicação', class Meta:
required=False, model = NormaJuridica
input_formats=['%d/%m/%Y'], fields = ['tipo',
widget=forms.TextInput( 'numero',
attrs={'class': 'dateinput'})) 'ano',
'data',
veiculo_publicacao = forms.CharField( 'esfera_federacao',
label='Veiculo Publicação', required=False) 'complemento',
'tipo_materia',
pg_inicio = forms.CharField(label='Pg. Início', required=False) 'numero_materia',
'ano_materia',
pg_fim = forms.CharField(label='Pg. Fim', required=False) 'data_publicacao',
'veiculo_publicacao',
# texto = form.FileUpload(label='Texto', required=False) # TODO: implement 'pagina_inicio_publicacao',
# file upload 'pagina_fim_publicacao',
'ementa',
'indexacao',
'observacao']
def __init__(self, *args, **kwargs):
row1 = sapl.layout.to_row(
[('tipo', 4),
('numero', 4),
('ano', 4)])
row2 = sapl.layout.to_row(
[('data', 4),
('esfera_federacao', 4),
('complemento', 4)])
row3 = sapl.layout.to_row(
[('tipo_materia', 4),
('numero_materia', 4),
('ano_materia', 4)])
row4 = sapl.layout.to_row(
[('data_publicacao', 3),
('veiculo_publicacao', 3),
('pagina_inicio_publicacao', 3),
('pagina_fim_publicacao', 3)])
data_fim_vigencia = forms.DateField(label='Data Fim Vigência', row5 = sapl.layout.to_row(
required=False, [('ementa', 12)])
input_formats=['%d/%m/%Y'],
widget=forms.TextInput(
attrs={'class': 'dateinput'}))
ementa = forms.CharField( row6 = sapl.layout.to_row(
label='Ementa', required=True, widget=forms.Textarea) [('indexacao', 12)])
indexacao = forms.CharField( row7 = sapl.layout.to_row(
label='Indexação', required=False, widget=forms.Textarea) [('observacao', 12)])
observacao = forms.CharField( self.helper = FormHelper()
label='Observação', required=False, widget=forms.Textarea) self.helper.layout = Layout(
Fieldset('Cadastro de Norma Jurídica',
Fieldset('Identificação Básica',
row1, row2, row3, row4, row5, row6, row7),
ButtonHolder(
Submit('submit', 'Salvar',
css_class='button primary'))
)
)
super(NormaJuridicaForm, self).__init__(*args, **kwargs)
class NormaIncluirView(FormMixin, GenericView): class NormaIncluirView(FormMixin, GenericView):
template_name = "norma/normajuridica_incluir.html" template_name = "norma/normajuridica_incluir.html"
def get_success_url(self): def get_success_url(self):
return reverse('norma-incluir') return '/norma/'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
form = NormaJuridicaForm() form = NormaJuridicaForm()
@ -186,57 +190,36 @@ class NormaIncluirView(FormMixin, GenericView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = NormaJuridicaForm(request.POST or None) form = NormaJuridicaForm(request.POST or None)
if form.is_valid(): if form.is_valid():
norma = form.save(commit=False)
if form.cleaned_data['tipo_materia']:
tipo = TipoMateriaLegislativa.objects.get(
id=form.cleaned_data['tipo_materia'])
try:
materia = MateriaLegislativa.objects.get(
tipo=tipo,
numero=form.cleaned_data['numero'],
ano=form.cleaned_data['ano'])
except ObjectDoesNotExist:
return self.render_to_response(
{'form': form,
'error': 'Matéria adicionada não existe!'})
else:
norma.materia = materia
norma = NormaJuridica() if form.cleaned_data['indexacao']:
norma.tipo = TipoNormaJuridica.objects.get( norma.indexacao = sub(
id=form.cleaned_data['tipo']) ' ', ' ', strip_tags(form.cleaned_data['indexacao']))
norma.numero = form.cleaned_data['numero']
norma.ano = form.cleaned_data['ano']
norma.data = form.cleaned_data['data']
norma.esfera = form.cleaned_data['esfera']
norma.complementar = form.cleaned_data['complementar']
if form.cleaned_data['complementar']:
norma.complementar = TipoMateriaLegislativa.objects.get(
id=form.cleaned_data['complementar'])
if form.cleaned_data['materia']:
norma.materia = form.cleaned_data['materia']
if form.cleaned_data['numero_materia']:
norma.numero_materia = form.cleaned_data['numero_materia']
if form.cleaned_data['ano_materia']:
norma.ano_materia = form.cleaned_data['ano_materia']
if form.cleaned_data['data_publicacao']:
norma.data_publicacao = form.cleaned_data['data_publicacao']
if form.cleaned_data['veiculo_publicacao']:
norma.veiculo_publicacao = form.cleaned_data[
'veiculo_publicacao']
if form.cleaned_data['pg_inicio']:
norma.pg_inicio = form.cleaned_data['pg_inicio']
if form.cleaned_data['pg_fim']:
norma.pg_fim = form.cleaned_data['pg_fim']
if form.cleaned_data['data_fim_vigencia']:
norma.data_fim_vigencia = form.cleaned_data[
'data_fim_vigencia']
norma.ementa = form.cleaned_data['ementa']
norma.indexacao = form.cleaned_data['indexacao']
norma.observacao = form.cleaned_data['observacao'] if form.cleaned_data['observacao']:
norma.observacao = sub(
' ', ' ', strip_tags(form.cleaned_data['observacao']))
norma.ementa = sub(
' ', ' ', strip_tags(form.cleaned_data['ementa']))
norma.timestamp = datetime.now() norma.timestamp = datetime.now()
norma.save() norma.save()
return self.form_valid(form)
return self.render_to_response({'form': form})
else: else:
return self.form_invalid(form) return self.form_invalid(form)

4
templates/norma/normajuridica_detail.html

@ -1,9 +1,7 @@
{% extends "crud/detail.html" %} {% extends "crud/detail.html" %}
{% load i18n %} {% load i18n %}
{% block actions %} {% endblock %}
{% block sections_nav %} {% block sections_nav %}
<dl class="sub-nav left"> <dl class="sub-nav left">
<dd><a href="{% url 'normajuridica:detail' object.pk %}" class="button secondary">{% trans 'Início' %}</a></dd>
<dd><a href="{% url 'compilacao' object.pk %}" class="button secondary">{% trans 'Texto Integral' %}</a></dd>
</dl> </dl>
{% endblock sections_nav %} {% endblock sections_nav %}

7
templates/norma/normajuridica_incluir.html

@ -1,12 +1,11 @@
{% extends "materia/materialegislativa_detail.html" %} {% extends "norma/normajuridica_detail.html" %}
{% load i18n %} {% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block detail_content %} {% block detail_content %}
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
{{ form.as_table }} {% if error %} <h5 align="center"><font color="#FF0000">{{ error }}</font></h5> {% endif %}
</br> {% crispy form %}
<input type="submit" name="salvar" value="Salvar" class="button primary" />
</form> </form>
{% endblock %} {% endblock %}
Loading…
Cancel
Save