Browse Source

Merge pull request #772 from interlegis/AssuntoNorma-2

Adiciona MasterDetail para adicionar assunto a norma
pull/781/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
committed by GitHub
parent
commit
b97ad91197
  1. 22
      sapl/norma/forms.py
  2. 23
      sapl/norma/migrations/0016_auto_20161027_1419.py
  3. 20
      sapl/norma/migrations/0017_auto_20161027_1432.py
  4. 26
      sapl/norma/migrations/0018_auto_20161027_1434.py
  5. 12
      sapl/norma/models.py
  6. 9
      sapl/norma/urls.py
  7. 25
      sapl/norma/views.py
  8. 6
      sapl/templates/norma/layouts.yaml
  9. 4
      sapl/templates/norma/subnav.yaml

22
sapl/norma/forms.py

@ -12,7 +12,7 @@ from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa
from sapl.settings import MAX_DOC_UPLOAD_SIZE
from sapl.utils import RANGE_ANOS
from .models import NormaJuridica
from .models import AssuntoNormaRelationship, NormaJuridica
def get_esferas():
@ -30,6 +30,26 @@ ORDENACAO_CHOICES = [('', '---------'),
('data,tipo,ano,numero', _('Data/Tipo/Ano/Número'))]
class AssuntoNormaRelationshipForm(ModelForm):
class Meta:
model = AssuntoNormaRelationship
fields = ['assunto']
def save(self, commit=False):
norma_assunto = super(AssuntoNormaRelationshipForm, self).save(commit)
try:
AssuntoNormaRelationship.objects.get(
norma=norma_assunto.norma,
assunto=norma_assunto.assunto)
except ObjectDoesNotExist:
norma_assunto.save()
else:
raise forms.ValidationError(
"Esse Assunto já está anexado nesta Norma Jurídica.")
return norma_assunto
# TODO termos, pesquisa textual, assunto(M2M)
class NormaJuridicaPesquisaForm(ModelForm):

23
sapl/norma/migrations/0016_auto_20161027_1419.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-27 14:19
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('norma', '0015_auto_20160929_1635'),
]
operations = [
migrations.AlterModelOptions(
name='assuntonormarelationship',
options={'verbose_name': 'Assunto', 'verbose_name_plural': 'Assuntos'},
),
migrations.AlterUniqueTogether(
name='assuntonormarelationship',
unique_together=set([]),
),
]

20
sapl/norma/migrations/0017_auto_20161027_1432.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-27 14:32
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('norma', '0016_auto_20161027_1419'),
]
operations = [
migrations.AlterField(
model_name='normajuridica',
name='assuntos',
field=models.ManyToManyField(through='norma.AssuntoNormaRelationship', to='norma.AssuntoNorma', verbose_name='Assuntos'),
),
]

26
sapl/norma/migrations/0018_auto_20161027_1434.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-27 14:34
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('norma', '0017_auto_20161027_1432'),
]
operations = [
migrations.AlterField(
model_name='assuntonormarelationship',
name='assunto',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='norma.AssuntoNorma', verbose_name='Assunto'),
),
migrations.AlterField(
model_name='assuntonormarelationship',
name='norma',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='norma.NormaJuridica', verbose_name='Norma'),
),
]

12
sapl/norma/models.py

@ -98,6 +98,7 @@ class NormaJuridica(models.Model):
# XXX was a CharField (attention on migrate)
assuntos = models.ManyToManyField(
AssuntoNorma,
verbose_name=_('Assuntos'),
through='AssuntoNormaRelationship')
data_vigencia = models.DateField(blank=True, null=True)
timestamp = models.DateTimeField()
@ -135,14 +136,21 @@ class NormaJuridica(models.Model):
class AssuntoNormaRelationship(models.Model):
assunto = models.ForeignKey(AssuntoNorma)
norma = models.ForeignKey(NormaJuridica)
assunto = models.ForeignKey(AssuntoNorma, verbose_name=_('Assunto'))
norma = models.ForeignKey(NormaJuridica, verbose_name=_('Norma'))
class Meta:
unique_together = (
('assunto', 'norma'),
)
class Meta:
verbose_name = _('Assunto')
verbose_name_plural = _('Assuntos')
def __str__(self):
return self.assunto.assunto
class LegislacaoCitada(models.Model):
materia = models.ForeignKey(MateriaLegislativa)

9
sapl/norma/urls.py

@ -1,8 +1,8 @@
from django.conf.urls import include, url
from sapl.norma.views import (AssuntoNormaCrud, NormaCrud, NormaPesquisaView,
NormaTaView, PesquisaNormaListView,
TipoNormaCrud)
from sapl.norma.views import (AssuntoNormaCrud, AssuntoNormaRelationshipCrud,
NormaCrud, NormaPesquisaView, NormaTaView,
PesquisaNormaListView, TipoNormaCrud)
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() +
AssuntoNormaRelationshipCrud.get_urls())),
# Integração com Compilação
url(r'^norma/(?P<pk>[0-9]+)/ta$', NormaTaView.as_view(), name='norma_ta'),

25
sapl/norma/views.py

@ -7,11 +7,13 @@ from django.views.generic.base import RedirectView
from sapl.base.models import AppConfig
from sapl.compilacao.views import IntegracaoTaView
from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, make_pagination
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
MasterDetailCrud, make_pagination)
from sapl.norma.forms import NormaJuridicaForm
from .forms import NormaJuridicaPesquisaForm
from .models import AssuntoNorma, NormaJuridica, TipoNormaJuridica
from .forms import AssuntoNormaRelationshipForm, NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, AssuntoNormaRelationship, NormaJuridica,
TipoNormaJuridica)
# LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '')
AssuntoNormaCrud = CrudAux.build(AssuntoNorma, 'assunto_norma_juridica',
@ -39,6 +41,23 @@ class NormaTaView(IntegracaoTaView):
return self.get_redirect_deactivated()
class AssuntoNormaRelationshipCrud(MasterDetailCrud):
model = AssuntoNormaRelationship
parent_field = 'norma'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['assunto']
ordering = 'assunto'
class CreateView(MasterDetailCrud.CreateView):
form_class = AssuntoNormaRelationshipForm
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AssuntoNormaRelationshipForm
class NormaCrud(Crud):
model = NormaJuridica
help_path = 'norma_juridica'

6
sapl/templates/norma/layouts.yaml

@ -1,4 +1,9 @@
{% load i18n %}
AssuntoNormaRelationship:
{% trans 'Assunto Norma Jurídica' %}:
- assunto
AssuntoNorma:
{% trans 'Assunto Norma Jurídica' %}:
- assunto descricao
@ -17,6 +22,7 @@ NormaJuridica:
- ementa
- indexacao
- observacao
- assuntos
NormaJuridicaCreate:
{% trans 'Identificação Básica' %}:

4
sapl/templates/norma/subnav.yaml

@ -1,11 +1,15 @@
{% load i18n common_tags%}
- title: {% trans 'Início' %}
url: normajuridica_detail
- title: {% trans 'Assuntos' %}
url: assuntonormarelationship_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
# e a view NormaTaView(IntegracaoTaView) em views.py
# Em nada mais a integração interfere em NormaJuridica
{% if 'texto_articulado_norma'|get_config_attr %}
- title: {% trans 'Texto' %}
url: norma_ta

Loading…
Cancel
Save