From 3b6134a4c9865a42c6feb4450b0a8a0b1d372fce Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Mon, 12 Mar 2018 13:52:20 -0300 Subject: [PATCH] Simplifica propriedades constantes --- sapl/base/views.py | 9 ++------- sapl/materia/views.py | 16 ++++------------ sapl/norma/views.py | 16 ++++------------ sapl/parlamentares/views.py | 8 ++------ sapl/protocoloadm/views.py | 4 +--- sapl/sessao/views.py | 12 +++--------- scripts/redbaron.py | 21 +++++++++++++++++++++ 7 files changed, 37 insertions(+), 49 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index 2240a71ba..bcfc94635 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -683,13 +683,8 @@ class AppConfigCrud(CrudAux): class BaseMixin(CrudAux.BaseMixin): form_class = ConfiguracoesAppForm - @property - def list_url(self): - return '' - - @property - def create_url(self): - return '' + list_url = '' + create_url = '' class CreateView(CrudAux.CreateView): diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 81a4dfcd1..31ce86c43 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1055,9 +1055,7 @@ class TramitacaoCrud(MasterDetailCrud): class UpdateView(MasterDetailCrud.UpdateView): form_class = TramitacaoUpdateForm - @property - def layout_key(self): - return 'TramitacaoUpdate' + layout_key = 'TramitacaoUpdate' def form_valid(self, form): self.object = form.save() @@ -1281,9 +1279,7 @@ class LegislacaoCitadaCrud(MasterDetailCrud): class DetailView(MasterDetailCrud.DetailView): - @property - def layout_key(self): - return 'LegislacaoCitadaDetail' + layout_key = 'LegislacaoCitadaDetail' class DeleteView(MasterDetailCrud.DeleteView): pass @@ -1357,9 +1353,7 @@ class MateriaLegislativaCrud(Crud): class BaseMixin(Crud.BaseMixin): list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao'] - @property - def list_url(self): - return '' + list_url = '' @property def search_url(self): @@ -1389,9 +1383,7 @@ class MateriaLegislativaCrud(Crud): class DetailView(Crud.DetailView): - @property - def layout_key(self): - return 'MateriaLegislativaDetail' + layout_key = 'MateriaLegislativaDetail' class ListView(Crud.ListView, RedirectView): diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 73e259a33..d74bc8857 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -60,9 +60,7 @@ class NormaRelacionadaCrud(MasterDetailCrud): class DetailView(MasterDetailCrud.DetailView): - @property - def layout_key(self): - return 'NormaRelacionadaDetail' + layout_key = 'NormaRelacionadaDetail' class NormaPesquisaView(FilterView): @@ -135,9 +133,7 @@ class NormaCrud(Crud): class BaseMixin(Crud.BaseMixin): list_field_names = ['tipo', 'numero', 'ano', 'ementa'] - @property - def list_url(self): - return '' + list_url = '' @property def search_url(self): @@ -159,9 +155,7 @@ class NormaCrud(Crud): def cancel_url(self): return self.search_url - @property - def layout_key(self): - return 'NormaJuridicaCreate' + layout_key = 'NormaJuridicaCreate' class ListView(Crud.ListView, RedirectView): @@ -175,9 +169,7 @@ class NormaCrud(Crud): class UpdateView(Crud.UpdateView): form_class = NormaJuridicaForm - @property - def layout_key(self): - return 'NormaJuridicaCreate' + layout_key = 'NormaJuridicaCreate' def get_initial(self): norma = NormaJuridica.objects.get(id=self.kwargs['pk']) diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 8baaadda2..078483f35 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -420,16 +420,12 @@ class ParlamentarCrud(Crud): class UpdateView(Crud.UpdateView): form_class = ParlamentarForm - @property - def layout_key(self): - return 'ParlamentarUpdate' + layout_key = 'ParlamentarUpdate' class CreateView(Crud.CreateView): form_class = ParlamentarCreateForm - @property - def layout_key(self): - return 'ParlamentarCreate' + layout_key = 'ParlamentarCreate' def form_valid(self, form): """ diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index b92975744..ee03daaff 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -93,9 +93,7 @@ class DocumentoAdministrativoCrud(Crud): namespace = self.model._meta.app_config.name return reverse('%s:%s' % (namespace, 'pesq_doc_adm')) - @property - def list_url(self): - return '' + list_url = '' class ListView(RedirectView, DocumentoAdministrativoMixin, Crud.ListView): diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 57fa69c09..0e715e514 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -256,9 +256,7 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): class DetailView(MasterDetailCrud.DetailView): - @property - def layout_key(self): - return 'OrdemDiaDetail' + layout_key = 'OrdemDiaDetail' class ListView(MasterDetailCrud.ListView): paginate_by = None @@ -530,9 +528,7 @@ class ExpedienteMateriaCrud(MasterDetailCrud): class DetailView(MasterDetailCrud.DetailView): - @property - def layout_key(self): - return 'ExpedienteMateriaDetail' + layout_key = 'ExpedienteMateriaDetail' class OradorCrud(MasterDetailCrud): @@ -638,9 +634,7 @@ class SessaoCrud(Crud): list_field_names = ['data_inicio', 'legislatura', 'sessao_legislativa', 'tipo'] - @property - def list_url(self): - return '' + list_url = '' @property def search_url(self): diff --git a/scripts/redbaron.py b/scripts/redbaron.py index c3d0894df..3229872bc 100644 --- a/scripts/redbaron.py +++ b/scripts/redbaron.py @@ -2,6 +2,7 @@ import os import re from redbaron import RedBaron +from redbaron.nodes import EndlNode, ReturnNode, StringNode root = '/home/mazza/work/sapl' @@ -85,3 +86,23 @@ def local(node): node.absolute_bounding_box.top_left.line) os.system("echo '%s' | xclip -selection c" % res) return res + + +def acha_props_constantes(red): + "Enumera nós property que apenas retornam uma constante" + for fun in red('def'): + if fun.decorators.dumps().strip() == '@property': + nos = [n for n in fun.value if not isinstance(n, EndlNode)] + if len(nos) == 1: + [ret] = nos + if (isinstance(ret, ReturnNode) + and isinstance(ret.value, StringNode)): + yield fun + + +def corrige_props_constantes(reds): + "Troca nós property que apenas retornam uma constante por um assign" + pp = [p for red in reds for p in acha_props_constantes(red)] + for p in pp: + p.parent.value[p.index_on_parent] = '{} = {}'.format(p.name, p('return')('string').dumps()) + write(p)