Browse Source

Simplifica propriedades constantes

pull/1765/head
Marcio Mazza 7 years ago
parent
commit
3b6134a4c9
  1. 9
      sapl/base/views.py
  2. 16
      sapl/materia/views.py
  3. 16
      sapl/norma/views.py
  4. 8
      sapl/parlamentares/views.py
  5. 4
      sapl/protocoloadm/views.py
  6. 12
      sapl/sessao/views.py
  7. 21
      scripts/redbaron.py

9
sapl/base/views.py

@ -683,13 +683,8 @@ class AppConfigCrud(CrudAux):
class BaseMixin(CrudAux.BaseMixin): class BaseMixin(CrudAux.BaseMixin):
form_class = ConfiguracoesAppForm form_class = ConfiguracoesAppForm
@property list_url = ''
def list_url(self): create_url = ''
return ''
@property
def create_url(self):
return ''
class CreateView(CrudAux.CreateView): class CreateView(CrudAux.CreateView):

16
sapl/materia/views.py

@ -1055,9 +1055,7 @@ class TramitacaoCrud(MasterDetailCrud):
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoUpdateForm form_class = TramitacaoUpdateForm
@property layout_key = 'TramitacaoUpdate'
def layout_key(self):
return 'TramitacaoUpdate'
def form_valid(self, form): def form_valid(self, form):
self.object = form.save() self.object = form.save()
@ -1281,9 +1279,7 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@property layout_key = 'LegislacaoCitadaDetail'
def layout_key(self):
return 'LegislacaoCitadaDetail'
class DeleteView(MasterDetailCrud.DeleteView): class DeleteView(MasterDetailCrud.DeleteView):
pass pass
@ -1357,9 +1353,7 @@ class MateriaLegislativaCrud(Crud):
class BaseMixin(Crud.BaseMixin): class BaseMixin(Crud.BaseMixin):
list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao'] list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao']
@property list_url = ''
def list_url(self):
return ''
@property @property
def search_url(self): def search_url(self):
@ -1389,9 +1383,7 @@ class MateriaLegislativaCrud(Crud):
class DetailView(Crud.DetailView): class DetailView(Crud.DetailView):
@property layout_key = 'MateriaLegislativaDetail'
def layout_key(self):
return 'MateriaLegislativaDetail'
class ListView(Crud.ListView, RedirectView): class ListView(Crud.ListView, RedirectView):

16
sapl/norma/views.py

@ -60,9 +60,7 @@ class NormaRelacionadaCrud(MasterDetailCrud):
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@property layout_key = 'NormaRelacionadaDetail'
def layout_key(self):
return 'NormaRelacionadaDetail'
class NormaPesquisaView(FilterView): class NormaPesquisaView(FilterView):
@ -135,9 +133,7 @@ class NormaCrud(Crud):
class BaseMixin(Crud.BaseMixin): class BaseMixin(Crud.BaseMixin):
list_field_names = ['tipo', 'numero', 'ano', 'ementa'] list_field_names = ['tipo', 'numero', 'ano', 'ementa']
@property list_url = ''
def list_url(self):
return ''
@property @property
def search_url(self): def search_url(self):
@ -159,9 +155,7 @@ class NormaCrud(Crud):
def cancel_url(self): def cancel_url(self):
return self.search_url return self.search_url
@property layout_key = 'NormaJuridicaCreate'
def layout_key(self):
return 'NormaJuridicaCreate'
class ListView(Crud.ListView, RedirectView): class ListView(Crud.ListView, RedirectView):
@ -175,9 +169,7 @@ class NormaCrud(Crud):
class UpdateView(Crud.UpdateView): class UpdateView(Crud.UpdateView):
form_class = NormaJuridicaForm form_class = NormaJuridicaForm
@property layout_key = 'NormaJuridicaCreate'
def layout_key(self):
return 'NormaJuridicaCreate'
def get_initial(self): def get_initial(self):
norma = NormaJuridica.objects.get(id=self.kwargs['pk']) norma = NormaJuridica.objects.get(id=self.kwargs['pk'])

8
sapl/parlamentares/views.py

@ -420,16 +420,12 @@ class ParlamentarCrud(Crud):
class UpdateView(Crud.UpdateView): class UpdateView(Crud.UpdateView):
form_class = ParlamentarForm form_class = ParlamentarForm
@property layout_key = 'ParlamentarUpdate'
def layout_key(self):
return 'ParlamentarUpdate'
class CreateView(Crud.CreateView): class CreateView(Crud.CreateView):
form_class = ParlamentarCreateForm form_class = ParlamentarCreateForm
@property layout_key = 'ParlamentarCreate'
def layout_key(self):
return 'ParlamentarCreate'
def form_valid(self, form): def form_valid(self, form):
""" """

4
sapl/protocoloadm/views.py

@ -93,9 +93,7 @@ class DocumentoAdministrativoCrud(Crud):
namespace = self.model._meta.app_config.name namespace = self.model._meta.app_config.name
return reverse('%s:%s' % (namespace, 'pesq_doc_adm')) return reverse('%s:%s' % (namespace, 'pesq_doc_adm'))
@property list_url = ''
def list_url(self):
return ''
class ListView(RedirectView, DocumentoAdministrativoMixin, Crud.ListView): class ListView(RedirectView, DocumentoAdministrativoMixin, Crud.ListView):

12
sapl/sessao/views.py

@ -256,9 +256,7 @@ class MateriaOrdemDiaCrud(MasterDetailCrud):
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@property layout_key = 'OrdemDiaDetail'
def layout_key(self):
return 'OrdemDiaDetail'
class ListView(MasterDetailCrud.ListView): class ListView(MasterDetailCrud.ListView):
paginate_by = None paginate_by = None
@ -530,9 +528,7 @@ class ExpedienteMateriaCrud(MasterDetailCrud):
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@property layout_key = 'ExpedienteMateriaDetail'
def layout_key(self):
return 'ExpedienteMateriaDetail'
class OradorCrud(MasterDetailCrud): class OradorCrud(MasterDetailCrud):
@ -638,9 +634,7 @@ class SessaoCrud(Crud):
list_field_names = ['data_inicio', 'legislatura', 'sessao_legislativa', list_field_names = ['data_inicio', 'legislatura', 'sessao_legislativa',
'tipo'] 'tipo']
@property list_url = ''
def list_url(self):
return ''
@property @property
def search_url(self): def search_url(self):

21
scripts/redbaron.py

@ -2,6 +2,7 @@ import os
import re import re
from redbaron import RedBaron from redbaron import RedBaron
from redbaron.nodes import EndlNode, ReturnNode, StringNode
root = '/home/mazza/work/sapl' root = '/home/mazza/work/sapl'
@ -85,3 +86,23 @@ def local(node):
node.absolute_bounding_box.top_left.line) node.absolute_bounding_box.top_left.line)
os.system("echo '%s' | xclip -selection c" % res) os.system("echo '%s' | xclip -selection c" % res)
return 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)

Loading…
Cancel
Save