Add widget support to SourceColumn
Allow passing a widget class to SourceColumn. This makes using lambdas to render model column unnecesary and are mostly removed too. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -23,6 +23,10 @@ from pure_pagination.mixins import PaginationMixin
|
||||
|
||||
from .forms import ChoiceForm
|
||||
from .icons import icon_assign_remove_add, icon_assign_remove_remove
|
||||
from .literals import (
|
||||
TEXT_CHOICE_ITEMS, TEXT_CHOICE_LIST, TEXT_LIST_AS_ITEMS,
|
||||
TEXT_LIST_AS_ITEMS_PARAMETER
|
||||
)
|
||||
from .mixins import (
|
||||
DeleteExtraDataMixin, DynamicFormViewMixin, ExtraContextMixin,
|
||||
FormExtraKwargsMixin, MultipleObjectMixin, ObjectActionMixin,
|
||||
@@ -500,14 +504,17 @@ class SingleObjectListView(PaginationMixin, ViewPermissionCheckMixin, ObjectList
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SingleObjectListView, self).get_context_data(**kwargs)
|
||||
if context.get('list_as_items'):
|
||||
default_mode = 'items'
|
||||
|
||||
if context.get(TEXT_LIST_AS_ITEMS):
|
||||
default_mode = TEXT_CHOICE_ITEMS
|
||||
else:
|
||||
default_mode = 'list'
|
||||
default_mode = TEXT_CHOICE_LIST
|
||||
|
||||
list_mode = self.request.GET.get('_list_mode', default_mode)
|
||||
list_mode = self.request.GET.get(
|
||||
TEXT_LIST_AS_ITEMS_PARAMETER, default_mode
|
||||
)
|
||||
|
||||
context.update({'list_as_items': list_mode=='items'})
|
||||
context.update({TEXT_LIST_AS_ITEMS: list_mode == TEXT_CHOICE_ITEMS})
|
||||
return context
|
||||
|
||||
def get_paginate_by(self, queryset):
|
||||
|
||||
@@ -30,8 +30,8 @@ icon_menu_about = Icon(
|
||||
icon_menu_user = Icon(
|
||||
driver_name='fontawesome', symbol='user-circle'
|
||||
)
|
||||
icon_object_error_list_with_icon = Icon(
|
||||
driver_name='fontawesome', symbol='lock'
|
||||
icon_object_error_list = Icon(
|
||||
driver_name='fontawesome', symbol='exclamation-triangle'
|
||||
)
|
||||
icon_ok = Icon(
|
||||
driver_name='fontawesome', symbol='check'
|
||||
|
||||
@@ -10,7 +10,7 @@ from .icons import (
|
||||
icon_about, icon_check_version, icon_current_user_details,
|
||||
icon_current_user_edit, icon_current_user_locale_profile_details,
|
||||
icon_current_user_locale_profile_edit, icon_documentation, icon_forum,
|
||||
icon_license, icon_object_error_list_with_icon, icon_packages_licenses,
|
||||
icon_license, icon_object_error_list, icon_packages_licenses,
|
||||
icon_setup, icon_source_code, icon_support, icon_tools
|
||||
)
|
||||
from .permissions_runtime import permission_error_log_view
|
||||
@@ -65,6 +65,7 @@ link_documentation = Link(
|
||||
text=_('Documentation'), url='https://docs.mayan-edms.com'
|
||||
)
|
||||
link_object_error_list = Link(
|
||||
icon_class=icon_object_error_list,
|
||||
kwargs=get_kwargs_factory('resolved_object'),
|
||||
permissions=(permission_error_log_view,), text=_('Errors'),
|
||||
view='common:object_error_list',
|
||||
@@ -74,12 +75,6 @@ link_object_error_list_clear = Link(
|
||||
permissions=(permission_error_log_view,), text=_('Clear all'),
|
||||
view='common:object_error_list_clear',
|
||||
)
|
||||
link_object_error_list_with_icon = Link(
|
||||
kwargs=get_kwargs_factory('resolved_object'),
|
||||
icon_class=icon_object_error_list_with_icon,
|
||||
permissions=(permission_error_log_view,), text=_('Errors'),
|
||||
view='common:error_list',
|
||||
)
|
||||
link_forum = Link(
|
||||
icon_class=icon_forum, tags='new_window', text=_('Forum'),
|
||||
url='https://forum.mayan-edms.com'
|
||||
|
||||
@@ -11,6 +11,12 @@ MESSAGE_SQLITE_WARNING = _(
|
||||
'for development and testing, not for production.'
|
||||
)
|
||||
PYPI_URL = 'https://pypi.python.org/pypi'
|
||||
|
||||
TEXT_LIST_AS_ITEMS_PARAMETER = '_list_mode'
|
||||
TEXT_LIST_AS_ITEMS = 'list_as_items'
|
||||
TEXT_CHOICE_ITEMS = 'items'
|
||||
TEXT_CHOICE_LIST = 'list'
|
||||
|
||||
TIME_DELTA_UNIT_DAYS = 'days'
|
||||
TIME_DELTA_UNIT_HOURS = 'hours'
|
||||
TIME_DELTA_UNIT_MINUTES = 'minutes'
|
||||
|
||||
@@ -4,7 +4,6 @@ import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import types
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
@@ -18,7 +17,6 @@ from django.utils.six.moves import xmlrpc_client
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
import mayan
|
||||
from mayan.apps.common.compat import dict_type, dictionary_type
|
||||
|
||||
from .exceptions import NotLatestVersion, UnknownLatestVersion
|
||||
from .literals import DJANGO_SQLITE_BACKEND, MAYAN_PYPI_NAME, PYPI_URL
|
||||
@@ -155,9 +153,9 @@ def resolve_attribute(obj, attribute, kwargs=None):
|
||||
except AttributeError:
|
||||
# Try as a related model field
|
||||
if LOOKUP_SEP in attribute:
|
||||
attrib = attribute.replace(LOOKUP_SEP, '.')
|
||||
attribute_replaced = attribute.replace(LOOKUP_SEP, '.')
|
||||
return resolve_attribute(
|
||||
obj=obj, attribute=attribute, kwargs=kwargs
|
||||
obj=obj, attribute=attribute_replaced, kwargs=kwargs
|
||||
)
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -28,7 +28,7 @@ from .generics import ( # NOQA
|
||||
SingleObjectDownloadView, SingleObjectDynamicFormCreateView,
|
||||
SingleObjectDynamicFormEditView, SingleObjectEditView, SingleObjectListView
|
||||
)
|
||||
from .icons import icon_setup
|
||||
from .icons import icon_object_error_list, icon_setup
|
||||
from .menus import menu_setup, menu_tools
|
||||
from .permissions_runtime import permission_error_log_view
|
||||
from .settings import setting_home_view
|
||||
@@ -211,6 +211,15 @@ class ObjectErrorLogEntryListView(SingleObjectListView):
|
||||
{'name': _('Result'), 'attribute': 'result'},
|
||||
),
|
||||
'hide_object': True,
|
||||
'no_results_icon': icon_object_error_list,
|
||||
'no_results_text': _(
|
||||
'Errors during the operation of some objects are recorded '
|
||||
'in this view. Some objects automatically clear their '
|
||||
'errors on subsequent successful operation.'
|
||||
),
|
||||
'no_results_title': _(
|
||||
'There are no errors for this object'
|
||||
),
|
||||
'object': self.get_object(),
|
||||
'title': _('Error log entries for: %s' % self.get_object()),
|
||||
}
|
||||
|
||||
@@ -89,18 +89,17 @@ class TextAreaDiv(forms.widgets.Widget):
|
||||
|
||||
|
||||
class TwoStateWidget(object):
|
||||
def __init__(self, state, center=False, icon_ok=None, icon_fail=None):
|
||||
self.state = state
|
||||
def __init__(self, center=False, icon_ok=None, icon_fail=None):
|
||||
self.icon_ok = icon_ok or default_icon_ok
|
||||
self.icon_fail = icon_fail or default_icon_fail
|
||||
self.center = center
|
||||
|
||||
def render(self):
|
||||
def render(self, name=None, value=None):
|
||||
center_class = ''
|
||||
if self.center:
|
||||
center_class = 'text-center'
|
||||
|
||||
if self.state:
|
||||
if value:
|
||||
return mark_safe(
|
||||
'<div class="{} text-success">{}</div>'.format(
|
||||
center_class, self.icon_ok.render()
|
||||
|
||||
Reference in New Issue
Block a user