diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index 82092c696..1569ed6ba 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -4,7 +4,7 @@ from crispy_forms.bootstrap import FormActions from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit from django import template -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, reverse_lazy from django.utils import formats from django.utils.translation import ugettext as _ import rtyaml @@ -206,7 +206,16 @@ class CrispyLayoutFormMixin: def get_column(self, fieldname, span): obj = self.get_object() - verbose_name, text = get_field_display(obj, fieldname) + + func = None + if '|' in fieldname: + fieldname, func = tuple(fieldname.split('|')) + + if func: + verbose_name, text = getattr(self, func)(obj, fieldname) + else: + verbose_name, text = get_field_display(obj, fieldname) + return { 'id': fieldname, 'span': span, @@ -214,6 +223,52 @@ class CrispyLayoutFormMixin: 'text': text, } + def fk_urlize_for_detail(self, obj, fieldname): + + field = obj._meta.get_field(fieldname) + value = getattr(obj, fieldname) + + display = '{}'.format( + reverse( + '%s:%s_detail' % ( + value._meta.app_config.name, value._meta.model_name), + args=(value.id,)), + value) + + return field.verbose_name, display + + def m2m_urlize_for_detail(self, obj, fieldname): + + manager, fieldname = tuple(fieldname.split('__')) + + manager = getattr(obj, manager) + + verbose_name = manager.model._meta.verbose_name + display = '' + for item in manager.all(): + obj_m2m = getattr(item, fieldname) + + if obj == obj_m2m: + continue + + verbose_name = item._meta.get_field(fieldname).verbose_name + + display += '
{{ column.verbose_name }}
-{{ column.verbose_name }}
+