diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index b6af79427..2574a4a46 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -55,28 +55,28 @@ def form_actions(more=[Div(css_class='clearfix')], class SaplFormHelper(FormHelper): render_hidden_fields = True # default = False """ - até a release 1.6.1 do django-crispy-forms, os fields em Meta.Fields eram + até a release 1.6.1 do django-crispy-forms, os fields em Meta.Fields eram renderizados mesmo se não mencionados no helper. Com esta mudança (https://github.com/django-crispy-forms/django-crispy-forms/commit/6b93e8a362422db8fe54aa731319c7cbc39990ba) render_hidden_fields foi adicionado uma condição em que a cada instância do Helper, fosse decidido se os fields não mencionados serião ou - não renderizados... + não renderizados... O Sapl até este commit: https://github.com/interlegis/sapl/commit/22b87f36ebc8659a6ecaf8831ab0f425206b0993 utilizou o django-crispy-forms na versão 1.6.1, ou seja, - sem a condição render_hidden_fields o que fazia o FormHelper, na 1.6.1 + sem a condição render_hidden_fields o que fazia o FormHelper, na 1.6.1 set comportar como se, agora, na 1.7.2 o default fosse True. - Como todos os Forms do Sapl foram construídos assumindo que fields + Como todos os Forms do Sapl foram construídos assumindo que fields não incluídos explicitamente no Helper, o helper o incluiria implicitamente, e assim o era, de acordo com commit acima do django-crispy-forms, então cria-se essa classe: - + class SaplFormHelper(FormHelper): - render_hidden_fields = True - + render_hidden_fields = True + onde torna o default, antes False, agora = True, o esperado pelos forms do sapl, e substituí-se todos os FormHelper por SaplFormHelper dentro do projeto Sapl - - + + esta explicação ficará aqui dentro do código, via commit, e na issue #2456. """ @@ -258,7 +258,12 @@ class CrispyLayoutFormMixin: if func: verbose_name, text = getattr(self, func)(obj, fieldname) else: - verbose_name, text = get_field_display(obj, fieldname) + 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) return { 'id': fieldname, diff --git a/sapl/crud/base.py b/sapl/crud/base.py index e0fe78db0..f4f86a36f 100644 --- a/sapl/crud/base.py +++ b/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 @@ -386,12 +383,13 @@ class CrudBaseMixin(CrispyLayoutFormMixin): class CrudListView(PermissionRequiredContainerCrudMixin, ListView): - permission_required = (RP_LIST, ) + permission_required = (RP_LIST,) logger = logging.getLogger(__name__) @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: - s.append(force_text(f.verbose_name)) + 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 @@ -598,7 +602,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): model_ordering = (model_ordering,) for mo in model_ordering: if mo not in ordering: - ordering = ordering + (mo, ) + ordering = ordering + (mo,) queryset = queryset.order_by(*ordering) # print(ordering) @@ -649,7 +653,7 @@ class AuditLogMixin(object): class CrudCreateView(PermissionRequiredContainerCrudMixin, FormMessagesMixin, AuditLogMixin, CreateView): - permission_required = (RP_ADD, ) + permission_required = (RP_ADD,) logger = logging.getLogger(__name__) @classmethod @@ -721,7 +725,7 @@ class CrudCreateView(PermissionRequiredContainerCrudMixin, class CrudDetailView(PermissionRequiredContainerCrudMixin, DetailView, MultipleObjectMixin): - permission_required = (RP_DETAIL, ) + permission_required = (RP_DETAIL,) no_entries_msg = _('Nenhum registro Associado.') paginate_by = 10 logger = logging.getLogger(__name__) @@ -867,7 +871,7 @@ class CrudDetailView(PermissionRequiredContainerCrudMixin, class CrudUpdateView(PermissionRequiredContainerCrudMixin, FormMessagesMixin, AuditLogMixin, UpdateView): - permission_required = (RP_CHANGE, ) + permission_required = (RP_CHANGE,) logger = logging.getLogger(__name__) def form_valid(self, form): @@ -898,7 +902,7 @@ class CrudUpdateView(PermissionRequiredContainerCrudMixin, class CrudDeleteView(PermissionRequiredContainerCrudMixin, FormMessagesMixin, AuditLogMixin, DeleteView): - permission_required = (RP_DELETE, ) + permission_required = (RP_DELETE,) logger = logging.getLogger(__name__) @classmethod @@ -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)