From 788dad162bccc40e48210d162f06210d483a5e37 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 27 Oct 2016 18:11:29 -0200 Subject: [PATCH] Fix qa --- sapl/api/forms.py | 2 +- sapl/api/serializers.py | 1 + sapl/api/urls.py | 6 +-- sapl/api/views.py | 9 ++-- sapl/base/apps.py | 2 +- sapl/base/forms.py | 15 ++---- sapl/base/models.py | 10 +--- sapl/base/templatetags/menus.py | 3 +- sapl/base/views.py | 2 +- sapl/crispy_layout_mixin.py | 2 +- sapl/crud/base.py | 3 +- sapl/materia/forms.py | 57 +++++++++++--------- sapl/materia/models.py | 13 ++--- sapl/materia/tests/test_materia.py | 2 +- sapl/materia/views.py | 35 +++++------- sapl/norma/models.py | 2 - sapl/protocoloadm/models.py | 6 +-- sapl/protocoloadm/tests/test_protocoloadm.py | 2 +- sapl/protocoloadm/views.py | 9 ++-- sapl/relatorios/views.py | 2 - sapl/rules/apps.py | 21 ++++---- sapl/rules/map_rules.py | 17 +++--- sapl/rules/tests/test_rules.py | 3 +- sapl/sessao/views.py | 2 +- sapl/test_urls.py | 7 ++- sapl/urls.py | 1 - sapl/utils.py | 23 ++++---- 27 files changed, 114 insertions(+), 143 deletions(-) diff --git a/sapl/api/forms.py b/sapl/api/forms.py index 87e2c2990..c220c01b2 100644 --- a/sapl/api/forms.py +++ b/sapl/api/forms.py @@ -1,6 +1,7 @@ from django.db.models import Q from django_filters.filters import MethodFilter, ModelChoiceFilter from rest_framework.filters import FilterSet + from sapl.base.models import Autor, TipoAutor from sapl.utils import generic_relations_for_model @@ -21,7 +22,6 @@ class SaplGenericRelationSearchFilterSet(FilterSet): order_by = [] for gr in generic_relations_for_model(self._meta.model): - model = gr[0] sgr = gr[1] for item in sgr: if item.related_model != self._meta.model: diff --git a/sapl/api/serializers.py b/sapl/api/serializers.py index 0791ab22f..bd3fb7def 100644 --- a/sapl/api/serializers.py +++ b/sapl/api/serializers.py @@ -1,4 +1,5 @@ from rest_framework import serializers + from sapl.base.models import Autor from sapl.materia.models import MateriaLegislativa diff --git a/sapl/api/urls.py b/sapl/api/urls.py index 0d197efc9..195c7f84a 100644 --- a/sapl/api/urls.py +++ b/sapl/api/urls.py @@ -1,9 +1,9 @@ from django.conf import settings -from django.conf.urls import url, include +from django.conf.urls import include, url from rest_framework.routers import DefaultRouter -from sapl.api.views import MateriaLegislativaViewSet, AutorListView,\ - ModelChoiceView +from sapl.api.views import (AutorListView, MateriaLegislativaViewSet, + ModelChoiceView) from .apps import AppConfig diff --git a/sapl/api/views.py b/sapl/api/views.py index d0d1a875d..41d327bff 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -5,13 +5,14 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework.filters import DjangoFilterBackend from rest_framework.generics import ListAPIView from rest_framework.mixins import ListModelMixin, RetrieveModelMixin -from rest_framework.permissions import IsAuthenticated, AllowAny +from rest_framework.permissions import IsAuthenticated from rest_framework.viewsets import GenericViewSet from sapl.api.forms import AutorChoiceFilterSet -from sapl.api.serializers import ChoiceSerializer, AutorSerializer,\ - AutorChoiceSerializer, ModelChoiceSerializer, MateriaLegislativaSerializer - +from sapl.api.serializers import (AutorChoiceSerializer, AutorSerializer, + ChoiceSerializer, + MateriaLegislativaSerializer, + ModelChoiceSerializer) from sapl.base.models import Autor, TipoAutor from sapl.materia.models import MateriaLegislativa from sapl.utils import SaplGenericRelation, sapl_logger diff --git a/sapl/base/apps.py b/sapl/base/apps.py index 2c3002470..c3af888b7 100644 --- a/sapl/base/apps.py +++ b/sapl/base/apps.py @@ -1,6 +1,6 @@ -from django.utils.translation import ugettext_lazy as _ import django +from django.utils.translation import ugettext_lazy as _ class AppConfig(django.apps.AppConfig): diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 46357ee00..5b4d9f734 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1,22 +1,17 @@ +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 -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 from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import Group from django.contrib.auth.password_validation import validate_password -from django.contrib.contenttypes.fields import GenericRel 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 _, string_concat - -import django_filters from django.utils.translation import ugettext_lazy as _ from django.utils.translation import string_concat @@ -26,11 +21,9 @@ from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, from sapl.materia.models import MateriaLegislativa from sapl.sessao.models import SessaoPlenaria from sapl.settings import MAX_IMAGE_UPLOAD_SIZE -from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, - RangeWidgetOverride, autor_label, autor_modal, - - SaplGenericRelation, models_with_gr_for_model, - ChoiceWithoutValidationField) +from sapl.utils import (RANGE_ANOS, ChoiceWithoutValidationField, + ImageThumbnailFileInput, RangeWidgetOverride, + autor_label, autor_modal, models_with_gr_for_model) from .models import AppConfig, CasaLegislativa diff --git a/sapl/base/models.py b/sapl/base/models.py index ad7b7a5aa..ddf48628c 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -1,18 +1,10 @@ -from builtins import LookupError - -from django.apps import apps -from django.contrib.auth.management import _get_all_permissions from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType -from django.core import exceptions -from django.db import models, router -from django.db.utils import DEFAULT_DB_ALIAS -from django.utils.translation import string_concat +from django.db import models from django.utils.translation import ugettext_lazy as _ from sapl.utils import UF, YES_NO_CHOICES, get_settings_auth_user_model - TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')), ('R', _('Restritivo'))) diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 1ce1d4ea5..e5b6b80d7 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -1,11 +1,10 @@ +import yaml from django import template from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ -import yaml from sapl.utils import sapl_logger - register = template.Library() diff --git a/sapl/base/views.py b/sapl/base/views.py index 1edcb58f4..4de2da9fc 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -13,8 +13,8 @@ from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode from django.utils.translation import ugettext_lazy as _ from django.views.generic.base import TemplateView from django_filters.views import FilterView -from sapl.base.forms import AutorForm, TipoAutorForm, AutorFormForAdmin +from sapl.base.forms import AutorForm, AutorFormForAdmin, TipoAutorForm from sapl.base.models import Autor, TipoAutor from sapl.crud.base import CrudAux from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index 51b386d9c..34c9ecab4 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -1,12 +1,12 @@ from math import ceil +import rtyaml from crispy_forms.bootstrap import FormActions from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit from django import template from django.utils import formats from django.utils.translation import ugettext as _ -import rtyaml def heads_and_tails(list_of_lists): diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 81450172d..945ddf5ae 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -16,8 +16,8 @@ from django.http.response import Http404 from django.shortcuts import redirect 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 @@ -27,7 +27,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 ebb3ab215..acfa37f16 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1,12 +1,13 @@ -from datetime import datetime, date import os +from datetime import date, datetime -from crispy_forms.bootstrap import Alert, InlineCheckboxes, FormActions,\ - InlineRadios +import django_filters +from crispy_forms.bootstrap import (Alert, FormActions, InlineCheckboxes, + InlineRadios) from crispy_forms.helper import FormHelper -from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Row,\ - Field, Submit +from crispy_forms.layout import (HTML, Button, Column, Field, Fieldset, Layout, + Submit) from django import forms from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist, ValidationError @@ -17,22 +18,21 @@ from django.db.models import Max from django.forms import ModelForm, widgets from django.forms.forms import Form from django.utils.translation import ugettext_lazy as _ -import django_filters +import sapl from sapl.base.models import Autor from sapl.comissoes.models import Comissao -from sapl.crispy_layout_mixin import form_actions, to_row, to_column,\ - SaplFormLayout -from sapl.materia.models import TipoProposicao, RegimeTramitacao, TipoDocumento +from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, + to_row) +from sapl.materia.models import RegimeTramitacao, TipoDocumento, TipoProposicao from sapl.norma.models import (LegislacaoCitada, NormaJuridica, TipoNormaJuridica) from sapl.parlamentares.models import Parlamentar from sapl.protocoloadm.models import Protocolo from sapl.settings import MAX_DOC_UPLOAD_SIZE -from sapl.utils import (RANGE_ANOS, RangeWidgetOverride, autor_label, - autor_modal, models_with_gr_for_model, - ChoiceWithoutValidationField, YES_NO_CHOICES) -import sapl +from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, + ChoiceWithoutValidationField, RangeWidgetOverride, + autor_label, autor_modal, models_with_gr_for_model) from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, DocumentoAcessorio, MateriaLegislativa, Numeracao, @@ -829,7 +829,8 @@ class TipoProposicaoForm(ModelForm): content_type = cd['content_type'] - if 'tipo_conteudo_related' not in cd or not cd['tipo_conteudo_related']: + if 'tipo_conteudo_related' not in cd or not cd[ + 'tipo_conteudo_related']: raise ValidationError( _('Seleção de Tipo não definida')) @@ -951,11 +952,14 @@ class ProposicaoForm(forms.ModelForm): if self.instance.materia_de_vinculo: self.fields[ - 'tipo_materia'].initial = self.instance.materia_de_vinculo.tipo + 'tipo_materia' + ].initial = self.instance.materia_de_vinculo.tipo self.fields[ - 'numero_materia'].initial = self.instance.materia_de_vinculo.numero + 'numero_materia' + ].initial = self.instance.materia_de_vinculo.numero self.fields[ - 'ano_materia'].initial = self.instance.materia_de_vinculo.ano + 'ano_materia' + ].initial = self.instance.materia_de_vinculo.ano def clean_texto_original(self): texto_original = self.cleaned_data.get('texto_original', False) @@ -1128,11 +1132,14 @@ class ConfirmarProposicaoForm(ProposicaoForm): if self.instance.materia_de_vinculo: self.fields[ - 'tipo_materia'].initial = self.instance.materia_de_vinculo.tipo + 'tipo_materia' + ].initial = self.instance.materia_de_vinculo.tipo self.fields[ - 'numero_materia'].initial = self.instance.materia_de_vinculo.numero + 'numero_materia' + ].initial = self.instance.materia_de_vinculo.numero self.fields[ - 'ano_materia'].initial = self.instance.materia_de_vinculo.ano + 'ano_materia' + ].initial = self.instance.materia_de_vinculo.ano if self.proposicao_incorporacao_obrigatoria == 'C': self.fields['gerar_protocolo'].initial = True @@ -1148,8 +1155,8 @@ class ConfirmarProposicaoForm(ProposicaoForm): raise ValidationError( _('Regimente de Tramitação deve ser informado.')) - elif self.instance.tipo.content_type.model_class() == TipoDocumento\ - and not cd['materia_de_vinculo']: + elif self.instance.tipo.content_type.model_class( + ) == TipoDocumento and not cd['materia_de_vinculo']: raise ValidationError( _('Documentos não podem ser incorporados sem definir ' @@ -1216,7 +1223,8 @@ class ConfirmarProposicaoForm(ProposicaoForm): proposicao = self.instance conteudo_gerado = None - if self.instance.tipo.content_type.model_class() == TipoMateriaLegislativa: + if self.instance.tipo.content_type.model_class( + ) == TipoMateriaLegislativa: numero__max = MateriaLegislativa.objects.filter( tipo=proposicao.tipo.tipo_conteudo_related, ano=datetime.now().year).aggregate(Max('numero')) @@ -1349,7 +1357,8 @@ class ConfirmarProposicaoForm(ProposicaoForm): protocolo.numero_paginas = cd['numero_de_paginas'] protocolo.anulado = False - if self.instance.tipo.content_type.model_class() == TipoMateriaLegislativa: + if self.instance.tipo.content_type.model_class( + ) == TipoMateriaLegislativa: protocolo.tipo_materia = proposicao.tipo.tipo_conteudo_related elif self.instance.tipo.content_type.model_class() == TipoDocumento: protocolo.tipo_documento = proposicao.tipo.tipo_conteudo_related diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 32d8fb486..589f039ce 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -1,9 +1,5 @@ -import datetime -import re - from django.contrib.auth.models import Group -from django.contrib.contenttypes.fields import GenericForeignKey,\ - GenericRelation +from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.models import ContentType from django.db import models from django.db.models.deletion import PROTECT @@ -14,10 +10,9 @@ from sapl.base.models import Autor from sapl.comissoes.models import Comissao from sapl.compilacao.models import TextoArticulado from sapl.parlamentares.models import Parlamentar -from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, - restringe_tipos_de_arquivo_txt, SaplGenericRelation, - SaplGenericForeignKey, texto_upload_path) - +from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, SaplGenericForeignKey, + SaplGenericRelation, restringe_tipos_de_arquivo_txt, + texto_upload_path) EM_TRAMITACAO = [(1, 'Sim'), (0, 'Não')] diff --git a/sapl/materia/tests/test_materia.py b/sapl/materia/tests/test_materia.py index d6031c442..19c0c9fa6 100644 --- a/sapl/materia/tests/test_materia.py +++ b/sapl/materia/tests/test_materia.py @@ -1,9 +1,9 @@ +import pytest from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse from model_mommy import mommy -import pytest from sapl.base.models import Autor, TipoAutor from sapl.comissoes.models import Comissao, TipoComissao diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 3fc9c8048..ec535447c 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -6,49 +6,43 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin -from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist,\ - PermissionDenied +from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail from django.core.urlresolvers import reverse -from django.db.models import Q from django.http import JsonResponse -from django.http.response import HttpResponseRedirect, Http404 +from django.http.response import Http404, HttpResponseRedirect from django.shortcuts import redirect from django.template import Context, loader -from django.utils import dateformat, formats -from django.utils.http import urlsafe_base64_decode +from django.utils import formats from django.utils.translation import ugettext_lazy as _ from django.views.generic import CreateView, ListView, TemplateView, UpdateView from django.views.generic.base import RedirectView from django.views.generic.edit import FormView from django_filters.views import FilterView -from sapl.base.models import Autor, CasaLegislativa, TipoAutor +import sapl +from sapl.base.models import Autor, CasaLegislativa from sapl.compilacao.views import IntegracaoTaView from sapl.crispy_layout_mixin import SaplFormLayout, form_actions from sapl.crud.base import (ACTION_CREATE, ACTION_DELETE, ACTION_DETAIL, ACTION_LIST, ACTION_UPDATE, RP_DETAIL, RP_LIST, - Crud, CrudAux, CrudDetailView, MasterDetailCrud, - make_pagination, PermissionRequiredForAppCrudMixin) + Crud, CrudAux, MasterDetailCrud, + PermissionRequiredForAppCrudMixin, make_pagination) from sapl.materia import apps -from sapl.materia.forms import AnexadaForm, LegislacaoCitadaForm,\ - TipoProposicaoForm, ProposicaoForm, ConfirmarProposicaoForm +from sapl.materia.forms import (AnexadaForm, ConfirmarProposicaoForm, + LegislacaoCitadaForm, ProposicaoForm, + TipoProposicaoForm) from sapl.norma.models import LegislacaoCitada from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, autor_modal, gerar_hash_arquivo, get_base_url, montar_row_autor, permission_required_for_app, permissoes_autor, permissoes_materia, - permissoes_protocoloadm, permission_required_for_app, - montar_row_autor) -import sapl - + permissoes_protocoloadm) from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, - DocumentoAcessorioForm, - MateriaLegislativaFilterSet, - PrimeiraTramitacaoEmLoteFilterSet, ProposicaoOldForm, - ReceberProposicaoForm, TramitacaoEmLoteFilterSet, - filtra_tramitacao_destino, + DocumentoAcessorioForm, MateriaLegislativaFilterSet, + PrimeiraTramitacaoEmLoteFilterSet, ReceberProposicaoForm, + TramitacaoEmLoteFilterSet, filtra_tramitacao_destino, filtra_tramitacao_destino_and_status, filtra_tramitacao_status) from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, @@ -58,7 +52,6 @@ from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, TipoMateriaLegislativa, TipoProposicao, Tramitacao, UnidadeTramitacao) - OrigemCrud = Crud.build(Origem, '') TipoMateriaCrud = CrudAux.build( diff --git a/sapl/norma/models.py b/sapl/norma/models.py index 23ba2d761..a9fa72780 100644 --- a/sapl/norma/models.py +++ b/sapl/norma/models.py @@ -143,8 +143,6 @@ class AssuntoNormaRelationship(models.Model): unique_together = ( ('assunto', 'norma'), ) - - class Meta: verbose_name = _('Assunto') verbose_name_plural = _('Assuntos') diff --git a/sapl/protocoloadm/models.py b/sapl/protocoloadm/models.py index 963ae4ae8..972fe53c4 100644 --- a/sapl/protocoloadm/models.py +++ b/sapl/protocoloadm/models.py @@ -1,13 +1,9 @@ -from uuid import uuid4 - from django.db import models from django.utils.translation import ugettext_lazy as _ from model_utils import Choices from sapl.base.models import Autor - -from sapl.materia.models import (TipoMateriaLegislativa, - UnidadeTramitacao) +from sapl.materia.models import TipoMateriaLegislativa, UnidadeTramitacao from sapl.utils import RANGE_ANOS, YES_NO_CHOICES, texto_upload_path diff --git a/sapl/protocoloadm/tests/test_protocoloadm.py b/sapl/protocoloadm/tests/test_protocoloadm.py index ea012b47f..66a2409f8 100644 --- a/sapl/protocoloadm/tests/test_protocoloadm.py +++ b/sapl/protocoloadm/tests/test_protocoloadm.py @@ -1,10 +1,10 @@ import datetime +import pytest from django.core.urlresolvers import reverse from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ from model_mommy import mommy -import pytest from sapl.materia.models import UnidadeTramitacao from sapl.protocoloadm.forms import AnularProcoloAdmForm diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 1091c7785..961ff01ab 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -12,12 +12,11 @@ from django.views.generic import CreateView, DetailView, FormView, ListView from django.views.generic.base import TemplateView from django_filters.views import FilterView +import sapl from sapl.crud.base import Crud, CrudAux, MasterDetailCrud, make_pagination from sapl.materia.models import TipoMateriaLegislativa -from sapl.protocoloadm.apps import AppConfig from sapl.utils import (create_barcode, get_client_ip, permissoes_adm, - permissoes_protocoloadm, permission_required_for_app) -import sapl + permissoes_protocoloadm) from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoFilterSet, @@ -28,7 +27,6 @@ from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, StatusTramitacaoAdministrativo, TipoDocumentoAdministrativo, TramitacaoAdministrativo) - TipoDocumentoAdministrativoCrud = CrudAux.build( TipoDocumentoAdministrativo, '') @@ -49,7 +47,8 @@ class DocumentoAdministrativoMixin: if app_config and app_config.documentos_administrativos == 'O': return True - return self.request.user.has_module_perms(sapl.base.models.AppConfig.label) + return self.request.user.has_module_perms( + sapl.base.models.AppConfig.label) class DocumentoAdministrativoCrud(Crud): diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index c574827a0..ac10778aa 100644 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -19,7 +19,6 @@ from sapl.sessao.models import (ExpedienteMateria, ExpedienteSessao, Orador, SessaoPlenariaPresenca, TipoExpediente) from sapl.settings import STATIC_ROOT from sapl.utils import UF -import sapl from .templates import (pdf_capa_processo_gerar, pdf_documento_administrativo_gerar, pdf_espelho_gerar, @@ -27,7 +26,6 @@ from .templates import (pdf_capa_processo_gerar, pdf_ordem_dia_gerar, pdf_pauta_sessao_gerar, pdf_protocolo_gerar, pdf_sessao_plenaria_gerar) - uf_dic = dict(UF) diff --git a/sapl/rules/apps.py b/sapl/rules/apps.py index 1df046f3a..affce7bec 100644 --- a/sapl/rules/apps.py +++ b/sapl/rules/apps.py @@ -1,19 +1,20 @@ from builtins import LookupError +import django from django.apps import apps from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.management import _get_all_permissions from django.core import exceptions -from django.db import router, models -from django.db.models.signals import post_migrate +from django.db import models, router from django.db.utils import DEFAULT_DB_ALIAS -from django.utils.translation import string_concat from django.utils.translation import ugettext_lazy as _ -import django -from sapl.rules import SAPL_GROUP_ADMINISTRATIVO, SAPL_GROUP_COMISSOES,\ - SAPL_GROUP_GERAL, SAPL_GROUP_MATERIA, SAPL_GROUP_NORMA, SAPL_GROUP_PAINEL,\ - SAPL_GROUP_PROTOCOLO, SAPL_GROUP_SESSAO +from django.utils.translation import string_concat + +from sapl.rules import (SAPL_GROUP_ADMINISTRATIVO, SAPL_GROUP_COMISSOES, + SAPL_GROUP_GERAL, SAPL_GROUP_MATERIA, SAPL_GROUP_NORMA, + SAPL_GROUP_PAINEL, SAPL_GROUP_PROTOCOLO, + SAPL_GROUP_SESSAO) class AppConfig(django.apps.AppConfig): @@ -131,7 +132,8 @@ def update_groups(app_config, verbosity=2, interactive=True, def associar(self, g, model, tipo): for t in tipo: content_type = ContentType.objects.get_by_natural_key( - app_label=model._meta.app_label, model=model._meta.model_name) + app_label=model._meta.app_label, + model=model._meta.model_name) codename = (t[1:] + model._meta.model_name)\ if t[0] == '.' and t[-1] == '_' else t @@ -185,7 +187,8 @@ def update_groups(app_config, verbosity=2, interactive=True, if not isinstance(groups_name, list): groups_name = [groups_name, ] for group_name in groups_name: - if not group_name or user.groups.filter(name=group_name).exists(): + if not group_name or user.groups.filter( + name=group_name).exists(): continue g = Group.objects.get_or_create(name=group_name)[0] user.groups.add(g) diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index 981646d08..fcee49c86 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -1,24 +1,21 @@ - -from django.utils.translation import ugettext_lazy as _ - from sapl.base import models as base from sapl.comissoes import models as comissoes from sapl.compilacao import models as compilacao -from sapl.crud.base import RP_LIST, RP_DETAIL, RP_ADD, RP_CHANGE, RP_DELETE +from sapl.crud.base import RP_ADD, RP_CHANGE, RP_DELETE, RP_DETAIL, RP_LIST from sapl.lexml import models as lexml from sapl.materia import models as materia from sapl.norma import models as norma from sapl.painel import models as painel from sapl.parlamentares import models as parlamentares from sapl.protocoloadm import models as protocoloadm -from sapl.rules import SAPL_GROUP_ADMINISTRATIVO, SAPL_GROUP_GERAL,\ - SAPL_GROUP_PROTOCOLO, SAPL_GROUP_COMISSOES, SAPL_GROUP_MATERIA,\ - SAPL_GROUP_ANONYMOUS, SAPL_GROUP_LOGIN_SOCIAL, SAPL_GROUP_NORMA,\ - SAPL_GROUP_AUTOR, SAPL_GROUP_PAINEL, SAPL_GROUP_SESSAO,\ - SAPL_GROUP_PARLAMENTAR +from sapl.rules import (SAPL_GROUP_ADMINISTRATIVO, SAPL_GROUP_ANONYMOUS, + SAPL_GROUP_AUTOR, SAPL_GROUP_COMISSOES, + SAPL_GROUP_GERAL, SAPL_GROUP_LOGIN_SOCIAL, + SAPL_GROUP_MATERIA, SAPL_GROUP_NORMA, + SAPL_GROUP_PAINEL, SAPL_GROUP_PARLAMENTAR, + SAPL_GROUP_PROTOCOLO, SAPL_GROUP_SESSAO) from sapl.sessao import models as sessao - # RP = Radicao de Permissão __base__ = [RP_LIST, RP_DETAIL, RP_ADD, RP_CHANGE, RP_DELETE] __listdetailchange__ = [RP_LIST, RP_DETAIL, RP_CHANGE] diff --git a/sapl/rules/tests/test_rules.py b/sapl/rules/tests/test_rules.py index 527e1f693..359c7d6d8 100644 --- a/sapl/rules/tests/test_rules.py +++ b/sapl/rules/tests/test_rules.py @@ -1,15 +1,14 @@ +import pytest from django.apps import apps from django.conf import settings from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext_lazy as _ -import pytest from sapl.rules import SAPL_GROUPS from sapl.rules.map_rules import rules_patterns from sapl.test_urls import create_perms_post_migrate - sapl_appconfs = [apps.get_app_config(n[5:]) for n in settings.SAPL_APPS] sapl_models = [] diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 9c7ca77dc..f3e39c46c 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -2,7 +2,7 @@ from datetime import datetime from re import sub from django.contrib import messages -from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.forms.utils import ErrorList from django.http import JsonResponse diff --git a/sapl/test_urls.py b/sapl/test_urls.py index c73b15ed9..c38355126 100644 --- a/sapl/test_urls.py +++ b/sapl/test_urls.py @@ -1,20 +1,19 @@ +import pytest from django.apps import apps from django.contrib.auth import get_user_model from django.contrib.auth.management import _get_all_permissions from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.db import transaction -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.rules.apps import update_groups, AppConfig +from sapl.rules.apps import AppConfig, update_groups 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/urls.py b/sapl/urls.py index 0bdaf19fa..649265aaa 100644 --- a/sapl/urls.py +++ b/sapl/urls.py @@ -33,7 +33,6 @@ import sapl.protocoloadm.urls import sapl.relatorios.urls import sapl.sessao.urls - urlpatterns = [ url(r'^$', TemplateView.as_view(template_name='index.html')), url(r'^admin/', include(admin.site.urls)), diff --git a/sapl/utils.py b/sapl/utils.py index 86dd66169..efc2d2ae0 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,12 +1,11 @@ -from datetime import date -from functools import wraps -from unicodedata import normalize as unicodedata_normalize import hashlib -import hashlib -import logging import logging import re +from datetime import date +from functools import wraps +from unicodedata import normalize as unicodedata_normalize +import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms @@ -15,19 +14,16 @@ from django.conf import settings from django.contrib import admin from django.contrib.auth.decorators import user_passes_test from django.contrib.auth.models import Permission -from django.contrib.contenttypes.fields import GenericRelation, GenericRel,\ - GenericForeignKey +from django.contrib.contenttypes.fields import (GenericForeignKey, GenericRel, + GenericRelation) from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied, ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput -import magic -import magic from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR - sapl_logger = logging.getLogger(BASE_DIR.name) @@ -102,7 +98,12 @@ def montar_helper_autor(self): class SaplGenericForeignKey(GenericForeignKey): - def __init__(self, ct_field='content_type', fk_field='object_id', for_concrete_model=True, verbose_name=''): + def __init__( + self, + ct_field='content_type', + fk_field='object_id', + for_concrete_model=True, + verbose_name=''): super().__init__(ct_field, fk_field, for_concrete_model) self.verbose_name = verbose_name