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):
form_class = ConfiguracoesAppForm
@property
def list_url(self):
return ''
@property
def create_url(self):
return ''
list_url = ''
create_url = ''
class CreateView(CrudAux.CreateView):

16
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):

16
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'])

8
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):
"""

4
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):

12
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):

21
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)

Loading…
Cancel
Save