Browse Source

limita edição de tipoautor a tipos externos a modelagem do sapl (#1623)

pull/1630/head
Leandro Roberto da Silva 7 years ago
committed by Edward
parent
commit
8c440b6228
  1. 20
      sapl/base/forms.py
  2. 20
      sapl/base/migrations/0012_auto_20171205_0917.py
  3. 5
      sapl/base/models.py
  4. 9
      sapl/base/templatetags/base_tags.py
  5. 24
      sapl/base/views.py
  6. 7
      sapl/static/styles/app.scss
  7. 2
      sapl/templates/base/layouts.yaml
  8. 20
      sapl/templates/base/tipoautor_form.html
  9. 34
      sapl/templates/base/tipoautor_list.html
  10. 4
      sapl/templates/crud/list.html

20
sapl/base/forms.py

@ -1,4 +1,3 @@
import django_filters
from crispy_forms.bootstrap import FieldWithButtons, InlineRadios, StrictButton from crispy_forms.bootstrap import FieldWithButtons, InlineRadios, StrictButton
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Div, Field, Fieldset, Layout, Row 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.core.exceptions import ValidationError
from django.db import models, transaction from django.db import models, transaction
from django.forms import ModelForm 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 string_concat
from django.utils.translation import ugettext_lazy as _
import django_filters
from sapl.base.models import Autor, TipoAutor from sapl.base.models import Autor, TipoAutor
from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, 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 from .models import AppConfig, CasaLegislativa
ACTION_CREATE_USERS_AUTOR_CHOICE = [ ACTION_CREATE_USERS_AUTOR_CHOICE = [
('A', _('Associar um usuário existente')), ('A', _('Associar um usuário existente')),
('N', _('Autor sem Usuário de Acesso ao Sapl')), ('N', _('Autor sem Usuário de Acesso ao Sapl')),
@ -45,27 +46,14 @@ STATUS_USER_CHOICE = [
class TipoAutorForm(ModelForm): class TipoAutorForm(ModelForm):
content_type = forms.ModelChoiceField(
queryset=ContentType.objects.all(),
label=TipoAutor._meta.get_field('content_type').verbose_name,
required=False)
class Meta: class Meta:
model = TipoAutor model = TipoAutor
fields = ['descricao', fields = ['descricao']
'content_type']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TipoAutorForm, self).__init__(*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): class AutorForm(ModelForm):
senha = forms.CharField( senha = forms.CharField(

20
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'),
),
]

5
sapl/base/models.py

@ -195,7 +195,10 @@ class AppConfig(models.Model):
@reversion.register() @reversion.register()
class TipoAutor(models.Model): 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( content_type = models.OneToOneField(
ContentType, ContentType,

9
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'

24
sapl/base/views.py

@ -11,7 +11,7 @@ from django.template import TemplateDoesNotExist
from django.template.loader import get_template from django.template.loader import get_template
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode 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.views.generic.base import TemplateView
from django_filters.views import FilterView from django_filters.views import FilterView
from haystack.views import SearchView from haystack.views import SearchView
@ -57,9 +57,29 @@ class TipoAutorCrud(CrudAux):
help_topic = 'tipo-autor' help_topic = 'tipo-autor'
class BaseMixin(CrudAux.BaseMixin): class BaseMixin(CrudAux.BaseMixin):
list_field_names = ['descricao', 'content_type'] list_field_names = ['descricao']
form_class = TipoAutorForm 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): class AutorCrud(CrudAux):
model = Autor model = Autor

7
sapl/static/styles/app.scss

@ -123,6 +123,13 @@ h6, .h6 {
display: block; display: block;
} }
} }
.help-block-danger {
margin: $grid-gutter-width / 2;
padding: $grid-gutter-width / 2;
border: 2px dashed #f00;
}
.controls-radio-checkbox { .controls-radio-checkbox {
padding: 0px; padding: 0px;
border: 1px solid #d6e1e5; border: 1px solid #d6e1e5;

2
sapl/templates/base/layouts.yaml

@ -28,7 +28,7 @@ AppConfig:
TipoAutor: TipoAutor:
{% trans 'Tipo Autor' %}: {% trans 'Tipo Autor' %}:
- content_type:4 descricao - descricao
Autor: Autor:
{% trans 'Autor' %}: {% trans 'Autor' %}:

20
sapl/templates/base/tipoautor_form.html

@ -1,20 +0,0 @@
{% extends "crud/form.html" %}
{% load i18n %}
{% block extra_js %}
<script type="text/javascript">
$(document).ready(function(){
$('#id_content_type').change(function(event) {
if (event.target.selectedIndex == 0)
$('#id_descricao').val('');
else
$('#id_descricao').val(this[event.target.selectedIndex].text);
});
});
</script>
{% endblock %}

34
sapl/templates/base/tipoautor_list.html

@ -0,0 +1,34 @@
{% extends "crud/list.html" %}
{% load i18n base_tags %}
{% block container_table_list %}
<div class="row">
<div class="col-lg-4">
<div class="list-group">
<span class="list-group-item active">Tipos de Autores do SAPL</span>
{% for tipo in tipos_sapl %}
<a href="{% url tipo|tipoautor_contenttype_list %}" class="list-group-item">{{tipo}}</a>
{% endfor %}
</div>
</div>
<div class="col-lg-8">
{{block.super}}
<div class="help-block-danger">
<strong>Atenção!!!</strong> - 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.<br>
</div>
<div class="help-block-danger">
Novamente, NÃO cadastre "Tipos de Autor" semelhantes aos tipos do SAPL.<br>
<strong>Veja como exemplo:</strong> 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".<br>
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.
</div>
</div>
</div>
{% endblock container_table_list %}

4
sapl/templates/crud/list.html

@ -22,8 +22,7 @@
{% endblock actions %} {% endblock actions %}
</div> </div>
{% block extra_content %} {% endblock %} {% block container_table_list %}
{% if not rows %} {% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p> <p>{{ NO_ENTRIES_MSG }}</p>
{% else %} {% else %}
@ -74,6 +73,7 @@
</table> </table>
</div> </div>
{% endif %} {% endif %}
{% endblock container_table_list %}
{% include "paginacao.html" %} {% include "paginacao.html" %}

Loading…
Cancel
Save