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. 92
      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.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(

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()
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,

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.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

7
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;

2
sapl/templates/base/layouts.yaml

@ -28,7 +28,7 @@ AppConfig:
TipoAutor:
{% trans 'Tipo Autor' %}:
- content_type:4 descricao
- descricao
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 %}

92
sapl/templates/crud/list.html

@ -22,58 +22,58 @@
{% endblock actions %}
</div>
{% block extra_content %} {% endblock %}
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<div class="container-table">
<div class="result-count">{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de {{ verbose_name_plural }}: <strong>{{count}}</strong>{% endblocktrans %}</div>
<table class="table table-striped table-hover table-link-ordering">
<thead>
<tr>
{% for name in headers %}
<th>
{% if view.ordered_list %}
<a title="{% trans 'Clique para alterar a ordem a listagem'%}" href="?o={% if 'o' not in request.GET and forloop.counter == 1 or 'o' in request.GET and forloop.counter|safe == request.GET.o %}-{%endif%}{{forloop.counter}}{{ordering_url}}">
{{ name }}
{% if 'o' in request.GET or not view.ordering %}
{% if 'o' not in request.GET and forloop.counter == 1 or 'o' in request.GET and forloop.counter|safe == request.GET.o %}
<span class="caret top" title="{% trans 'Listado na Ordem Ascendente'%}"></span>
{% elif 'o' in request.GET and forloop.counter == request.GET.o|str2intabs %}
<span class="caret" title="{% trans 'Listado na Ordem Descendente'%}"></span>
{% block container_table_list %}
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<div class="container-table">
<div class="result-count">{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de {{ verbose_name_plural }}: <strong>{{count}}</strong>{% endblocktrans %}</div>
<table class="table table-striped table-hover table-link-ordering">
<thead>
<tr>
{% for name in headers %}
<th>
{% if view.ordered_list %}
<a title="{% trans 'Clique para alterar a ordem a listagem'%}" href="?o={% if 'o' not in request.GET and forloop.counter == 1 or 'o' in request.GET and forloop.counter|safe == request.GET.o %}-{%endif%}{{forloop.counter}}{{ordering_url}}">
{{ name }}
{% if 'o' in request.GET or not view.ordering %}
{% if 'o' not in request.GET and forloop.counter == 1 or 'o' in request.GET and forloop.counter|safe == request.GET.o %}
<span class="caret top" title="{% trans 'Listado na Ordem Ascendente'%}"></span>
{% elif 'o' in request.GET and forloop.counter == request.GET.o|str2intabs %}
<span class="caret" title="{% trans 'Listado na Ordem Descendente'%}"></span>
{%endif%}
{%endif%}
{%endif%}
</a>
</a>
{% else %}
{{ name }}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in rows %}
<tr>
{% for value, href in value_list %}
<td>
{% if href %}
<a href="{{ href }}">{{ value|safe|default:"" }}</a>
{% elif valu != 'core.Cep.None' %}
{% if value|url %}
<a href="{{ value|safe }}"> {{ value|safe|default:"" }} </a></div>
{% else %}
{{ name }}
{{ value|safe|default:"" }}
{% endif %}
</th>
{% endif %}
</td>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in rows %}
<tr>
{% for value, href in value_list %}
<td>
{% if href %}
<a href="{{ href }}">{{ value|safe|default:"" }}</a>
{% elif valu != 'core.Cep.None' %}
{% if value|url %}
<a href="{{ value|safe }}"> {{ value|safe|default:"" }} </a></div>
{% else %}
{{ value|safe|default:"" }}
{% endif %}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</tbody>
</table>
</div>
{% endif %}
{% endblock container_table_list %}
{% include "paginacao.html" %}

Loading…
Cancel
Save