Browse Source

Cria vinculo de normas

pull/814/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
b1f4b7da13
  1. 8
      sapl/norma/forms.py
  2. 26
      sapl/norma/migrations/0027_auto_20161123_1538.py
  3. 10
      sapl/norma/models.py
  4. 10
      sapl/norma/urls.py
  5. 53
      sapl/norma/views.py
  6. 11
      sapl/templates/norma/layouts.yaml
  7. 27
      sapl/templates/norma/normarelacionada_form.html
  8. 2
      sapl/templates/norma/subnav.yaml

8
sapl/norma/forms.py

@ -159,12 +159,13 @@ class NormaRelacionadaForm(ModelForm):
)
numero = forms.CharField(label='Número', required=True)
ano = forms.CharField(label='Ano', required=True)
ementa = forms.CharField(widget=forms.Textarea)
ementa = forms.CharField(
required=False,
widget=forms.Textarea(attrs={'disabled': 'disabled'}))
class Meta:
model = NormaRelacionada
fields = ['tipo', 'numero', 'ano', 'ementa', 'tipo_vinculo']
widgets = {'ementa': forms.Select(attrs={'disabled': 'disabled'})}
def __init__(self, *args, **kwargs):
super(NormaRelacionadaForm, self).__init__(*args, **kwargs)
@ -175,10 +176,9 @@ class NormaRelacionadaForm(ModelForm):
cleaned_data = self.cleaned_data
try:
norma_relacionada = MateriaLegislativa.objects.get(
norma_relacionada = NormaJuridica.objects.get(
numero=cleaned_data['numero'],
ano=cleaned_data['ano'],
ementa=cleaned_data['ementa'],
tipo=cleaned_data['tipo'])
except ObjectDoesNotExist:
msg = _('A norma a ser relacionada não existe.')

26
sapl/norma/migrations/0027_auto_20161123_1538.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-11-23 15:38
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('norma', '0026_auto_20161123_1450'),
]
operations = [
migrations.AlterField(
model_name='normarelacionada',
name='norma_principal',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='norma_principal', to='norma.NormaJuridica', verbose_name='Norma Principal'),
),
migrations.AlterField(
model_name='normarelacionada',
name='norma_relacionada',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='norma_relacionada', to='norma.NormaJuridica', verbose_name='Norma Relacionada'),
),
]

10
sapl/norma/models.py

@ -186,11 +186,15 @@ class VinculoNormaJuridica(models.Model):
class NormaRelacionada(models.Model):
norma_principal = models.ForeignKey(
NormaJuridica, related_name='norma_principal')
NormaJuridica,
related_name='norma_principal',
verbose_name=_('Norma Principal'))
norma_relacionada = models.ForeignKey(
NormaJuridica, related_name='norma_relacionada')
NormaJuridica,
related_name='norma_relacionada',
verbose_name=_('Norma Relacionada'))
tipo_vinculo = models.ForeignKey(
VinculoNormaJuridica, verbose_name='Tipo de Vínculo')
VinculoNormaJuridica, verbose_name=_('Tipo de Vínculo'))
class Meta:
verbose_name = _('Norma Relacionada')

10
sapl/norma/urls.py

@ -1,8 +1,8 @@
from django.conf.urls import include, url
from sapl.norma.views import (AssuntoNormaCrud, NormaCrud, NormaPesquisaView,
NormaTaView, TipoNormaCrud,
VinculoNormaJuridicaCrud)
NormaRelacionadaCrud, NormaTaView, TipoNormaCrud,
VinculoNormaJuridicaCrud, recuperar_norma)
from .apps import AppConfig
@ -10,7 +10,8 @@ app_name = AppConfig.name
urlpatterns = [
url(r'^norma/', include(NormaCrud.get_urls())),
url(r'^norma/', include(NormaCrud.get_urls() +
NormaRelacionadaCrud.get_urls())),
# Integração com Compilação
url(r'^norma/(?P<pk>[0-9]+)/ta$', NormaTaView.as_view(), name='norma_ta'),
@ -22,4 +23,7 @@ urlpatterns = [
url(r'^norma/pesquisar$',
NormaPesquisaView.as_view(), name='norma_pesquisa'),
url(r'^norma/recuperar-norma/', recuperar_norma),
]

53
sapl/norma/views.py

@ -1,6 +1,7 @@
from datetime import datetime
from django.core.urlresolvers import reverse
from django.http import JsonResponse
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView, ListView
@ -12,9 +13,9 @@ from sapl.compilacao.views import IntegracaoTaView
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
MasterDetailCrud, make_pagination)
from .forms import NormaFilterSet, NormaJuridicaForm
from .models import (AssuntoNorma, NormaJuridica, TipoNormaJuridica,
VinculoNormaJuridica)
from .forms import NormaFilterSet, NormaJuridicaForm, NormaRelacionadaForm
from .models import (AssuntoNorma, NormaJuridica, NormaRelacionada,
TipoNormaJuridica, VinculoNormaJuridica)
# LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '')
AssuntoNormaCrud = CrudAux.build(AssuntoNorma, 'assunto_norma_juridica',
@ -28,6 +29,35 @@ VinculoNormaJuridicaCrud = CrudAux.build(
VinculoNormaJuridica, '', list_field_names=['sigla', 'descricao'])
class NormaRelacionadaCrud(MasterDetailCrud):
model = NormaRelacionada
parent_field = 'norma_principal'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['norma_relacionada']
class CreateView(MasterDetailCrud.CreateView):
form_class = NormaRelacionadaForm
class UpdateView(MasterDetailCrud.UpdateView):
form_class = NormaRelacionadaForm
def get_initial(self):
self.initial['tipo'] = self.object.norma_relacionada.tipo.id
self.initial['numero'] = self.object.norma_relacionada.numero
self.initial['ano'] = self.object.norma_relacionada.ano
self.initial['ementa'] = self.object.norma_relacionada.ementa
return self.initial
class DetailView(MasterDetailCrud.DetailView):
@property
def layout_key(self):
return 'NormaRelacionadaDetail'
class NormaPesquisaView(FilterView):
model = NormaJuridica
filterset_class = NormaFilterSet
@ -132,3 +162,20 @@ class NormaCrud(Crud):
self.initial['ano_materia'] = norma.materia.ano
self.initial['numero_materia'] = norma.materia.numero
return self.initial.copy()
def recuperar_norma(request):
tipo = TipoNormaJuridica.objects.get(pk=request.GET['tipo'])
numero = request.GET['numero']
ano = request.GET['ano']
try:
norma = NormaJuridica.objects.get(tipo=tipo,
ano=ano,
numero=numero)
response = JsonResponse({'ementa': norma.ementa,
'id': norma.id})
except ObjectDoesNotExist:
response = JsonResponse({'ementa': '', 'id': 0})
return response

11
sapl/templates/norma/layouts.yaml

@ -53,3 +53,14 @@ LegislacaoCitadaDetail:
VinculoNormaJuridica:
{% trans 'Tipo de Vínculo entre Normas Jurídicas' %}:
- sigla:2 descricao
NormaRelacionada:
{% trans 'Norma Relacionada' %}:
- tipo numero ano
- tipo_vinculo
- ementa
NormaRelacionadaDetail:
{% trans 'Norma Relacionada' %}:
- norma_relacionada
- tipo_vinculo

27
sapl/templates/norma/normarelacionada_form.html

@ -0,0 +1,27 @@
{% extends "crud/form.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load common_tags %}
{% block extra_js %}
<script language="Javascript">
function recuperar_norma() {
var tipo = $("#id_tipo").val()
var numero = $("#id_numero").val()
var ano = $("#id_ano").val()
if (tipo && numero && ano) {
$.get("/norma/recuperar-norma",{tipo: tipo,
numero: numero,
ano: ano},
function(data, status) {
$("#id_ementa").val(data.ementa);
});
}
}
var fields = ["#id_tipo", "#id_numero", "#id_ano"]
for (i = 0; i < fields.length; i++) {
$(fields[i]).change(recuperar_norma);
}
</script>
{% endblock %}

2
sapl/templates/norma/subnav.yaml

@ -2,6 +2,8 @@
- title: {% trans 'Início' %}
url: normajuridica_detail
- title: {% trans 'Normas Relacionadas' %}
url: normarelacionada_list
# Opção adicionada para chamar o TextoArticulado da norma.
# para integração foram necessárias apenas criar a url norma_ta em urls.py

Loading…
Cancel
Save