diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index 0246ec320..4fd8c8579 100644 --- a/sapl/norma/forms.py +++ b/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 @@ -208,8 +190,8 @@ class NormaJuridicaForm(ModelForm): return texto_integral def save(self, commit=False): - norma = super(NormaJuridicaForm, self).save(commit) + norma = self.instance norma.timestamp = datetime.now() norma.materia = self.cleaned_data['materia'] - norma.save() + norma = super(NormaJuridicaForm, self).save(commit=True) return norma diff --git a/sapl/norma/migrations/0020_auto_20161028_1335.py b/sapl/norma/migrations/0020_auto_20161028_1335.py new file mode 100644 index 000000000..4391c8340 --- /dev/null +++ b/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', + ), + ] diff --git a/sapl/norma/migrations/0021_auto_20161028_1335.py b/sapl/norma/migrations/0021_auto_20161028_1335.py new file mode 100644 index 000000000..bbadc60d2 --- /dev/null +++ b/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'), + ), + ] diff --git a/sapl/norma/models.py b/sapl/norma/models.py index a9fa72780..debbdadc9 100644 --- a/sapl/norma/models.py +++ b/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) diff --git a/sapl/norma/urls.py b/sapl/norma/urls.py index f911c917f..a8d8c59d7 100644 --- a/sapl/norma/urls.py +++ b/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[0-9]+)/ta$', NormaTaView.as_view(), name='norma_ta'), diff --git a/sapl/norma/views.py b/sapl/norma/views.py index d0b13d117..1cddc0ca9 100644 --- a/sapl/norma/views.py +++ b/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, '') @@ -52,23 +52,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' diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index 570af1aa2..ccc056aca 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -127,7 +127,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 diff --git a/sapl/templates/norma/layouts.yaml b/sapl/templates/norma/layouts.yaml index f52d65102..99e14640c 100644 --- a/sapl/templates/norma/layouts.yaml +++ b/sapl/templates/norma/layouts.yaml @@ -34,6 +34,7 @@ NormaJuridicaCreate: - ementa - indexacao - observacao + - assuntos LegislacaoCitada: {% trans 'Legislação Citada' %}: diff --git a/sapl/templates/norma/subnav.yaml b/sapl/templates/norma/subnav.yaml index 465585e41..be3cf3c0a 100644 --- a/sapl/templates/norma/subnav.yaml +++ b/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