Browse Source

Add vínculo com assunto de norma na edição

pull/781/head
LeandroRoberto 8 years ago
parent
commit
926659c0f0
  1. 28
      sapl/norma/forms.py
  2. 39
      sapl/norma/migrations/0020_auto_20161028_1335.py
  3. 24
      sapl/norma/migrations/0021_auto_20161028_1335.py
  4. 20
      sapl/norma/models.py
  5. 5
      sapl/norma/urls.py
  6. 21
      sapl/norma/views.py
  7. 1
      sapl/rules/map_rules.py
  8. 1
      sapl/templates/norma/layouts.yaml
  9. 2
      sapl/templates/norma/subnav.yaml

28
sapl/norma/forms.py

@ -4,7 +4,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Layout
from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.forms import ModelForm
from django.forms import ModelForm, widgets
from django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row
@ -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 AssuntoNorma, AssuntoNormaRelationship, NormaJuridica
from .models import AssuntoNorma, NormaJuridica
def get_esferas():
@ -30,26 +30,6 @@ 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):
@ -177,7 +157,9 @@ class NormaJuridicaForm(ModelForm):
'ementa',
'indexacao',
'observacao',
'texto_integral']
'texto_integral',
'assuntos']
widgets = {'assuntos': widgets.CheckboxSelectMultiple}
def clean(self):
cleaned_data = self.cleaned_data

39
sapl/norma/migrations/0020_auto_20161028_1335.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-28 13:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('norma', '0019_auto_20161028_0232'),
]
operations = [
migrations.AlterUniqueTogether(
name='assuntonormarelationship',
unique_together=set([]),
),
migrations.RemoveField(
model_name='assuntonormarelationship',
name='assunto',
),
migrations.RemoveField(
model_name='assuntonormarelationship',
name='norma',
),
migrations.RemoveField(
model_name='normajuridica',
name='assuntos',
),
migrations.AddField(
model_name='normajuridica',
name='assuntos',
field=models.TextField(blank=True, null=True),
),
migrations.DeleteModel(
name='AssuntoNormaRelationship',
),
]

24
sapl/norma/migrations/0021_auto_20161028_1335.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-28 13:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('norma', '0020_auto_20161028_1335'),
]
operations = [
migrations.RemoveField(
model_name='normajuridica',
name='assuntos',
),
migrations.AddField(
model_name='normajuridica',
name='assuntos',
field=models.ManyToManyField(blank=True, to='norma.AssuntoNorma', verbose_name='Assuntos'),
),
]

20
sapl/norma/models.py

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

5
sapl/norma/urls.py

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

21
sapl/norma/views.py

@ -11,8 +11,8 @@ from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
MasterDetailCrud, make_pagination)
from sapl.norma.forms import NormaJuridicaForm
from .forms import AssuntoNormaRelationshipForm, NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, AssuntoNormaRelationship, NormaJuridica,
from .forms import NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, NormaJuridica,
TipoNormaJuridica)
# LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '')
@ -41,23 +41,6 @@ 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'

1
sapl/rules/map_rules.py

@ -86,7 +86,6 @@ rules_group_norma = {
'group': SAPL_GROUP_NORMA,
'rules': [
(norma.NormaJuridica, __base__),
(norma.AssuntoNormaRelationship, __base__),
(norma.VinculoNormaJuridica, __base__),
# Publicacao está com permissão apenas para norma e não para matéria

1
sapl/templates/norma/layouts.yaml

@ -34,6 +34,7 @@ NormaJuridicaCreate:
- ementa
- indexacao
- observacao
- assuntos
LegislacaoCitada:
{% trans 'Legislação Citada' %}:

2
sapl/templates/norma/subnav.yaml

@ -2,8 +2,6 @@
- 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

Loading…
Cancel
Save