Browse Source

Merge pull request #781 from interlegis/Assunto-Norma-3

Add assunto-norma no form de cadastro norma
pull/788/head
Leandro Roberto da Silva 8 years ago
committed by GitHub
parent
commit
50f83d5fb7
  1. 32
      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

32
sapl/norma/forms.py

@ -4,7 +4,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Layout from crispy_forms.layout import Fieldset, Layout
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError 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 django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row 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.settings import MAX_DOC_UPLOAD_SIZE
from sapl.utils import RANGE_ANOS from sapl.utils import RANGE_ANOS
from .models import AssuntoNorma, AssuntoNormaRelationship, NormaJuridica from .models import AssuntoNorma, NormaJuridica
def get_esferas(): def get_esferas():
@ -30,26 +30,6 @@ ORDENACAO_CHOICES = [('', '---------'),
('data,tipo,ano,numero', _('Data/Tipo/Ano/Número'))] ('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) # TODO termos, pesquisa textual, assunto(M2M)
class NormaJuridicaPesquisaForm(ModelForm): class NormaJuridicaPesquisaForm(ModelForm):
@ -177,7 +157,9 @@ class NormaJuridicaForm(ModelForm):
'ementa', 'ementa',
'indexacao', 'indexacao',
'observacao', 'observacao',
'texto_integral'] 'texto_integral',
'assuntos']
widgets = {'assuntos': widgets.CheckboxSelectMultiple}
def clean(self): def clean(self):
cleaned_data = self.cleaned_data cleaned_data = self.cleaned_data
@ -208,8 +190,8 @@ class NormaJuridicaForm(ModelForm):
return texto_integral return texto_integral
def save(self, commit=False): def save(self, commit=False):
norma = super(NormaJuridicaForm, self).save(commit) norma = self.instance
norma.timestamp = datetime.now() norma.timestamp = datetime.now()
norma.materia = self.cleaned_data['materia'] norma.materia = self.cleaned_data['materia']
norma.save() norma = super(NormaJuridicaForm, self).save(commit=True)
return norma return norma

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) choices=YES_NO_CHOICES)
# XXX was a CharField (attention on migrate) # XXX was a CharField (attention on migrate)
assuntos = models.ManyToManyField( assuntos = models.ManyToManyField(
AssuntoNorma, AssuntoNorma, blank=True,
verbose_name=_('Assuntos'), verbose_name=_('Assuntos'))
through='AssuntoNormaRelationship')
data_vigencia = models.DateField(blank=True, null=True) data_vigencia = models.DateField(blank=True, null=True)
timestamp = models.DateTimeField() timestamp = models.DateTimeField()
@ -135,21 +134,6 @@ class NormaJuridica(models.Model):
update_fields=update_fields) 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): class LegislacaoCitada(models.Model):
materia = models.ForeignKey(MateriaLegislativa) materia = models.ForeignKey(MateriaLegislativa)
norma = models.ForeignKey(NormaJuridica) norma = models.ForeignKey(NormaJuridica)

5
sapl/norma/urls.py

@ -1,6 +1,6 @@
from django.conf.urls import include, url from django.conf.urls import include, url
from sapl.norma.views import (AssuntoNormaCrud, AssuntoNormaRelationshipCrud, from sapl.norma.views import (AssuntoNormaCrud,
NormaCrud, NormaPesquisaView, NormaTaView, NormaCrud, NormaPesquisaView, NormaTaView,
PesquisaNormaListView, TipoNormaCrud) PesquisaNormaListView, TipoNormaCrud)
@ -10,8 +10,7 @@ app_name = AppConfig.name
urlpatterns = [ urlpatterns = [
url(r'^norma/', include(NormaCrud.get_urls() + url(r'^norma/', include(NormaCrud.get_urls())),
AssuntoNormaRelationshipCrud.get_urls())),
# Integração com Compilação # Integração com Compilação
url(r'^norma/(?P<pk>[0-9]+)/ta$', NormaTaView.as_view(), name='norma_ta'), 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) MasterDetailCrud, make_pagination)
from sapl.norma.forms import NormaJuridicaForm from sapl.norma.forms import NormaJuridicaForm
from .forms import AssuntoNormaRelationshipForm, NormaJuridicaPesquisaForm from .forms import NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, AssuntoNormaRelationship, NormaJuridica, from .models import (AssuntoNorma, NormaJuridica,
TipoNormaJuridica) TipoNormaJuridica)
# LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') # LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '')
@ -52,23 +52,6 @@ class NormaTaView(IntegracaoTaView):
return self.get_redirect_deactivated() 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): class NormaCrud(Crud):
model = NormaJuridica model = NormaJuridica
help_path = 'norma_juridica' help_path = 'norma_juridica'

1
sapl/rules/map_rules.py

@ -127,7 +127,6 @@ rules_group_norma = {
'group': SAPL_GROUP_NORMA, 'group': SAPL_GROUP_NORMA,
'rules': [ 'rules': [
(norma.NormaJuridica, __base__), (norma.NormaJuridica, __base__),
(norma.AssuntoNormaRelationship, __base__),
(norma.VinculoNormaJuridica, __base__), (norma.VinculoNormaJuridica, __base__),
# Publicacao está com permissão apenas para norma e não para matéria # 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 - ementa
- indexacao - indexacao
- observacao - observacao
- assuntos
LegislacaoCitada: LegislacaoCitada:
{% trans 'Legislação Citada' %}: {% trans 'Legislação Citada' %}:

2
sapl/templates/norma/subnav.yaml

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

Loading…
Cancel
Save