Support marking columns as indetifier and sortable
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -124,7 +124,9 @@
|
||||
* Add document state action view test.
|
||||
* Remove sidebar menu instance. The secondary menu and the
|
||||
previour sidebar menu now perform the same function.
|
||||
|
||||
* Backport source column identifiable and sortable
|
||||
improvements.
|
||||
|
||||
3.1.11 (2019-04-XX)
|
||||
===================
|
||||
* Fix multiple tag selection wizard step.
|
||||
|
||||
@@ -156,6 +156,9 @@ Other changes
|
||||
* Add document state action view test.
|
||||
* Remove sidebar menu instance. The secondary menu and the
|
||||
previour sidebar menu now perform the same function.
|
||||
* Backport source column identifiable and sortable
|
||||
improvements.
|
||||
|
||||
|
||||
Removals
|
||||
--------
|
||||
|
||||
@@ -50,24 +50,25 @@
|
||||
<div class="checkbox">
|
||||
<label for="id_indexes_0">
|
||||
{% if multi_item_actions %}
|
||||
{% if multi_select_item_properties %}
|
||||
<input class="form-multi-object-action-checkbox check-all-slave checkbox" type="checkbox" name="properties_{{ object|get_encoded_parameter:multi_select_item_properties }}" />
|
||||
{% else %}
|
||||
<input class="form-multi-object-action-checkbox check-all-slave checkbox" type="checkbox" name="pk_{{ object.pk }}" />
|
||||
{% endif %}
|
||||
<input class="form-multi-object-action-checkbox check-all-slave checkbox" type="checkbox" name="pk_{{ object.pk }}" />
|
||||
{% endif %}
|
||||
|
||||
<span style="color: white; word-break: break-all; overflow-wrap: break-word;">
|
||||
{% if not hide_object %}
|
||||
{% if main_object %}
|
||||
{% with object|object_property:main_object as object %}
|
||||
{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}
|
||||
{% endwith %}
|
||||
{% if not hide_link %}
|
||||
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
|
||||
{% else %}
|
||||
{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}
|
||||
{{ object }}
|
||||
{% endif %}
|
||||
{% 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|default:object.get_absolute_url }}">{{ column_value }}</a>
|
||||
{% else %}
|
||||
{{ column_value }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
@@ -77,8 +78,9 @@
|
||||
<div class="panel-body">
|
||||
|
||||
{% if not hide_columns %}
|
||||
{% for column in object|get_source_columns %}
|
||||
<div class="text-center" style="">{% source_column_resolve column=column %}{{ column_result }}</div>
|
||||
{% navigation_get_source_columns source=object exclude_identifier=True as source_columns %}
|
||||
{% for column in source_columns %}
|
||||
<div class="text-center" style="">{% navigation_source_column_resolve column=column as column_value %}{% if column_value != '' %}{% if column.include_label %}{{ column.label }}: {% endif %}{{ column_value }}{% endif %}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-condensed table-striped">
|
||||
<table class="table table-condensed table-striped table-hover">
|
||||
<tbody>
|
||||
{% if not hide_header %}
|
||||
<tr>
|
||||
@@ -48,11 +48,37 @@
|
||||
|
||||
{% if not hide_object %}
|
||||
<th>{% trans 'Identifier' %}</th>
|
||||
{% else %}
|
||||
{% navigation_get_source_columns source=object_list only_identifier=True as source_column %}
|
||||
{% if source_column %}
|
||||
<th>
|
||||
{% if source_column.is_sortable %}
|
||||
<a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}
|
||||
{% if navigation_source_column.get_sort_field == sort_field %}
|
||||
{% if icon_sort %}{{ icon_sort.render }}{% endif %}
|
||||
{% endif %}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ source_column.label }}
|
||||
{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if not hide_columns %}
|
||||
{% for column in object_list|get_source_columns %}
|
||||
<th>{{ column.label }}</th>
|
||||
{% navigation_get_source_columns source=object_list exclude_identifier=True as source_columns %}
|
||||
{% for column in source_columns %}
|
||||
<th>
|
||||
{% if column.is_sortable %}
|
||||
<a href="{% navigation_get_sort_field_querystring column=column %}">{{ column.label }}
|
||||
{% if column.get_sort_field == sort_field %}
|
||||
{% if icon_sort %}{{ icon_sort.render }}{% endif %}
|
||||
{% endif %}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ column.label }}
|
||||
{% endif %}
|
||||
</th>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -68,60 +94,68 @@
|
||||
{% for object in object_list %}
|
||||
<tr>
|
||||
|
||||
{% if multi_item_actions %}
|
||||
<td>
|
||||
{% if multi_select_item_properties %}
|
||||
<input type="checkbox" class="form-multi-object-action-checkbox check-all-slave checkbox" name="properties_{{ object|get_encoded_parameter:multi_select_item_properties }}" value="" />
|
||||
{% else %}
|
||||
<input type="checkbox" class="form-multi-object-action-checkbox check-all-slave checkbox" name="pk_{{ object.pk }}" value="" />
|
||||
{% if multi_item_actions %}
|
||||
<td>
|
||||
<input type="checkbox" class="form-multi-object-action-checkbox check-all-slave checkbox" name="pk_{{ object.pk }}" value="" />
|
||||
</td>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if not hide_object %}
|
||||
{% if main_object %}
|
||||
{% with object|object_property:main_object as object %}
|
||||
<td>{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}</td>
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
|
||||
{% if not hide_object %}
|
||||
<td>{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}</td>
|
||||
{% else %}
|
||||
{% navigation_get_source_columns source=object only_identifier=True as source_column %}
|
||||
{% 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|default:object.get_absolute_url }}">{{ column_value }}</a>
|
||||
{% else %}
|
||||
{{ column_value }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if not hide_columns %}
|
||||
{% for column in object|get_source_columns %}
|
||||
<td>{% source_column_resolve column=column %}{{ column_result }}</td>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for column in extra_columns %}
|
||||
<td>{{ object|object_property:column.attribute }}</td>
|
||||
{% endfor %}
|
||||
{% if not hide_links %}
|
||||
<td class="last">
|
||||
{% navigation_resolve_menu name='list facet' sort_results=True source=object as facet_menus_results %}
|
||||
{% for facet_menu_results in facet_menus_results %}
|
||||
{% for link_group in facet_menu_results.link_groups %}
|
||||
{% with link_group.links as object_navigation_links %}
|
||||
{% with 'true' as horizontal %}
|
||||
{% with 'true' as hide_icon %}
|
||||
{% include 'navigation/generic_navigation.html' %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
||||
{% if not hide_columns %}
|
||||
{% navigation_get_source_columns source=object exclude_identifier=True as source_columns %}
|
||||
{% for column in source_columns %}
|
||||
<td>
|
||||
<div class="{{ table_cell_container_classes }}">
|
||||
{% navigation_source_column_resolve column=column as column_value %}{{ column_value }}
|
||||
{# Use explicit 'as column_value ' to force date rendering #}
|
||||
</div>
|
||||
</td>
|
||||
{% endfor %}
|
||||
{% navigation_resolve_menu name='object' source=object as object_menus_results %}
|
||||
{% for object_menu_results in object_menus_results %}
|
||||
{% for link_group in object_menu_results.link_groups %}
|
||||
{% with link_group.links as object_navigation_links %}
|
||||
{% with 'true' as horizontal %}
|
||||
{% with 'true' as hide_icon %}
|
||||
{% include 'navigation/generic_navigation.html' %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% if not hide_links %}
|
||||
<td class="last">
|
||||
{% navigation_resolve_menu name='list facet' sort_results=True source=object as facet_menus_results %}
|
||||
{% for facet_menu_results in facet_menus_results %}
|
||||
{% for link_group in facet_menu_results.link_groups %}
|
||||
{% with link_group.links as object_navigation_links %}
|
||||
{% with 'true' as horizontal %}
|
||||
{% with 'true' as hide_icon %}
|
||||
{% include 'navigation/generic_navigation.html' %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% navigation_resolve_menu name='object' source=object as object_menus_results %}
|
||||
{% for object_menu_results in object_menus_results %}
|
||||
{% for link_group in object_menu_results.link_groups %}
|
||||
{% with link_group.links as object_navigation_links %}
|
||||
{% with 'true' as horizontal %}
|
||||
{% with 'true' as hide_icon %}
|
||||
{% include 'navigation/generic_navigation.html' %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
|
||||
@@ -22,7 +22,15 @@ from django_downloadview import (
|
||||
from pure_pagination.mixins import PaginationMixin
|
||||
|
||||
from .forms import ChoiceForm
|
||||
from .icons import icon_assign_remove_add, icon_assign_remove_remove
|
||||
from .icons import (
|
||||
icon_assign_remove_add, icon_assign_remove_remove, icon_sort_down,
|
||||
icon_sort_up
|
||||
)
|
||||
from .literals import (
|
||||
TEXT_SORT_FIELD_PARAMETER, TEXT_SORT_FIELD_VARIABLE_NAME,
|
||||
TEXT_SORT_ORDER_CHOICE_ASCENDING, TEXT_SORT_ORDER_PARAMETER,
|
||||
TEXT_SORT_ORDER_VARIABLE_NAME
|
||||
)
|
||||
from .mixins import (
|
||||
DeleteExtraDataMixin, DynamicFormViewMixin, ExtraContextMixin,
|
||||
FormExtraKwargsMixin, MultipleObjectMixin, ObjectActionMixin,
|
||||
@@ -495,12 +503,52 @@ class SingleObjectListView(PaginationMixin, ViewPermissionCheckMixin, ObjectList
|
||||
|
||||
return result
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SingleObjectListView, self).get_context_data(**kwargs)
|
||||
|
||||
context.update(
|
||||
{
|
||||
TEXT_SORT_FIELD_VARIABLE_NAME: self.get_sort_field(),
|
||||
TEXT_SORT_ORDER_VARIABLE_NAME: self.get_sort_order(),
|
||||
'icon_sort': self.get_sort_icon(),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def get_paginate_by(self, queryset):
|
||||
return setting_paginate_by.value
|
||||
|
||||
def get_queryset(self):
|
||||
try:
|
||||
return super(SingleObjectListView, self).get_queryset()
|
||||
queryset = super(SingleObjectListView, self).get_queryset()
|
||||
except ImproperlyConfigured:
|
||||
self.queryset = self.get_object_list()
|
||||
return super(SingleObjectListView, self).get_queryset()
|
||||
queryset = super(SingleObjectListView, self).get_queryset()
|
||||
|
||||
self.field_name = self.get_sort_field()
|
||||
if self.get_sort_order() == TEXT_SORT_ORDER_CHOICE_ASCENDING:
|
||||
sort_order = ''
|
||||
else:
|
||||
sort_order = '-'
|
||||
|
||||
if self.field_name:
|
||||
queryset = queryset.order_by(
|
||||
'{}{}'.format(sort_order, self.field_name)
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
def get_sort_field(self):
|
||||
return self.request.GET.get(TEXT_SORT_FIELD_PARAMETER)
|
||||
|
||||
def get_sort_icon(self):
|
||||
sort_order = self.get_sort_order()
|
||||
if not sort_order:
|
||||
return
|
||||
elif sort_order == TEXT_SORT_ORDER_CHOICE_ASCENDING:
|
||||
return icon_sort_down
|
||||
else:
|
||||
return icon_sort_up
|
||||
|
||||
def get_sort_order(self):
|
||||
return self.request.GET.get(TEXT_SORT_ORDER_PARAMETER)
|
||||
|
||||
@@ -52,6 +52,8 @@ icon_social_paypal = Icon(
|
||||
icon_social_twitter = Icon(
|
||||
driver_name='fontawesomecss', css_classes='fab fa-twitter'
|
||||
)
|
||||
icon_sort_down = Icon(driver_name='fontawesome', symbol='sort-down')
|
||||
icon_sort_up = Icon(driver_name='fontawesome', symbol='sort-up')
|
||||
icon_source_code = Icon(driver_name='fontawesome', symbol='code-branch')
|
||||
icon_support = Icon(
|
||||
driver_name='fontawesome', symbol='phone'
|
||||
|
||||
@@ -11,6 +11,14 @@ MESSAGE_SQLITE_WARNING = _(
|
||||
'for development and testing, not for production.'
|
||||
)
|
||||
PYPI_URL = 'https://pypi.python.org/pypi'
|
||||
|
||||
TEXT_SORT_FIELD_PARAMETER = '_sort_field'
|
||||
TEXT_SORT_FIELD_VARIABLE_NAME = 'sort_field'
|
||||
TEXT_SORT_ORDER_CHOICE_ASCENDING = 'asc'
|
||||
TEXT_SORT_ORDER_CHOICE_DESCENDING = 'desc'
|
||||
TEXT_SORT_ORDER_PARAMETER = '_sort_order'
|
||||
TEXT_SORT_ORDER_VARIABLE_NAME = 'sort_order'
|
||||
|
||||
TIME_DELTA_UNIT_DAYS = 'days'
|
||||
TIME_DELTA_UNIT_HOURS = 'hours'
|
||||
TIME_DELTA_UNIT_MINUTES = 'minutes'
|
||||
|
||||
@@ -14,6 +14,11 @@ from django.urls import resolve, reverse
|
||||
from django.utils.encoding import force_str, force_text
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from mayan.apps.common.literals import (
|
||||
TEXT_SORT_FIELD_PARAMETER, TEXT_SORT_FIELD_VARIABLE_NAME,
|
||||
TEXT_SORT_ORDER_CHOICE_ASCENDING, TEXT_SORT_ORDER_CHOICE_DESCENDING,
|
||||
TEXT_SORT_ORDER_PARAMETER, TEXT_SORT_ORDER_VARIABLE_NAME
|
||||
)
|
||||
from mayan.apps.common.settings import setting_home_view
|
||||
from mayan.apps.common.utils import resolve_attribute
|
||||
from mayan.apps.permissions import Permission
|
||||
@@ -528,38 +533,90 @@ class SourceColumn(object):
|
||||
return sorted(columns, key=lambda x: x.order)
|
||||
|
||||
@classmethod
|
||||
def get_for_source(cls, source):
|
||||
def get_for_source(cls, context, source, exclude_identifier=False, only_identifier=False):
|
||||
try:
|
||||
return SourceColumn.sort(columns=cls._registry[source])
|
||||
result = cls._registry[source]
|
||||
except KeyError:
|
||||
try:
|
||||
# Try it as a queryset
|
||||
return SourceColumn.sort(columns=cls._registry[source.model])
|
||||
except AttributeError:
|
||||
# Might be an instance, try its class
|
||||
result = cls._registry[source.__class__]
|
||||
except KeyError:
|
||||
try:
|
||||
# It seems to be an instance, try its class
|
||||
return SourceColumn.sort(columns=cls._registry[source.__class__])
|
||||
except KeyError:
|
||||
# Might be an inherited class insance, try its source class
|
||||
result = cls._registry[source.source_ptr.__class__]
|
||||
except (KeyError, AttributeError):
|
||||
try:
|
||||
# Special case for queryset items produced from
|
||||
# .defer() or .only() optimizations
|
||||
return SourceColumn.sort(columns=cls._registry[list(source._meta.parents.items())[0][0]])
|
||||
except (AttributeError, KeyError, IndexError):
|
||||
return ()
|
||||
# Try it as a queryset
|
||||
result = cls._registry[source.model]
|
||||
except AttributeError:
|
||||
try:
|
||||
# Special case for queryset items produced from
|
||||
# .defer() or .only() optimizations
|
||||
result = cls._registry[list(source._meta.parents.items())[0][0]]
|
||||
except (AttributeError, KeyError, IndexError):
|
||||
result = ()
|
||||
except TypeError:
|
||||
# unhashable type: list
|
||||
return ()
|
||||
result = ()
|
||||
|
||||
def __init__(self, source, label=None, attribute=None, func=None, kwargs=None, order=None, widget=None):
|
||||
result = SourceColumn.sort(columns=result)
|
||||
|
||||
if exclude_identifier:
|
||||
result = [item for item in result if not item.is_identifier]
|
||||
else:
|
||||
if only_identifier:
|
||||
for item in result:
|
||||
if item.is_identifier:
|
||||
return item
|
||||
return None
|
||||
|
||||
final_result = []
|
||||
|
||||
try:
|
||||
request = context.request
|
||||
except AttributeError:
|
||||
# Simple request extraction failed. Might not be a view context.
|
||||
# Try alternate method.
|
||||
try:
|
||||
request = Variable('request').resolve(context)
|
||||
except VariableDoesNotExist:
|
||||
# There is no request variable, most probable a 500 in a test
|
||||
# view. Don't return any resolved request.
|
||||
logger.warning(
|
||||
'No request variable, aborting request resolution'
|
||||
)
|
||||
return result
|
||||
|
||||
current_view_name = get_current_view_name(request=request)
|
||||
for item in result:
|
||||
if item.views:
|
||||
if current_view_name in item.views:
|
||||
final_result.append(item)
|
||||
else:
|
||||
final_result.append(item)
|
||||
|
||||
return final_result
|
||||
|
||||
def __init__(
|
||||
self, source, label=None, attribute=None, func=None,
|
||||
is_absolute_url=False, is_identifier=False, is_sortable=False,
|
||||
kwargs=None, order=None, sort_field=None, views=None, widget=None
|
||||
):
|
||||
self.source = source
|
||||
self._label = label
|
||||
self.attribute = attribute
|
||||
self.func = func
|
||||
self.is_absolute_url = is_absolute_url
|
||||
self.is_identifier = is_identifier
|
||||
self.is_sortable = is_sortable
|
||||
self.kwargs = kwargs or {}
|
||||
self.order = order or 0
|
||||
self.sort_field = sort_field
|
||||
self.views = views or []
|
||||
self.widget = widget
|
||||
|
||||
self.__class__._registry.setdefault(source, [])
|
||||
self.__class__._registry[source].append(self)
|
||||
self.widget = widget
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
@@ -574,7 +631,39 @@ class SourceColumn(object):
|
||||
|
||||
return self._label
|
||||
|
||||
def get_sort_field(self):
|
||||
if self.sort_field:
|
||||
return self.sort_field
|
||||
else:
|
||||
return self.attribute
|
||||
|
||||
def get_sort_field_querystring(self, context):
|
||||
# We do this to get an mutable copy we can modify
|
||||
querystring = context.request.GET.copy()
|
||||
|
||||
previous_sort_field = context.get(TEXT_SORT_FIELD_VARIABLE_NAME, None)
|
||||
previous_sort_order = context.get(
|
||||
TEXT_SORT_ORDER_VARIABLE_NAME, TEXT_SORT_ORDER_CHOICE_DESCENDING
|
||||
)
|
||||
|
||||
if previous_sort_field != self.get_sort_field():
|
||||
sort_order = TEXT_SORT_ORDER_CHOICE_ASCENDING
|
||||
else:
|
||||
if previous_sort_order == TEXT_SORT_ORDER_CHOICE_DESCENDING:
|
||||
sort_order = TEXT_SORT_ORDER_CHOICE_ASCENDING
|
||||
else:
|
||||
sort_order = TEXT_SORT_ORDER_CHOICE_DESCENDING
|
||||
|
||||
querystring[TEXT_SORT_FIELD_PARAMETER] = self.get_sort_field()
|
||||
querystring[TEXT_SORT_ORDER_PARAMETER] = sort_order
|
||||
|
||||
return '?{}'.format(querystring.urlencode())
|
||||
|
||||
def resolve(self, context):
|
||||
if self.views:
|
||||
if get_current_view_name(request=context.request) not in self.views:
|
||||
return
|
||||
|
||||
if self.attribute:
|
||||
result = resolve_attribute(
|
||||
attribute=self.attribute, kwargs=self.kwargs,
|
||||
|
||||
@@ -48,8 +48,13 @@ def get_multi_item_links_form(context, object_list):
|
||||
return ''
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_source_columns(source):
|
||||
@register.simple_tag(takes_context=True)
|
||||
def navigation_get_sort_field_querystring(context, column):
|
||||
return column.get_sort_field_querystring(context=context)
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def navigation_get_source_columns(context, source, exclude_identifier=False, only_identifier=False):
|
||||
try:
|
||||
# Is it a query set?
|
||||
source = source.model
|
||||
@@ -68,7 +73,10 @@ def get_source_columns(source):
|
||||
# It a list and it's empty
|
||||
pass
|
||||
|
||||
return SourceColumn.get_for_source(source)
|
||||
return SourceColumn.get_for_source(
|
||||
context=context, source=source, exclude_identifier=exclude_identifier,
|
||||
only_identifier=only_identifier
|
||||
)
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
@@ -107,6 +115,10 @@ def resolve_link(context, link):
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def source_column_resolve(context, column):
|
||||
context['column_result'] = column.resolve(context=context)
|
||||
return ''
|
||||
def navigation_source_column_resolve(context, column):
|
||||
if column:
|
||||
result = column.resolve(context=context)
|
||||
return result
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user