From abf789778e5c3ee50c1c43c354427b8e8c691138 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Mon, 3 Oct 2016 19:27:30 -0300 Subject: [PATCH] fix qa --- sapl/base/models.py | 3 +-- sapl/base/templatetags/menus.py | 2 +- sapl/comissoes/views.py | 8 +++----- sapl/crispy_layout_mixin.py | 2 +- sapl/crud/base.py | 3 +-- sapl/materia/forms.py | 3 +-- sapl/materia/views.py | 10 ++++------ sapl/norma/views.py | 4 +--- sapl/sessao/views.py | 19 ++++++++----------- sapl/utils.py | 6 +++--- scripts/inicializa_grupos_autorizacoes.py | 2 +- .../test_inicializa_grupos_autorizacoes.py | 6 ++---- 12 files changed, 27 insertions(+), 41 deletions(-) diff --git a/sapl/base/models.py b/sapl/base/models.py index a0a902702..71f2634fe 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -7,12 +7,11 @@ 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.utils.translation import ugettext_lazy as _ +from django.utils.translation import string_concat from sapl.utils import UF, YES_NO_CHOICES - TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')), ('R', _('Restritivo'))) diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 56a301a6a..61c468acf 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -19,7 +19,7 @@ def subnav(context, path=None): Os campos esperados nos arquivos yaml são: title url - check_permission - opcional. quando usado + check_permission - opcional. quando usado será realizado o teste de permissão para renderizá-lo. """ menu = None diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 277714460..ae11cdbf7 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -73,11 +73,9 @@ class MateriasTramitacaoListView(ListView): for materia in materias: comissao = materia.tramitacao_set.last( ).unidade_tramitacao_destino.comissao - if (comissao and - materia not in lista and - comissao.pk == int(self.kwargs['pk']) - ): - lista.append(materia) + if (comissao and materia not in lista and + comissao.pk == int(self.kwargs['pk'])): + lista.append(materia) return lista def get_context_data(self, **kwargs): diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index ebc570394..e0184e0f0 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 c6283aa5c..97aef7461 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -13,8 +13,8 @@ from django.db import models 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 @@ -23,7 +23,6 @@ from django.views.generic.list import MultipleObjectMixin from sapl.crispy_layout_mixin import CrispyLayoutFormMixin, get_field_display from sapl.utils import normalize - logger = logging.getLogger(__name__) ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \ diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index c33c5bc7b..f4f054c6e 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 @@ -11,7 +12,6 @@ from django.db import models, transaction from django.db.models import Max from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ -import django_filters from sapl.comissoes.models import Comissao from sapl.crispy_layout_mixin import form_actions, to_row @@ -27,7 +27,6 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao) - ANO_CHOICES = [('', '---------')] + RANGE_ANOS diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 3b12c145e..132f48fac 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -26,10 +26,10 @@ from django_filters.views import FilterView from sapl.base.models import CasaLegislativa from sapl.compilacao.views import IntegracaoTaView from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row -from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, CrudDetailView, - MasterDetailCrud, make_pagination, - ACTION_CREATE, ACTION_UPDATE, ACTION_LIST, - ACTION_DELETE, ACTION_DETAIL) +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) from sapl.materia.forms import AnexadaForm, LegislacaoCitadaForm from sapl.norma.models import LegislacaoCitada from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, @@ -52,8 +52,6 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, Tramitacao, UnidadeTramitacao) - -#AnexadaCrud = Crud.build(Anexada, '') OrigemCrud = Crud.build(Origem, '') TipoMateriaCrud = CrudAux.build( diff --git a/sapl/norma/views.py b/sapl/norma/views.py index c2dd31724..47813a3b0 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -8,9 +8,7 @@ from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, make_pagination from sapl.norma.forms import NormaJuridicaForm from .forms import NormaJuridicaPesquisaForm -from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, - TipoNormaJuridica) - +from .models import AssuntoNorma, NormaJuridica, TipoNormaJuridica # LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 1116472fb..1a5c446de 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -2,8 +2,6 @@ from datetime import datetime from re import sub from django.contrib import messages -from django.contrib.auth.decorators import permission_required -from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.urlresolvers import reverse from django.forms.utils import ErrorList @@ -21,8 +19,8 @@ from rest_framework import generics from sapl.base.models import AppConfig as AppsAppConfig from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, - MasterDetailCrud, make_pagination, - PermissionRequiredForAppCrudMixin) + MasterDetailCrud, + PermissionRequiredForAppCrudMixin, make_pagination) from sapl.materia.forms import pega_ultima_tramitacao from sapl.materia.models import (Autoria, DocumentoAcessorio, TipoMateriaLegislativa, Tramitacao) @@ -33,7 +31,7 @@ from sapl.parlamentares.models import (Legislatura, Parlamentar, from sapl.sessao.apps import AppConfig from sapl.sessao.forms import ExpedienteMateriaForm, OrdemDiaForm from sapl.sessao.serializers import SessaoPlenariaSerializer -from sapl.utils import permissoes_painel, permission_required_for_app +from sapl.utils import permission_required_for_app from .forms import (AdicionarVariasMateriasFilterSet, ExpedienteForm, ListMateriaForm, MesaForm, PautaSessaoFilterSet, @@ -46,9 +44,8 @@ from .models import (Bancada, Bloco, CargoBancada, CargoMesa, SessaoPlenariaPresenca, TipoExpediente, TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar) - -#OrdemDiaCrud = Crud.build(OrdemDia, '') -#RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') +# OrdemDiaCrud = Crud.build(OrdemDia, '') +# RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') TipoExpedienteCrud = CrudAux.build(TipoExpediente, 'tipo_expediente') CargoBancadaCrud = CrudAux.build(CargoBancada, '') @@ -181,9 +178,9 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): 'mid': obj.pk}) if self.request.user.has_module_perms(AppConfig.label): btn_registrar = ''' - Registrar Votação''' % ( + Registrar Votação''' % ( url) obj.resultado = btn_registrar else: diff --git a/sapl/utils.py b/sapl/utils.py index 467d0d2b2..05eed3457 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,8 +1,9 @@ +import hashlib from datetime import date from functools import wraps from unicodedata import normalize as unicodedata_normalize -import hashlib +import magic from django import forms from django.apps import apps from django.conf import settings @@ -10,10 +11,9 @@ 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.models import ContentType -from django.core.exceptions import ValidationError, PermissionDenied +from django.core.exceptions import PermissionDenied, ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput -import magic def normalize(txt): diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index fcd4b3203..c7950ca98 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -1,6 +1,6 @@ import os -import django +import django os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sapl.settings") django.setup() diff --git a/scripts/test_inicializa_grupos_autorizacoes.py b/scripts/test_inicializa_grupos_autorizacoes.py index 07ad2ce10..d9f7d90a2 100644 --- a/scripts/test_inicializa_grupos_autorizacoes.py +++ b/scripts/test_inicializa_grupos_autorizacoes.py @@ -1,16 +1,14 @@ +import pytest from django.apps import apps from django.contrib.auth.management import _get_all_permissions from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ValidationError from django.utils.encoding import force_text -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 inicializa_grupos_autorizacoes import cria_grupos_permissoes - pytestmark = pytest.mark.django_db apps_com_permissao_padrao = [