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. 26
      sapl/crud/base.py

5
sapl/crispy_layout_mixin.py

@ -257,6 +257,11 @@ class CrispyLayoutFormMixin:
if func: if func:
verbose_name, text = getattr(self, func)(obj, fieldname) 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: else:
verbose_name, text = get_field_display(obj, fieldname) verbose_name, text = get_field_display(obj, fieldname)

26
sapl/crud/base.py

@ -30,10 +30,8 @@ from sapl.rules.map_rules import (RP_ADD, RP_CHANGE, RP_DELETE, RP_DETAIL,
RP_LIST) RP_LIST)
from sapl.utils import normalize from sapl.utils import normalize
logger = logging.getLogger(settings.BASE_DIR.name) logger = logging.getLogger(settings.BASE_DIR.name)
ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \ ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \
'list', 'create', 'detail', 'update', '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) head = from_to(1, PAGINATION_LENGTH - len(tail) - 1)
return head + [None] + tail return head + [None] + tail
""" """
variáveis do crud: variáveis do crud:
help_topic help_topic
@ -386,12 +383,13 @@ class CrudBaseMixin(CrispyLayoutFormMixin):
class CrudListView(PermissionRequiredContainerCrudMixin, ListView): class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
permission_required = (RP_LIST, ) permission_required = (RP_LIST,)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@classmethod @classmethod
def get_url_regex(cls): def get_url_regex(cls):
return r'^$' return r'^$'
paginate_by = 10 paginate_by = 10
no_entries_msg = _('Nenhum registro encontrado.') no_entries_msg = _('Nenhum registro encontrado.')
@ -423,7 +421,13 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
if hasattr(f, 'related_model') and f.related_model: if hasattr(f, 'related_model') and f.related_model:
m = f.related_model m = f.related_model
if f: 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.append(force_text(f.verbose_name))
s = ' / '.join(s) s = ' / '.join(s)
r.append(s) r.append(s)
return r return r
@ -598,7 +602,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
model_ordering = (model_ordering,) model_ordering = (model_ordering,)
for mo in model_ordering: for mo in model_ordering:
if mo not in ordering: if mo not in ordering:
ordering = ordering + (mo, ) ordering = ordering + (mo,)
queryset = queryset.order_by(*ordering) queryset = queryset.order_by(*ordering)
# print(ordering) # print(ordering)
@ -649,7 +653,7 @@ class AuditLogMixin(object):
class CrudCreateView(PermissionRequiredContainerCrudMixin, class CrudCreateView(PermissionRequiredContainerCrudMixin,
FormMessagesMixin, AuditLogMixin, CreateView): FormMessagesMixin, AuditLogMixin, CreateView):
permission_required = (RP_ADD, ) permission_required = (RP_ADD,)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@classmethod @classmethod
@ -721,7 +725,7 @@ class CrudCreateView(PermissionRequiredContainerCrudMixin,
class CrudDetailView(PermissionRequiredContainerCrudMixin, class CrudDetailView(PermissionRequiredContainerCrudMixin,
DetailView, MultipleObjectMixin): DetailView, MultipleObjectMixin):
permission_required = (RP_DETAIL, ) permission_required = (RP_DETAIL,)
no_entries_msg = _('Nenhum registro Associado.') no_entries_msg = _('Nenhum registro Associado.')
paginate_by = 10 paginate_by = 10
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -867,7 +871,7 @@ class CrudDetailView(PermissionRequiredContainerCrudMixin,
class CrudUpdateView(PermissionRequiredContainerCrudMixin, class CrudUpdateView(PermissionRequiredContainerCrudMixin,
FormMessagesMixin, AuditLogMixin, UpdateView): FormMessagesMixin, AuditLogMixin, UpdateView):
permission_required = (RP_CHANGE, ) permission_required = (RP_CHANGE,)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def form_valid(self, form): def form_valid(self, form):
@ -898,7 +902,7 @@ class CrudUpdateView(PermissionRequiredContainerCrudMixin,
class CrudDeleteView(PermissionRequiredContainerCrudMixin, class CrudDeleteView(PermissionRequiredContainerCrudMixin,
FormMessagesMixin, AuditLogMixin, DeleteView): FormMessagesMixin, AuditLogMixin, DeleteView):
permission_required = (RP_DELETE, ) permission_required = (RP_DELETE,)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@classmethod @classmethod
@ -958,10 +962,12 @@ class Crud:
def _add_base(view): def _add_base(view):
if view: if view:
class CrudViewWithBase(cls.BaseMixin, view): class CrudViewWithBase(cls.BaseMixin, view):
model = cls.model model = cls.model
help_topic = cls.help_topic help_topic = cls.help_topic
crud = cls crud = cls
CrudViewWithBase.__name__ = view.__name__ CrudViewWithBase.__name__ = view.__name__
return CrudViewWithBase return CrudViewWithBase
@ -995,11 +1001,13 @@ class Crud:
def build(cls, _model, _help_topic, _model_set=None, list_field_names=[]): def build(cls, _model, _help_topic, _model_set=None, list_field_names=[]):
def create_class(_list_field_names): def create_class(_list_field_names):
class ModelCrud(cls): class ModelCrud(cls):
model = _model model = _model
model_set = _model_set model_set = _model_set
help_topic = _help_topic help_topic = _help_topic
list_field_names = _list_field_names list_field_names = _list_field_names
return ModelCrud return ModelCrud
ModelCrud = create_class(list_field_names) ModelCrud = create_class(list_field_names)

Loading…
Cancel
Save