Browse Source

Conc refatoração no Cada de Autor e Tipos de Autor

pull/752/head
LeandroRoberto 8 years ago
parent
commit
2a44eb455a
  1. 2
      sapl/api/urls.py
  2. 7
      sapl/api/views.py
  3. 12
      sapl/base/forms.py
  4. 2
      sapl/base/views.py
  5. 3
      sapl/crud/base.py
  6. 2
      sapl/materia/forms.py
  7. 3
      sapl/materia/views.py
  8. 2
      sapl/templates/base.html
  9. 7
      sapl/templates/base/autor_form.html
  10. 14
      sapl/templates/bootstrap3/layout/checkboxselectmultiple.html
  11. 19
      sapl/templates/bootstrap3/layout/radioselect.html
  12. 4
      sapl/test_urls.py
  13. 1
      sapl/utils.py

2
sapl/api/urls.py

@ -1,3 +1,4 @@
from django.conf import settings from django.conf import settings
from django.conf.urls import url, include from django.conf.urls import url, include
@ -5,7 +6,6 @@ from sapl.api.views import AutorListView
from .apps import AppConfig from .apps import AppConfig
app_name = AppConfig.name app_name = AppConfig.name

7
sapl/api/views.py

@ -5,6 +5,8 @@ from django.utils.translation import ugettext_lazy as _
from rest_framework.filters import DjangoFilterBackend from rest_framework.filters import DjangoFilterBackend
from rest_framework.generics import ListAPIView from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAuthenticated, AllowAny from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.generics import ListAPIView, get_object_or_404
from rest_framework.viewsets import ModelViewSet
from sapl.api.forms import AutorChoiceFilterSet from sapl.api.forms import AutorChoiceFilterSet
from sapl.api.serializers import ChoiceSerializer, AutorSerializer,\ from sapl.api.serializers import ChoiceSerializer, AutorSerializer,\
@ -32,7 +34,7 @@ class AutorListView(ListAPIView):
em combobox, radiobox, checkbox, etc com pesquisa básica em combobox, radiobox, checkbox, etc com pesquisa básica
de Autores mas feito para Possíveis Autores armazenados de Autores mas feito para Possíveis Autores armazenados
segundo o ContentType associado ao Tipo de Autor via segundo o ContentType associado ao Tipo de Autor via
relacionamento genérico. relacionamento genérico.
Busca feita sem django-filter processada no get_queryset Busca feita sem django-filter processada no get_queryset
-> processo no cadastro de autores para seleção e busca -> processo no cadastro de autores para seleção e busca
dos possíveis autores dos possíveis autores
@ -44,7 +46,7 @@ class AutorListView(ListAPIView):
- q - busca textual no nome do Autor ou em fields_search - q - busca textual no nome do Autor ou em fields_search
declarados no field SaplGenericRelation das GenericFks declarados no field SaplGenericRelation das GenericFks
A busca textual acontece via django-filter com a A busca textual acontece via django-filter com a
variável `tr` igual 1 ou 3. Em caso contrário, variável `tr` igual 1 ou 3. Em caso contrário,
o django-filter é desativado e a busca é feita o django-filter é desativado e a busca é feita
no model do ContentType associado ao tipo. no model do ContentType associado ao tipo.
@ -99,6 +101,7 @@ class AutorListView(ListAPIView):
return ListAPIView.get(self, request, *args, **kwargs) return ListAPIView.get(self, request, *args, **kwargs)
def get_queryset(self): def get_queryset(self):
queryset = ListAPIView.get_queryset(self) queryset = ListAPIView.get_queryset(self)

12
sapl/base/forms.py

@ -1,7 +1,9 @@
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
from crispy_forms.templatetags.crispy_forms_field import css_class from crispy_forms.templatetags.crispy_forms_field import css_class
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -28,6 +30,12 @@ from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput,
from .models import AppConfig, CasaLegislativa from .models import AppConfig, CasaLegislativa
ACTION_CREATE_USERS_AUTOR_CHOICE = [
('C', _('Criar novo Usuário')),
('A', _('Associar um usuário existente')),
('N', _('Autor sem Usuário de Acesso ao Sapl')),
]
ACTION_CREATE_USERS_AUTOR_CHOICE = [ ACTION_CREATE_USERS_AUTOR_CHOICE = [
('C', _('Criar novo Usuário')), ('C', _('Criar novo Usuário')),
@ -161,6 +169,7 @@ class AutorForm(ModelForm):
'como o Sistema deve proceder com o usuário que está sendo' 'como o Sistema deve proceder com o usuário que está sendo'
' desvinculado?')) ' desvinculado?'))
class Meta: class Meta:
model = Autor model = Autor
fields = ['tipo', fields = ['tipo',
@ -181,8 +190,6 @@ class AutorForm(ModelForm):
StrictButton( StrictButton(
_('Filtrar'), css_class='btn-default btn-filtrar-autor', _('Filtrar'), css_class='btn-default btn-filtrar-autor',
type='button')), type='button')),
css_class='hidden', css_class='hidden',
data_action='create', data_action='create',
data_application='AutorSearch', data_application='AutorSearch',
@ -199,6 +206,7 @@ class AutorForm(ModelForm):
row2 = Row(to_column((InlineRadios('action_user'), 8)), row2 = Row(to_column((InlineRadios('action_user'), 8)),
to_column((Div('username'), 4))) to_column((Div('username'), 4)))
row3 = Row(to_column(('senha', 3)), row3 = Row(to_column(('senha', 3)),
to_column(('senha_confirma', 3)), to_column(('senha_confirma', 3)),
to_column(('email', 3)), to_column(('email', 3)),

2
sapl/base/views.py

@ -77,7 +77,7 @@ class AutorCrud(CrudAux):
try: try:
kwargs = {} kwargs = {}
user = self.object.user user = self.object.user
if user.is_active: if user.is_active:
return reverse('sapl.base:autor_detail', return reverse('sapl.base:autor_detail',
kwargs={'pk': pk_autor}) kwargs={'pk': pk_autor})

3
sapl/crud/base.py

@ -14,8 +14,8 @@ from django.db.models.fields.related import ForeignKey
from django.http.response import Http404 from django.http.response import Http404
from django.utils.decorators import classonlymethod from django.utils.decorators import classonlymethod
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat
from django.views.generic import (CreateView, DeleteView, DetailView, ListView, from django.views.generic import (CreateView, DeleteView, DetailView, ListView,
UpdateView) UpdateView)
from django.views.generic.base import ContextMixin from django.views.generic.base import ContextMixin
@ -25,7 +25,6 @@ from sapl.crispy_layout_mixin import CrispyLayoutFormMixin, get_field_display
from sapl.settings import BASE_DIR from sapl.settings import BASE_DIR
from sapl.utils import normalize from sapl.utils import normalize
logger = logging.getLogger(BASE_DIR.name) logger = logging.getLogger(BASE_DIR.name)
ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \ ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \

2
sapl/materia/forms.py

@ -1,5 +1,6 @@
from datetime import datetime from datetime import datetime
import django_filters
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout
from django import forms from django import forms
@ -8,7 +9,6 @@ from django.db import models
from django.db.models import Max from django.db.models import Max
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import django_filters
from sapl.base.models import Autor from sapl.base.models import Autor
from sapl.comissoes.models import Comissao from sapl.comissoes.models import Comissao

3
sapl/materia/views.py

@ -37,7 +37,6 @@ from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label,
permissoes_protocoloadm, permission_required_for_app, permissoes_protocoloadm, permission_required_for_app,
montar_row_autor) montar_row_autor)
from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm,
ConfirmarProposicaoForm, DocumentoAcessorioForm, ConfirmarProposicaoForm, DocumentoAcessorioForm,
MateriaLegislativaFilterSet, MateriaLegislativaFilterSet,
@ -314,7 +313,7 @@ class ProposicaoCrud(Crud):
TODO: Entre outros comportamento gerais, mesmo que um usuário tenha TODO: Entre outros comportamento gerais, mesmo que um usuário tenha
Perfil de Autor o Crud de proposição não deverá permitir acesso a Perfil de Autor o Crud de proposição não deverá permitir acesso a
proposições. O acesso deve ser permitido se existe um Autor registrado proposições. O acesso deve ser permitido se existe um Autor registrado
e vinculado ao usuário. Essa tarefa deve ser realizada nas Tabelas Aux. e vinculado ao usuário. Essa tarefa deve ser realizada nas Tabelas Aux.
""" """
model = Proposicao model = Proposicao
help_path = '' help_path = ''

2
sapl/templates/base.html

@ -287,6 +287,8 @@
<script type="text/javascript" src="{% static 'js/jquery.runner.js' %}"></script> <script type="text/javascript" src="{% static 'js/jquery.runner.js' %}"></script>
<script type="text/javascript" src="{% static 'jquery-mask-plugin/dist/jquery.mask.js' %}"></script> <script type="text/javascript" src="{% static 'jquery-mask-plugin/dist/jquery.mask.js' %}"></script>
<script type="text/javascript" src="{% static 'drunken-parrot-flat-ui/js/checkbox.js' %}"></script>
<script type="text/javascript" src="{% static 'drunken-parrot-flat-ui/js/radio.js' %}"></script>
<script src="{% static 'tinymce/tinymce.min.js' %}"></script> <script src="{% static 'tinymce/tinymce.min.js' %}"></script>
<script type="text/javascript" src="{% static 'jsdiff/diff.min.js' %}"></script> <script type="text/javascript" src="{% static 'jsdiff/diff.min.js' %}"></script>

7
sapl/templates/base/autor_form.html

@ -39,12 +39,12 @@ $(document).ready(function(){
active('pesquisa'); active('pesquisa');
if (atualizar) { if (atualizar) {
var radios = $("#div_id_autor_related .controls").html(''); var radios = $("#div_id_autor_related .controls").html('');
data.models.forEach(function (val, index) { data.results.forEach(function (val, index) {
var html_radio = '<label class="radio"><span class="icons"><span class="first-icon"></span><span class="second-icon"></span></span><input type="radio" name="autor_related" id="id_autor_related_'+index+'" value="'+val.value+'">'+val.text+'</label>'; var html_radio = '<label class="radio"><span class="icons"><span class="first-icon"></span><span class="second-icon"></span></span><input type="radio" name="autor_related" id="id_autor_related_'+index+'" value="'+val.value+'">'+val.text+'</label>';
radios.append(html_radio); radios.append(html_radio);
}); });
if (data.models.length > 1) { if (data.results.length > 1) {
$('input[name=autor_related]').change(function(event){ $('input[name=autor_related]').change(function(event){
if (this.checked) if (this.checked)
$('#id_q').val(event.target.parentElement.textContent); $('#id_q').val(event.target.parentElement.textContent);
@ -132,7 +132,8 @@ $(document).ready(function(){
}); });
$('input[name=action_user]:checked').trigger('change'); $('input[name=action_user]:checked').trigger('change');
$('input[name=autor_related]').closest('.radio').remove(); if (flag_create)
$('input[name=autor_related]').closest('.radio').remove();
var pk = $('#id_tipo').val(); var pk = $('#id_tipo').val();
if (pk) if (pk)

14
sapl/templates/bootstrap3/layout/checkboxselectmultiple.html

@ -0,0 +1,14 @@
{% load crispy_forms_filters %}
{% load l10n %}
<div class="controls controls-checkbox {{ field_class }}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
{% include 'bootstrap3/layout/field_errors_block.html' %}
{% for choice in field.field.choices %}
<label class="checkbox{% if field.field.inline_class %} checkbox-inline{% endif %}{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter }}">
<span class="icons"><span class="first-icon"></span><span class="second-icon fa fa-check"></span></span>
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
</label>
{% endfor %}
{% include 'bootstrap3/layout/help_text.html' %}
</div>

19
sapl/templates/bootstrap3/layout/radioselect.html

@ -0,0 +1,19 @@
{% load crispy_forms_filters %}
{% load l10n %}
<div class="controls controls-radio {{ field_class }}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
{% include 'bootstrap3/layout/field_errors_block.html' %}
{% for choice in field.field.choices %}
<label class="radio{% if field.field.inline_class %} radio-inline{% endif %}{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter }}">
<span class="icons">
<span class="first-icon"></span>
<span class="second-icon"></span>
</span>
<input type="radio"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
</label>
{% endfor %}
{% include 'bootstrap3/layout/help_text.html' %}
</div>

4
sapl/test_urls.py

@ -1,3 +1,4 @@
import pytest
from django.apps import apps from django.apps import apps
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.management import _get_all_permissions from django.contrib.auth.management import _get_all_permissions
@ -7,7 +8,7 @@ from django.db import transaction
from django.utils.translation import string_concat from django.utils.translation import string_concat
from django.utils.translation import string_concat from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import pytest from django.utils.translation import string_concat
from sapl.crud.base import PermissionRequiredForAppCrudMixin from sapl.crud.base import PermissionRequiredForAppCrudMixin
from sapl.materia.views import recuperar_materia from sapl.materia.views import recuperar_materia
@ -16,7 +17,6 @@ from scripts.lista_urls import lista_urls
from .settings import SAPL_APPS from .settings import SAPL_APPS
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
sapl_appconfs = [apps.get_app_config(n[5:]) for n in SAPL_APPS] sapl_appconfs = [apps.get_app_config(n[5:]) for n in SAPL_APPS]

1
sapl/utils.py

@ -4,6 +4,7 @@ from unicodedata import normalize as unicodedata_normalize
import hashlib import hashlib
import logging import logging
import magic
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button from crispy_forms.layout import HTML, Button
from django import forms from django import forms

Loading…
Cancel
Save