Browse Source

add hook_ em Details do Crud

pull/2996/head
Leandro Roberto 5 years ago
parent
commit
5026633cc7
  1. 5
      sapl/crispy_layout_mixin.py
  2. 14
      sapl/crud/base.py

5
sapl/crispy_layout_mixin.py

@ -257,6 +257,11 @@ class CrispyLayoutFormMixin:
if func:
verbose_name, text = getattr(self, func)(obj, fieldname)
else:
hook_fieldname = 'hook_%s' % fieldname
if hasattr(self, hook_fieldname):
verbose_name, text = getattr(
self, hook_fieldname)(obj)
else:
verbose_name, text = get_field_display(obj, fieldname)

14
sapl/crud/base.py

@ -30,10 +30,8 @@ from sapl.rules.map_rules import (RP_ADD, RP_CHANGE, RP_DELETE, RP_DETAIL,
RP_LIST)
from sapl.utils import normalize
logger = logging.getLogger(settings.BASE_DIR.name)
ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \
'list', 'create', 'detail', 'update', 'delete'
@ -82,7 +80,6 @@ def make_pagination(index, num_pages):
head = from_to(1, PAGINATION_LENGTH - len(tail) - 1)
return head + [None] + tail
"""
variáveis do crud:
help_topic
@ -392,6 +389,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
@classmethod
def get_url_regex(cls):
return r'^$'
paginate_by = 10
no_entries_msg = _('Nenhum registro encontrado.')
@ -423,7 +421,13 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
if hasattr(f, 'related_model') and f.related_model:
m = f.related_model
if f:
hook = 'hook_header_{}'.format(''.join(fn))
if hasattr(self, hook):
header = getattr(self, hook)()
s.append(header)
else:
s.append(force_text(f.verbose_name))
s = ' / '.join(s)
r.append(s)
return r
@ -958,10 +962,12 @@ class Crud:
def _add_base(view):
if view:
class CrudViewWithBase(cls.BaseMixin, view):
model = cls.model
help_topic = cls.help_topic
crud = cls
CrudViewWithBase.__name__ = view.__name__
return CrudViewWithBase
@ -995,11 +1001,13 @@ class Crud:
def build(cls, _model, _help_topic, _model_set=None, list_field_names=[]):
def create_class(_list_field_names):
class ModelCrud(cls):
model = _model
model_set = _model_set
help_topic = _help_topic
list_field_names = _list_field_names
return ModelCrud
ModelCrud = create_class(list_field_names)

Loading…
Cancel
Save