Support source column widget condition
- Add default HTML anchor widget for source columns that return and absolute URL. - Fix CSS pointer behavior on list item panel headers. Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -21,9 +21,9 @@
|
|||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label for="id_indexes_0">
|
<label for="id_indexes_0" style="cursor: auto;">
|
||||||
{% if links_multi_menus_results %}
|
{% if links_multi_menus_results %}
|
||||||
<input class="form-multi-object-action-checkbox check-all-slave checkbox" name="pk_{{ object.pk }}" type="checkbox" />
|
<input class="form-multi-object-action-checkbox check-all-slave checkbox" name="pk_{{ object.pk }}" style="cursor: pointer;" type="checkbox" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<span style="color: white; word-break: break-all; overflow-wrap: break-word;">
|
<span style="color: white; word-break: break-all; overflow-wrap: break-word;">
|
||||||
@@ -36,12 +36,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
{% navigation_get_source_columns source=object only_identifier=True as source_column %}
|
{% navigation_get_source_columns source=object only_identifier=True as source_column %}
|
||||||
{% navigation_source_column_resolve column=source_column as column_value %}
|
{% navigation_source_column_resolve column=source_column as column_value %}
|
||||||
|
{{ column_value }}
|
||||||
{% if source_column.is_attribute_absolute_url or source_column.is_object_absolute_url %}
|
|
||||||
<a href="{% navigation_source_column_get_absolute_url source_column=source_column obj=object %}">{{ column_value }}</a>
|
|
||||||
{% else %}
|
|
||||||
{{ column_value }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -95,11 +95,7 @@
|
|||||||
{% navigation_source_column_resolve column=source_column as column_value %}
|
{% navigation_source_column_resolve column=source_column as column_value %}
|
||||||
{% if column_value %}
|
{% if column_value %}
|
||||||
<td>
|
<td>
|
||||||
{% if source_column.is_attribute_absolute_url or source_column.is_object_absolute_url %}
|
{{ column_value }}
|
||||||
<a href="{% navigation_source_column_get_absolute_url source_column=source_column obj=object %}">{{ column_value }}</a>
|
|
||||||
{% else %}
|
|
||||||
{{ column_value }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from mayan.apps.common.settings import setting_home_view
|
|||||||
from mayan.apps.common.utils import resolve_attribute
|
from mayan.apps.common.utils import resolve_attribute
|
||||||
from mayan.apps.permissions import Permission
|
from mayan.apps.permissions import Permission
|
||||||
|
|
||||||
|
from .html_widgets import SourceColumnLinkWidget
|
||||||
from .utils import get_current_view_name
|
from .utils import get_current_view_name
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -694,7 +695,7 @@ class SourceColumn(object):
|
|||||||
help_text=None, include_label=False, is_attribute_absolute_url=False,
|
help_text=None, include_label=False, is_attribute_absolute_url=False,
|
||||||
is_object_absolute_url=False, is_identifier=False, is_sortable=False,
|
is_object_absolute_url=False, is_identifier=False, is_sortable=False,
|
||||||
kwargs=None, label=None, order=None, sort_field=None, views=None,
|
kwargs=None, label=None, order=None, sort_field=None, views=None,
|
||||||
widget=None
|
widget=None, widget_condition=None
|
||||||
):
|
):
|
||||||
self._label = label
|
self._label = label
|
||||||
self._help_text = help_text
|
self._help_text = help_text
|
||||||
@@ -713,6 +714,11 @@ class SourceColumn(object):
|
|||||||
self.sort_field = sort_field
|
self.sort_field = sort_field
|
||||||
self.views = views or []
|
self.views = views or []
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
|
self.widget_condition = widget_condition
|
||||||
|
|
||||||
|
if self.is_attribute_absolute_url or self.is_object_absolute_url:
|
||||||
|
if not self.widget:
|
||||||
|
self.widget = SourceColumnLinkWidget
|
||||||
|
|
||||||
self.__class__._registry.setdefault(source, [])
|
self.__class__._registry.setdefault(source, [])
|
||||||
self.__class__._registry[source].append(self)
|
self.__class__._registry[source].append(self)
|
||||||
@@ -773,6 +779,12 @@ class SourceColumn(object):
|
|||||||
def add_exclude(self, source):
|
def add_exclude(self, source):
|
||||||
self.exclude = self.exclude + (source,)
|
self.exclude = self.exclude + (source,)
|
||||||
|
|
||||||
|
def check_widget_condition(self, context):
|
||||||
|
if self.widget_condition:
|
||||||
|
return self.widget_condition(context=context)
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def get_absolute_url(self, obj):
|
def get_absolute_url(self, obj):
|
||||||
if self.is_object_absolute_url:
|
if self.is_object_absolute_url:
|
||||||
return obj.get_absolute_url()
|
return obj.get_absolute_url()
|
||||||
@@ -826,9 +838,12 @@ class SourceColumn(object):
|
|||||||
else:
|
else:
|
||||||
result = context['object']
|
result = context['object']
|
||||||
|
|
||||||
|
self.absolute_url = self.get_absolute_url(obj=context['object'])
|
||||||
if self.widget:
|
if self.widget:
|
||||||
widget_instance = self.widget()
|
if self.check_widget_condition(context=context):
|
||||||
return widget_instance.render(name=self.attribute, value=result)
|
widget_instance = self.widget()
|
||||||
|
widget_instance.column = self
|
||||||
|
return widget_instance.render(name=self.attribute, value=result)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
if self.empty_value:
|
if self.empty_value:
|
||||||
|
|||||||
15
mayan/apps/navigation/html_widgets.py
Normal file
15
mayan/apps/navigation/html_widgets.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
|
|
||||||
|
class SourceColumnLinkWidget(object):
|
||||||
|
template_name = 'navigation/source_column_link_widget.html'
|
||||||
|
|
||||||
|
def render(self, name=None, value=None):
|
||||||
|
return render_to_string(
|
||||||
|
template_name=self.template_name, context={
|
||||||
|
'column': self.column, 'value': value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<a href="{{ column.absolute_url }}">{{ value }}</a>
|
||||||
@@ -108,11 +108,6 @@ def navigation_resolve_menus(context, names, source=None, sort_results=None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
|
||||||
def navigation_source_column_get_absolute_url(source_column, obj):
|
|
||||||
return source_column.get_absolute_url(obj=obj)
|
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def resolve_link(context, link):
|
def resolve_link(context, link):
|
||||||
# This can be used to resolve links or menus too
|
# This can be used to resolve links or menus too
|
||||||
|
|||||||
Reference in New Issue
Block a user