Browse Source

Add inclusão NormaJuridica

pull/11/merge
Edward Ribeiro 9 years ago
parent
commit
8d93e7bd01
  1. 14
      norma/urls.py
  2. 166
      norma/views.py
  3. 5
      templates/materia/formulario_simplificado.html
  4. 26
      templates/norma/normajuridica_incluir.html

14
norma/urls.py

@ -2,15 +2,15 @@ from django.conf.urls import include, url
from norma.views import (assunto_norma_crud,
norma_temporario_para_compilacao_crud,
tipo_norma_crud)
tipo_norma_crud, NormaIncluirView)
norma_url_patterns = norma_temporario_para_compilacao_crud.urlpatterns
urlpatterns = [
url(r'^norma/', include(norma_url_patterns,
norma_temporario_para_compilacao_crud.namespace,
norma_temporario_para_compilacao_crud.namespace)),
url(r'^sistema/norma/tipo/', include(tipo_norma_crud.urls)),
url(r'^sistema/norma/assunto/', include(assunto_norma_crud.urls)),
# url(r'^norma/', include(norma_url_patterns,
# norma_temporario_para_compilacao_crud.namespace,
# norma_temporario_para_compilacao_crud.namespace)),
# url(r'^sistema/norma/tipo/', include(tipo_norma_crud.urls)),
# url(r'^sistema/norma/assunto/', include(assunto_norma_crud.urls)),
url(r'^norma/incluir', NormaIncluirView.as_view(), name='norma-incluir'),
]

166
norma/views.py

@ -2,9 +2,21 @@ from django.utils.translation import ugettext_lazy as _
from sapl.crud import build_crud
from django import forms
from django.utils.safestring import mark_safe
from django.core.urlresolvers import reverse
from datetime import datetime
from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica,
TipoNormaJuridica)
from materia.models import TipoMateriaLegislativa
from django.views.generic.edit import FormMixin
from vanilla import GenericView
assunto_norma_crud = build_crud(
AssuntoNorma, 'assunto_norma_juridica', [
@ -67,3 +79,157 @@ legislacao_citada_crud = build_crud(
[('capitulo', 3), ('secao', 3), ('subsecao', 3), ('artigo', 3)],
[('paragrafo', 3), ('inciso', 3), ('alinea', 3), ('item', 3)]],
])
def get_tipos_norma():
return [('', 'Selecione')] \
+ [(n.id, n.descricao)
for n in TipoNormaJuridica.objects.all()]
def get_esferas():
return [('E', 'Estadual'),
('F', 'Federal'),
('M', 'Municipal')]
def get_tipos_materia():
return [('', 'Selecione')] \
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoMateriaLegislativa.objects.all()]
class HorizontalRadioRenderer(forms.RadioSelect.renderer):
def render(self):
return mark_safe(u' '.join([u'%s ' % w for w in self]))
class NormaJuridicaForm(forms.Form):
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',
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',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
numero_materia = forms.CharField(label='Número', required=False)
ano_materia = forms.CharField(label='Ano', required=False)
data_publicacao = forms.DateField(label='Data Publicação',
required=False,
input_formats=['%d/%m/%Y'],
widget=forms.TextInput(
attrs={'class': 'dateinput'}))
veiculo_publicacao = forms.CharField(label='Veiculo Publicação', required=False)
pg_inicio = forms.CharField(label='Pg. Início', required=False)
pg_fim = forms.CharField(label='Pg. Fim', required=False)
# texto = form.FileUpload(label='Texto', required=False) # TODO: implement file upload
data_fim_vigencia = forms.DateField(label='Data Fim Vigência',
required=False,
input_formats=['%d/%m/%Y'],
widget=forms.TextInput(
attrs={'class': 'dateinput'}))
ementa = forms.CharField(label='Ementa', required=True, widget=forms.Textarea)
indexacao = forms.CharField(label='Indexação', required=False, widget=forms.Textarea)
observacao = forms.CharField(label='Observação', required=False, widget=forms.Textarea)
class NormaIncluirView(FormMixin, GenericView):
template_name = "norma/normajuridica_incluir.html"
def get_success_url(self):
return reverse('norma-incluir')
def get(self, request, *args, **kwargs):
form = NormaJuridicaForm()
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = NormaJuridicaForm(request.POST or None)
if form.is_valid():
norma = NormaJuridica()
norma.tipo = TipoNormaJuridica.objects.get(id=form.cleaned_data['tipo'])
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']
norma.timestamp = datetime.now()
norma.save()
return self.render_to_response({'form': form})
else:
return self.form_invalid(form)

5
templates/materia/formulario_simplificado.html

@ -21,6 +21,11 @@
endDate: '31/12/2100',
todayBtn: true
});
/* $('input[type="radio"]').change(function() {
alert('ok');
};*/
});
</script>
{% endblock %}

26
templates/norma/normajuridica_incluir.html

@ -0,0 +1,26 @@
{% extends "materia/materia_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
<form method="POST">
{% csrf_token %}
{{ form.as_table }}
</br>
<input type="submit" name="salvar" value="Salvar" class="button primary" />
</form>
{% endblock %}
{% block foot_js %}
<script type="text/javascript">
$(function () {
$('.dateinput').fdatepicker({
// TODO localize
format: 'dd/mm/yyyy',
language: 'pt',
endDate: '31/12/2100',
todayBtn: true
});
});
</script>
{% endblock %}
Loading…
Cancel
Save