From 926659c0f06823a046ce1db865caf2c3bec5d90e Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Fri, 28 Oct 2016 13:43:10 -0200 Subject: [PATCH] =?UTF-8?q?Add=20v=C3=ADnculo=20com=20assunto=20de=20norma?= =?UTF-8?q?=20na=20edi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/norma/forms.py | 28 +++---------- .../migrations/0020_auto_20161028_1335.py | 39 +++++++++++++++++++ .../migrations/0021_auto_20161028_1335.py | 24 ++++++++++++ sapl/norma/models.py | 20 +--------- sapl/norma/urls.py | 5 +-- sapl/norma/views.py | 21 +--------- sapl/rules/map_rules.py | 1 - sapl/templates/norma/layouts.yaml | 1 + sapl/templates/norma/subnav.yaml | 2 - 9 files changed, 75 insertions(+), 66 deletions(-) create mode 100644 sapl/norma/migrations/0020_auto_20161028_1335.py create mode 100644 sapl/norma/migrations/0021_auto_20161028_1335.py diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index a767c37fa..a2410f9ce 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 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 283c43bb8..b76d6b517 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, '') @@ -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' diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index 8f9441e62..ab3ceb846 100644 --- a/sapl/rules/map_rules.py +++ b/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 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