From 8c440b6228b697ffa10e179fef174efaa19539fb Mon Sep 17 00:00:00 2001 From: Leandro Roberto da Silva Date: Tue, 5 Dec 2017 13:02:24 -0200 Subject: [PATCH] =?UTF-8?q?limita=20edi=C3=A7=C3=A3o=20de=20tipoautor=20a?= =?UTF-8?q?=20tipos=20externos=20a=20modelagem=20do=20sapl=20(#1623)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/forms.py | 20 +--- .../migrations/0012_auto_20171205_0917.py | 20 ++++ sapl/base/models.py | 5 +- sapl/base/templatetags/base_tags.py | 9 ++ sapl/base/views.py | 24 ++++- sapl/static/styles/app.scss | 7 ++ sapl/templates/base/layouts.yaml | 2 +- sapl/templates/base/tipoautor_form.html | 20 ---- sapl/templates/base/tipoautor_list.html | 34 +++++++ sapl/templates/crud/list.html | 92 +++++++++---------- 10 files changed, 147 insertions(+), 86 deletions(-) create mode 100644 sapl/base/migrations/0012_auto_20171205_0917.py create mode 100644 sapl/base/templatetags/base_tags.py delete mode 100644 sapl/templates/base/tipoautor_form.html create mode 100644 sapl/templates/base/tipoautor_list.html diff --git a/sapl/base/forms.py b/sapl/base/forms.py index ffd49c735..d0bef23cd 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1,4 +1,3 @@ -import django_filters from crispy_forms.bootstrap import FieldWithButtons, InlineRadios, StrictButton from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Div, Field, Fieldset, Layout, Row @@ -12,8 +11,9 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.db import models, transaction from django.forms import ModelForm -from django.utils.translation import ugettext_lazy as _ from django.utils.translation import string_concat +from django.utils.translation import ugettext_lazy as _ +import django_filters from sapl.base.models import Autor, TipoAutor from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, @@ -28,6 +28,7 @@ from sapl.utils import (RANGE_ANOS, ChoiceWithoutValidationField, from .models import AppConfig, CasaLegislativa + ACTION_CREATE_USERS_AUTOR_CHOICE = [ ('A', _('Associar um usuário existente')), ('N', _('Autor sem Usuário de Acesso ao Sapl')), @@ -45,27 +46,14 @@ STATUS_USER_CHOICE = [ class TipoAutorForm(ModelForm): - content_type = forms.ModelChoiceField( - queryset=ContentType.objects.all(), - label=TipoAutor._meta.get_field('content_type').verbose_name, - required=False) - class Meta: model = TipoAutor - fields = ['descricao', - 'content_type'] + fields = ['descricao'] def __init__(self, *args, **kwargs): super(TipoAutorForm, self).__init__(*args, **kwargs) - content_types = ContentType.objects.get_for_models( - *models_with_gr_for_model(Autor)) - - self.fields['content_type'].choices = [ - ('', _('Outros (Especifique)'))] + [ - (ct.pk, ct) for key, ct in content_types.items()] - class AutorForm(ModelForm): senha = forms.CharField( diff --git a/sapl/base/migrations/0012_auto_20171205_0917.py b/sapl/base/migrations/0012_auto_20171205_0917.py new file mode 100644 index 000000000..4080818fa --- /dev/null +++ b/sapl/base/migrations/0012_auto_20171205_0917.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2017-12-05 11:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0011_auto_20171121_0958'), + ] + + operations = [ + migrations.AlterField( + model_name='tipoautor', + name='descricao', + field=models.CharField(help_text='Obs: Não crie tipos de autores semelhante aos tipos fixos. ', max_length=50, verbose_name='Descrição'), + ), + ] diff --git a/sapl/base/models.py b/sapl/base/models.py index 640616fa9..033812735 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -195,7 +195,10 @@ class AppConfig(models.Model): @reversion.register() class TipoAutor(models.Model): - descricao = models.CharField(max_length=50, verbose_name=_('Descrição')) + descricao = models.CharField( + max_length=50, verbose_name=_('Descrição'), + help_text=_('Obs: Não crie tipos de autores ' + 'semelhante aos tipos fixos. ')) content_type = models.OneToOneField( ContentType, diff --git a/sapl/base/templatetags/base_tags.py b/sapl/base/templatetags/base_tags.py new file mode 100644 index 000000000..22f0aa4b1 --- /dev/null +++ b/sapl/base/templatetags/base_tags.py @@ -0,0 +1,9 @@ + +from django import template + +register = template.Library() + + +@register.filter +def tipoautor_contenttype_list(tipo): + return 'sapl.'+tipo.content_type.app_label+':'+tipo.content_type.model+'_list' diff --git a/sapl/base/views.py b/sapl/base/views.py index f0ae926e5..4bb6cb580 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -11,7 +11,7 @@ from django.template import TemplateDoesNotExist from django.template.loader import get_template from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, string_concat from django.views.generic.base import TemplateView from django_filters.views import FilterView from haystack.views import SearchView @@ -57,9 +57,29 @@ class TipoAutorCrud(CrudAux): help_topic = 'tipo-autor' class BaseMixin(CrudAux.BaseMixin): - list_field_names = ['descricao', 'content_type'] + list_field_names = ['descricao'] form_class = TipoAutorForm + @property + def verbose_name(self): + vn = super().verbose_name + vn = string_concat(vn, ' ', _('Externo ao SAPL')) + return vn + + class ListView(CrudAux.ListView): + def get_queryset(self): + qs = CrudAux.ListView.get_queryset(self) + qs = qs.filter(content_type__isnull=True) + return qs + + def get_context_data(self, **kwargs): + context = CrudAux.ListView.get_context_data(self, **kwargs) + + context['tipos_sapl'] = TipoAutor.objects.filter( + content_type__isnull=False) + + return context + class AutorCrud(CrudAux): model = Autor diff --git a/sapl/static/styles/app.scss b/sapl/static/styles/app.scss index 74fcd42b4..170310313 100644 --- a/sapl/static/styles/app.scss +++ b/sapl/static/styles/app.scss @@ -123,6 +123,13 @@ h6, .h6 { display: block; } } + +.help-block-danger { + margin: $grid-gutter-width / 2; + padding: $grid-gutter-width / 2; + border: 2px dashed #f00; +} + .controls-radio-checkbox { padding: 0px; border: 1px solid #d6e1e5; diff --git a/sapl/templates/base/layouts.yaml b/sapl/templates/base/layouts.yaml index 0b4b07b27..68da1cd70 100644 --- a/sapl/templates/base/layouts.yaml +++ b/sapl/templates/base/layouts.yaml @@ -28,7 +28,7 @@ AppConfig: TipoAutor: {% trans 'Tipo Autor' %}: - - content_type:4 descricao + - descricao Autor: {% trans 'Autor' %}: diff --git a/sapl/templates/base/tipoautor_form.html b/sapl/templates/base/tipoautor_form.html deleted file mode 100644 index 01f771246..000000000 --- a/sapl/templates/base/tipoautor_form.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "crud/form.html" %} -{% load i18n %} -{% block extra_js %} - - - -{% endblock %} diff --git a/sapl/templates/base/tipoautor_list.html b/sapl/templates/base/tipoautor_list.html new file mode 100644 index 000000000..e7aaf98db --- /dev/null +++ b/sapl/templates/base/tipoautor_list.html @@ -0,0 +1,34 @@ +{% extends "crud/list.html" %} +{% load i18n base_tags %} + + +{% block container_table_list %} +
+
+
+ Tipos de Autores do SAPL + {% for tipo in tipos_sapl %} + {{tipo}} + {% endfor %} + + +
+
+
+ {{block.super}} +
+ Atenção!!! - Não cadastre tipos de autores semelhantes + aos "Tipos de Autores do SAPL" que estão na tabela ao lado. Esses tipos + são fixos no SAPL pois representam seus cadastros no local apropriado.
+
+
+ Novamente, NÃO cadastre "Tipos de Autor" semelhantes aos tipos do SAPL.
+ Veja como exemplo: No Sapl existe o tipo Parlamentar. + Não use tipos semelhantes, como cadastrar um tipo com a descrição "Vereador", + ou mesmo cadastrar outro como "Parlamentar".
+ Se está ali na tabela da lateral esquerda, talvez não exatamente igual, + mas tem o mesmo sentido de sua intenção, não deve ser adicionado. +
+
+
+{% endblock container_table_list %} diff --git a/sapl/templates/crud/list.html b/sapl/templates/crud/list.html index 614389235..9debc332b 100644 --- a/sapl/templates/crud/list.html +++ b/sapl/templates/crud/list.html @@ -22,58 +22,58 @@ {% endblock actions %} -{% block extra_content %} {% endblock %} - -{% if not rows %} -

{{ NO_ENTRIES_MSG }}

-{% else %} -
-
{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de {{ verbose_name_plural }}: {{count}}{% endblocktrans %}
- - - - {% for name in headers %} - +
+ {% endif %} +{% endblock container_table_list %} {% include "paginacao.html" %}