Support empty values and absolute URLs
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -131,7 +131,10 @@
|
||||
* Improve TwoStateWidget to use a template. Make
|
||||
it compatible with the SourceColumn.
|
||||
* Update SourceColumn to support related attributes.
|
||||
|
||||
* Add support for display for empty values for
|
||||
source columns.
|
||||
* Add support for source column object or attribute
|
||||
absolute URLs.
|
||||
|
||||
3.1.11 (2019-04-XX)
|
||||
===================
|
||||
|
||||
@@ -163,7 +163,10 @@ Other changes
|
||||
* Improve TwoStateWidget to use a template. Make
|
||||
it compatible with the SourceColumn.
|
||||
* Update SourceColumn to support related attributes.
|
||||
|
||||
* Add support for display for empty values for
|
||||
source columns.
|
||||
* Add support for source column object or attribute
|
||||
absolute URLs.
|
||||
|
||||
Removals
|
||||
--------
|
||||
|
||||
@@ -68,8 +68,9 @@
|
||||
{% else %}
|
||||
{% navigation_get_source_columns source=object only_identifier=True as source_column %}
|
||||
{% navigation_source_column_resolve column=source_column as column_value %}
|
||||
{% if source_column.is_absolute_url %}
|
||||
<a href="{{ column_value.get_absolute_url }}">{{ column_value }}</a>
|
||||
|
||||
{% 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 %}
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
{% navigation_source_column_resolve column=source_column as column_value %}
|
||||
{% if column_value %}
|
||||
<td>
|
||||
{% if source_column.is_absolute_url %}
|
||||
<a href="{{ column_value.get_absolute_url }}">{{ column_value }}</a>
|
||||
{% 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 %}
|
||||
|
||||
@@ -7,7 +7,9 @@ from furl import furl
|
||||
|
||||
from django.apps import apps
|
||||
from django.contrib.admin.utils import label_for_field
|
||||
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
|
||||
from django.core.exceptions import (
|
||||
FieldDoesNotExist, ImproperlyConfigured, PermissionDenied
|
||||
)
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
from django.template import VariableDoesNotExist, Variable
|
||||
from django.template.defaulttags import URLNode
|
||||
@@ -619,16 +621,19 @@ class SourceColumn(object):
|
||||
return final_result
|
||||
|
||||
def __init__(
|
||||
self, source, label=None, attribute=None, func=None,
|
||||
include_label=False, is_absolute_url=False, is_identifier=False,
|
||||
is_sortable=False,
|
||||
kwargs=None, order=None, sort_field=None, views=None, widget=None
|
||||
self, source, attribute=None, empty_value=None, func=None,
|
||||
include_label=False, is_attribute_absolute_url=False,
|
||||
is_object_absolute_url=False, is_identifier=False, is_sortable=False,
|
||||
kwargs=None, label=None, order=None, sort_field=None, views=None,
|
||||
widget=None
|
||||
):
|
||||
self.source = source
|
||||
self._label = label
|
||||
self.attribute = attribute
|
||||
self.empty_value = empty_value
|
||||
self.func = func
|
||||
self.is_absolute_url = is_absolute_url
|
||||
self.is_attribute_absolute_url = is_attribute_absolute_url
|
||||
self.is_object_absolute_url = is_object_absolute_url
|
||||
self.is_identifier = is_identifier
|
||||
self.is_sortable = is_sortable
|
||||
self.kwargs = kwargs or {}
|
||||
@@ -665,6 +670,16 @@ class SourceColumn(object):
|
||||
|
||||
self.label = self._label
|
||||
|
||||
def get_absolute_url(self, obj):
|
||||
if self.is_object_absolute_url:
|
||||
return obj.get_absolute_url()
|
||||
elif self.is_attribute_absolute_url:
|
||||
result = resolve_attribute(
|
||||
attribute=self.attribute, kwargs=self.kwargs,
|
||||
obj=obj
|
||||
)
|
||||
return result.get_absolute_url()
|
||||
|
||||
def get_sort_field(self):
|
||||
if self.sort_field:
|
||||
return self.sort_field
|
||||
@@ -710,7 +725,13 @@ class SourceColumn(object):
|
||||
widget_instance = self.widget()
|
||||
return widget_instance.render(name=self.attribute, value=result)
|
||||
|
||||
return result
|
||||
if not result:
|
||||
if self.empty_value:
|
||||
return self.empty_value
|
||||
else:
|
||||
return result
|
||||
else:
|
||||
return result
|
||||
|
||||
|
||||
class Text(Link):
|
||||
|
||||
@@ -108,6 +108,11 @@ def navigation_resolve_menus(context, names, source=None, sort_results=None):
|
||||
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)
|
||||
def resolve_link(context, link):
|
||||
# This can be used to resolve links or menus too
|
||||
@@ -121,4 +126,3 @@ def navigation_source_column_resolve(context, column):
|
||||
return result
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user