From 2a44eb455a5caa1a6edb588021e46fb34b1160e7 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Tue, 11 Oct 2016 16:36:43 -0300 Subject: [PATCH] =?UTF-8?q?Conc=20refatora=C3=A7=C3=A3o=20no=20Cada=20de?= =?UTF-8?q?=20Autor=20e=20Tipos=20de=20Autor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/api/urls.py | 2 +- sapl/api/views.py | 7 +++++-- sapl/base/forms.py | 12 ++++++++++-- sapl/base/views.py | 2 +- sapl/crud/base.py | 3 +-- sapl/materia/forms.py | 2 +- sapl/materia/views.py | 3 +-- sapl/templates/base.html | 2 ++ sapl/templates/base/autor_form.html | 7 ++++--- .../layout/checkboxselectmultiple.html | 14 ++++++++++++++ .../bootstrap3/layout/radioselect.html | 19 +++++++++++++++++++ sapl/test_urls.py | 4 ++-- sapl/utils.py | 1 + 13 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 sapl/templates/bootstrap3/layout/checkboxselectmultiple.html create mode 100644 sapl/templates/bootstrap3/layout/radioselect.html diff --git a/sapl/api/urls.py b/sapl/api/urls.py index d87a5d48f..d547bb2fb 100644 --- a/sapl/api/urls.py +++ b/sapl/api/urls.py @@ -1,3 +1,4 @@ + from django.conf import settings from django.conf.urls import url, include @@ -5,7 +6,6 @@ from sapl.api.views import AutorListView from .apps import AppConfig - app_name = AppConfig.name diff --git a/sapl/api/views.py b/sapl/api/views.py index 4d5ee0ca8..419248c0f 100644 --- a/sapl/api/views.py +++ b/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.generics import ListAPIView 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.serializers import ChoiceSerializer, AutorSerializer,\ @@ -32,7 +34,7 @@ class AutorListView(ListAPIView): em combobox, radiobox, checkbox, etc com pesquisa básica de Autores mas feito para Possíveis Autores armazenados segundo o ContentType associado ao Tipo de Autor via - relacionamento genérico. + relacionamento genérico. Busca feita sem django-filter processada no get_queryset -> processo no cadastro de autores para seleção e busca dos possíveis autores @@ -44,7 +46,7 @@ class AutorListView(ListAPIView): - q - busca textual no nome do Autor ou em fields_search 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, o django-filter é desativado e a busca é feita no model do ContentType associado ao tipo. @@ -99,6 +101,7 @@ class AutorListView(ListAPIView): return ListAPIView.get(self, request, *args, **kwargs) + def get_queryset(self): queryset = ListAPIView.get_queryset(self) diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 8033c37f6..01c05d1d6 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1,7 +1,9 @@ + 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 from crispy_forms.templatetags.crispy_forms_field import css_class + from django import forms from django.conf import settings from django.contrib.auth import get_user_model @@ -28,6 +30,12 @@ from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, 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 = [ ('C', _('Criar novo Usuário')), @@ -161,6 +169,7 @@ class AutorForm(ModelForm): 'como o Sistema deve proceder com o usuário que está sendo' ' desvinculado?')) + class Meta: model = Autor fields = ['tipo', @@ -181,8 +190,6 @@ class AutorForm(ModelForm): StrictButton( _('Filtrar'), css_class='btn-default btn-filtrar-autor', type='button')), - - css_class='hidden', data_action='create', data_application='AutorSearch', @@ -199,6 +206,7 @@ class AutorForm(ModelForm): row2 = Row(to_column((InlineRadios('action_user'), 8)), to_column((Div('username'), 4))) + row3 = Row(to_column(('senha', 3)), to_column(('senha_confirma', 3)), to_column(('email', 3)), diff --git a/sapl/base/views.py b/sapl/base/views.py index 89aaec991..5d0a3dc25 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -77,7 +77,7 @@ class AutorCrud(CrudAux): try: kwargs = {} user = self.object.user - + if user.is_active: return reverse('sapl.base:autor_detail', kwargs={'pk': pk_autor}) diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 694898115..a7fb95e2b 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -14,8 +14,8 @@ from django.db.models.fields.related import ForeignKey from django.http.response import Http404 from django.utils.decorators import classonlymethod 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 string_concat from django.views.generic import (CreateView, DeleteView, DetailView, ListView, UpdateView) 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.utils import normalize - logger = logging.getLogger(BASE_DIR.name) ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \ diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index b41549018..8eae1e6a2 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1,5 +1,6 @@ from datetime import datetime +import django_filters from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout from django import forms @@ -8,7 +9,6 @@ from django.db import models from django.db.models import Max from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ -import django_filters from sapl.base.models import Autor from sapl.comissoes.models import Comissao diff --git a/sapl/materia/views.py b/sapl/materia/views.py index e1604a74c..c1411f078 100644 --- a/sapl/materia/views.py +++ b/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, montar_row_autor) - from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, ConfirmarProposicaoForm, DocumentoAcessorioForm, MateriaLegislativaFilterSet, @@ -314,7 +313,7 @@ class ProposicaoCrud(Crud): 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 proposições. O acesso só 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 help_path = '' diff --git a/sapl/templates/base.html b/sapl/templates/base.html index f1ad89e8e..80ad94f38 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -287,6 +287,8 @@ + + diff --git a/sapl/templates/base/autor_form.html b/sapl/templates/base/autor_form.html index 12eaf104b..cee9e5bb9 100644 --- a/sapl/templates/base/autor_form.html +++ b/sapl/templates/base/autor_form.html @@ -39,12 +39,12 @@ $(document).ready(function(){ active('pesquisa'); if (atualizar) { var radios = $("#div_id_autor_related .controls").html(''); - data.models.forEach(function (val, index) { + data.results.forEach(function (val, index) { var html_radio = ''; radios.append(html_radio); }); - if (data.models.length > 1) { + if (data.results.length > 1) { $('input[name=autor_related]').change(function(event){ if (this.checked) $('#id_q').val(event.target.parentElement.textContent); @@ -132,7 +132,8 @@ $(document).ready(function(){ }); $('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(); if (pk) diff --git a/sapl/templates/bootstrap3/layout/checkboxselectmultiple.html b/sapl/templates/bootstrap3/layout/checkboxselectmultiple.html new file mode 100644 index 000000000..a7398ab11 --- /dev/null +++ b/sapl/templates/bootstrap3/layout/checkboxselectmultiple.html @@ -0,0 +1,14 @@ +{% load crispy_forms_filters %} +{% load l10n %} + +
+ {% include 'bootstrap3/layout/field_errors_block.html' %} + {% for choice in field.field.choices %} + + {% endfor %} + {% include 'bootstrap3/layout/help_text.html' %} +
diff --git a/sapl/templates/bootstrap3/layout/radioselect.html b/sapl/templates/bootstrap3/layout/radioselect.html new file mode 100644 index 000000000..b3e6b589e --- /dev/null +++ b/sapl/templates/bootstrap3/layout/radioselect.html @@ -0,0 +1,19 @@ +{% load crispy_forms_filters %} +{% load l10n %} + +
+ {% include 'bootstrap3/layout/field_errors_block.html' %} + + {% for choice in field.field.choices %} + + {% endfor %} + + {% include 'bootstrap3/layout/help_text.html' %} +
diff --git a/sapl/test_urls.py b/sapl/test_urls.py index 7735749cd..72c02b251 100644 --- a/sapl/test_urls.py +++ b/sapl/test_urls.py @@ -1,3 +1,4 @@ +import pytest from django.apps import apps from django.contrib.auth import get_user_model 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 ugettext_lazy as _ -import pytest +from django.utils.translation import string_concat from sapl.crud.base import PermissionRequiredForAppCrudMixin from sapl.materia.views import recuperar_materia @@ -16,7 +17,6 @@ from scripts.lista_urls import lista_urls from .settings import SAPL_APPS - pytestmark = pytest.mark.django_db sapl_appconfs = [apps.get_app_config(n[5:]) for n in SAPL_APPS] diff --git a/sapl/utils.py b/sapl/utils.py index 7029a508b..74d4f6fd5 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -4,6 +4,7 @@ from unicodedata import normalize as unicodedata_normalize import hashlib import logging +import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms