Refactor register_model_columns into SourceColumn class
This commit is contained in:
@@ -51,8 +51,8 @@
|
||||
<th>{% trans 'Identifier' %}</th>
|
||||
{% endif %}
|
||||
|
||||
{% for column in object_list|get_model_list_columns %}
|
||||
<th>{{ column.name }}</th>
|
||||
{% for column in object_list|get_source_columns %}
|
||||
<th>{{ column.label }}</th>
|
||||
{% endfor %}
|
||||
|
||||
{% for column in extra_columns %}
|
||||
@@ -86,7 +86,7 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if not hide_columns %}
|
||||
{% for column in object|get_model_list_columns %}
|
||||
{% for column in object|get_source_columns %}
|
||||
<td>{{ object|object_property:column.attribute }}</td>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from django.template import Library
|
||||
|
||||
from common.utils import return_attrib
|
||||
from navigation.api import model_list_columns
|
||||
|
||||
register = Library()
|
||||
|
||||
@@ -9,30 +8,3 @@ register = Library()
|
||||
@register.filter
|
||||
def object_property(value, arg):
|
||||
return return_attrib(value, arg)
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_model_list_columns(obj):
|
||||
try:
|
||||
# Is it a query set?
|
||||
obj = obj.model
|
||||
except AttributeError:
|
||||
# Is not a query set
|
||||
try:
|
||||
# Is iterable?
|
||||
obj = obj[0]
|
||||
except TypeError:
|
||||
# It is not
|
||||
pass
|
||||
except IndexError:
|
||||
# It a list and it's empty
|
||||
pass
|
||||
except KeyError:
|
||||
# It a list and it's empty
|
||||
pass
|
||||
|
||||
for key, value in model_list_columns.items():
|
||||
if key == obj or isinstance(obj, key):
|
||||
return value
|
||||
|
||||
return []
|
||||
|
||||
@@ -9,7 +9,7 @@ from common import MayanAppConfig, menu_facet, menu_object, menu_sidebar
|
||||
from common.classes import ModelAttribute
|
||||
from common.utils import encapsulate
|
||||
from documents.models import Document
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
|
||||
from .links import (
|
||||
link_comment_add, link_comment_delete, link_comments_for_document
|
||||
@@ -40,27 +40,16 @@ class DocumentCommentsApp(MayanAppConfig):
|
||||
|
||||
ModelAttribute(Document, label=_('Comments'), name='comments', type_name='related')
|
||||
|
||||
SourceColumn(source=Comment, label=_('Date'), attribute='submit_date')
|
||||
SourceColumn(source=Comment, label=_('User'), attribute=encapsulate(lambda x: x.user.get_full_name() if x.user.get_full_name() else x.user))
|
||||
SourceColumn(source=Comment, label=_('Comment'), attribute='comment')
|
||||
|
||||
class_permissions(Document, [
|
||||
PERMISSION_COMMENT_CREATE,
|
||||
PERMISSION_COMMENT_DELETE,
|
||||
PERMISSION_COMMENT_VIEW]
|
||||
)
|
||||
|
||||
register_model_list_columns(Comment, [
|
||||
{
|
||||
'name': _('Date'),
|
||||
'attribute': 'submit_date'
|
||||
},
|
||||
{
|
||||
'name': _('User'),
|
||||
'attribute': encapsulate(lambda x: x.user.get_full_name() if x.user.get_full_name() else x.user)
|
||||
},
|
||||
{
|
||||
'name': _('Comment'),
|
||||
'attribute': 'comment'
|
||||
}
|
||||
])
|
||||
|
||||
menu_sidebar.bind_links(links=[link_comment_add], sources=['comments:comments_for_document', 'comments:comment_add', 'comments:comment_delete', 'comments:comment_multiple_delete'])
|
||||
menu_object.bind_links(links=[link_comment_delete], sources=[Comment])
|
||||
menu_facet.bind_links(links=[link_comments_for_document], sources=[Document])
|
||||
|
||||
@@ -9,7 +9,7 @@ from common import (
|
||||
)
|
||||
from common.utils import encapsulate
|
||||
from documents.models import Document
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
|
||||
from .handlers import launch_workflow
|
||||
from .models import (
|
||||
@@ -35,6 +35,26 @@ class DocumentStatesApp(MayanAppConfig):
|
||||
|
||||
def ready(self):
|
||||
super(DocumentStatesApp, self).ready()
|
||||
|
||||
SourceColumn(source=Workflow, label=_('Initial state'), attribute=encapsulate(lambda workflow: workflow.get_initial_state() or _('None')))
|
||||
|
||||
SourceColumn(source=WorkflowInstance, label=_('Current state'), attribute='get_current_state')
|
||||
SourceColumn(source=WorkflowInstance, label=_('User'), attribute=encapsulate(lambda workflow: getattr(workflow.get_last_log_entry(), 'user', _('None'))))
|
||||
SourceColumn(source=WorkflowInstance, label=_('Last transition'), attribute='get_last_transition')
|
||||
SourceColumn(source=WorkflowInstance, label=_('Date and time'), attribute=encapsulate(lambda workflow: getattr(workflow.get_last_log_entry(), 'datetime', _('None'))))
|
||||
SourceColumn(source=WorkflowInstance, label=_('Completion'), attribute=encapsulate(lambda workflow: getattr(workflow.get_current_state(), 'completion', _('None'))))
|
||||
|
||||
SourceColumn(source=WorkflowInstanceLogEntry, label=_('Date and time'), attribute='datetime')
|
||||
SourceColumn(source=WorkflowInstanceLogEntry, label=_('User'), attribute='user')
|
||||
SourceColumn(source=WorkflowInstanceLogEntry, label=_('Transition'), attribute='transition')
|
||||
SourceColumn(source=WorkflowInstanceLogEntry, label=_('Comment'), attribute='comment')
|
||||
|
||||
SourceColumn(source=WorkflowState, label=_('Is initial state?'), attribute='initial')
|
||||
SourceColumn(source=WorkflowState, label=_('Completion'), attribute='completion')
|
||||
|
||||
SourceColumn(source=WorkflowTransition, label=_('Origin state'), attribute='origin_state')
|
||||
SourceColumn(source=WorkflowTransition, label=_('Destination state'), attribute='destination_state')
|
||||
|
||||
menu_facet.bind_links(links=[link_document_workflow_instance_list], sources=[Document])
|
||||
menu_object.bind_links(links=[link_setup_workflow_states, link_setup_workflow_transitions, link_setup_workflow_document_types, link_setup_workflow_edit, link_setup_workflow_delete], sources=[Workflow])
|
||||
menu_object.bind_links(links=[link_setup_workflow_state_edit, link_setup_workflow_state_delete], sources=[WorkflowState])
|
||||
@@ -44,75 +64,4 @@ class DocumentStatesApp(MayanAppConfig):
|
||||
menu_setup.bind_links(links=[link_setup_workflow_list])
|
||||
menu_sidebar.bind_links(links=[link_setup_workflow_state_create, link_setup_workflow_transition_create], sources=[Workflow])
|
||||
|
||||
register_model_list_columns(Workflow, [
|
||||
{
|
||||
'name': _('Initial state'),
|
||||
'attribute': encapsulate(lambda workflow: workflow.get_initial_state() or _('None'))
|
||||
},
|
||||
])
|
||||
|
||||
register_model_list_columns(WorkflowInstance, [
|
||||
{
|
||||
'name': _('Current state'),
|
||||
'attribute': 'get_current_state'
|
||||
},
|
||||
{
|
||||
'name': _('User'),
|
||||
'attribute': encapsulate(lambda workflow: getattr(workflow.get_last_log_entry(), 'user', _('None')))
|
||||
},
|
||||
{
|
||||
'name': _('Last transition'),
|
||||
'attribute': 'get_last_transition'
|
||||
},
|
||||
{
|
||||
'name': _('Date and time'),
|
||||
'attribute': encapsulate(lambda workflow: getattr(workflow.get_last_log_entry(), 'datetime', _('None')))
|
||||
},
|
||||
{
|
||||
'name': _('Completion'),
|
||||
'attribute': encapsulate(lambda workflow: getattr(workflow.get_current_state(), 'completion', _('None')))
|
||||
},
|
||||
])
|
||||
|
||||
register_model_list_columns(WorkflowInstanceLogEntry, [
|
||||
{
|
||||
'name': _('Date and time'),
|
||||
'attribute': 'datetime'
|
||||
},
|
||||
{
|
||||
'name': _('User'),
|
||||
'attribute': 'user'
|
||||
},
|
||||
{
|
||||
'name': _('Transition'),
|
||||
'attribute': 'transition'
|
||||
},
|
||||
{
|
||||
'name': _('Comment'),
|
||||
'attribute': 'comment'
|
||||
},
|
||||
])
|
||||
|
||||
register_model_list_columns(WorkflowState, [
|
||||
{
|
||||
'name': _('Is initial state?'),
|
||||
'attribute': 'initial'
|
||||
},
|
||||
{
|
||||
'name': _('Completion'),
|
||||
'attribute': 'completion'
|
||||
},
|
||||
])
|
||||
|
||||
register_model_list_columns(WorkflowTransition, [
|
||||
{
|
||||
'name': _('Origin state'),
|
||||
'attribute': 'origin_state'
|
||||
},
|
||||
{
|
||||
'name': _('Destination state'),
|
||||
'attribute': 'destination_state'
|
||||
},
|
||||
])
|
||||
|
||||
post_save.connect(launch_workflow, dispatch_uid='launch_workflow', sender=Document)
|
||||
|
||||
@@ -24,7 +24,7 @@ from converter.permissions import (
|
||||
)
|
||||
from dynamic_search.classes import SearchModel
|
||||
from events.permissions import PERMISSION_EVENTS_VIEW
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
from statistics.classes import StatisticNamespace
|
||||
|
||||
@@ -150,12 +150,6 @@ class DocumentsApp(MayanAppConfig):
|
||||
registry.register(Document)
|
||||
|
||||
register_maintenance_links([link_clear_image_cache], namespace='documents', title=_('Documents'))
|
||||
register_model_list_columns(Document, [
|
||||
{
|
||||
'name': _('Thumbnail'), 'attribute':
|
||||
encapsulate(lambda x: document_thumbnail(x, gallery_name='documents:document_list', title=getattr(x, 'label', None), size=setting_thumbnail_size.value))
|
||||
},
|
||||
{
|
||||
'name': _('Type'), 'attribute': 'document_type'
|
||||
}
|
||||
])
|
||||
|
||||
SourceColumn(source=Document, label=_('Thumbnail'), attribute=encapsulate(lambda document: document_thumbnail(document, gallery_name='documents:document_list', title=getattr(document, 'label', None), size=setting_thumbnail_size.value)))
|
||||
SourceColumn(source=Document, label=_('type'), attribute='document_type')
|
||||
|
||||
@@ -2,9 +2,14 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from actstream.models import Action
|
||||
|
||||
from common import MayanAppConfig, menu_tools
|
||||
from common.utils import encapsulate
|
||||
from navigation import SourceColumn
|
||||
|
||||
from .links import link_events_list
|
||||
from .widgets import event_type_link
|
||||
|
||||
|
||||
class EventsApp(MayanAppConfig):
|
||||
@@ -14,4 +19,8 @@ class EventsApp(MayanAppConfig):
|
||||
def ready(self):
|
||||
super(EventsApp, self).ready()
|
||||
|
||||
SourceColumn(source=Action, label=_('Timestamp'), attribute='timestamp')
|
||||
SourceColumn(source=Action, label=_('Actor'), attribute='actor')
|
||||
SourceColumn(source=Action, label=_('Verb'), attribute=encapsulate(lambda entry: event_type_link(entry)))
|
||||
|
||||
menu_tools.bind_links(links=[link_events_list])
|
||||
|
||||
@@ -4,13 +4,7 @@ from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from actstream.models import Action
|
||||
|
||||
from common.utils import encapsulate
|
||||
from navigation.api import register_model_list_columns
|
||||
|
||||
from .classes import Event
|
||||
from .widgets import event_type_link
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
@@ -25,17 +19,3 @@ class EventType(models.Model):
|
||||
verbose_name_plural = _('Event types')
|
||||
|
||||
|
||||
register_model_list_columns(Action, [
|
||||
{
|
||||
'name': _('Timestamp'),
|
||||
'attribute': 'timestamp'
|
||||
},
|
||||
{
|
||||
'name': _('Actor'),
|
||||
'attribute': 'actor',
|
||||
},
|
||||
{
|
||||
'name': _('Verb'),
|
||||
'attribute': encapsulate(lambda entry: event_type_link(entry))
|
||||
},
|
||||
])
|
||||
|
||||
@@ -10,8 +10,7 @@ from common import (
|
||||
)
|
||||
from common.utils import encapsulate
|
||||
from documents.models import Document
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import CombinedSource
|
||||
from navigation import CombinedSource, SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .links import (
|
||||
@@ -55,7 +54,5 @@ class FoldersApp(MayanAppConfig):
|
||||
menu_secondary.bind_links(links=[link_folder_list, link_folder_create], sources=[Folder, 'folders:folder_list', 'folders:folder_create'])
|
||||
menu_sidebar.bind_links(links=[link_folder_add_document], sources=['folders:document_folder_list', 'folders:folder_add_document'])
|
||||
|
||||
register_model_list_columns(Folder, [
|
||||
{'name': _('Created'), 'attribute': 'datetime_created'},
|
||||
{'name': _('Documents'), 'attribute': encapsulate(lambda x: x.documents.count())},
|
||||
])
|
||||
SourceColumn(source=Folder, label=_('Created'), attribute='datetime_created')
|
||||
SourceColumn(source=Folder, label=_('Document'), attribute=encapsulate(lambda x: x.documents.count()))
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common import MayanAppConfig, menu_tools, menu_object, menu_secondary
|
||||
from common.utils import encapsulate
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
|
||||
from .classes import Property, PropertyNamespace, PIPNotFound, VirtualEnv
|
||||
from .links import link_menu_link, link_namespace_details, link_namespace_list
|
||||
@@ -17,6 +17,12 @@ class InstallationApp(MayanAppConfig):
|
||||
def ready(self):
|
||||
super(InstallationApp, self).ready()
|
||||
|
||||
SourceColumn(source=PropertyNamespace, label=_('Label'), attribute='label')
|
||||
SourceColumn(source=PropertyNamespace, label=_('Items'), attribute=encapsulate(lambda entry: len(entry.get_properties())))
|
||||
|
||||
SourceColumn(source=Property, label=_('Label'), attribute='label')
|
||||
SourceColumn(source=Property, label=_('Value'), attribute='value')
|
||||
|
||||
menu_object.bind_links(links=[link_namespace_details], sources=[PropertyNamespace])
|
||||
menu_secondary.bind_links(links=[link_namespace_list], sources=['installation:namespace_list', PropertyNamespace])
|
||||
menu_tools.bind_links(links=[link_menu_link])
|
||||
@@ -29,25 +35,3 @@ class InstallationApp(MayanAppConfig):
|
||||
else:
|
||||
for item, version, result in venv.get_results():
|
||||
namespace.add_property(item, '%s (%s)' % (item, version), result, report=True)
|
||||
|
||||
register_model_list_columns(PropertyNamespace, [
|
||||
{
|
||||
'name': _('Label'),
|
||||
'attribute': 'label'
|
||||
},
|
||||
{
|
||||
'name': _('Items'),
|
||||
'attribute': encapsulate(lambda entry: len(entry.get_properties()))
|
||||
}
|
||||
])
|
||||
|
||||
register_model_list_columns(Property, [
|
||||
{
|
||||
'name': _('Label'),
|
||||
'attribute': 'label'
|
||||
},
|
||||
{
|
||||
'name': _('Value'),
|
||||
'attribute': 'value'
|
||||
}
|
||||
])
|
||||
|
||||
@@ -14,7 +14,7 @@ from common.classes import ModelAttribute
|
||||
from common.utils import encapsulate
|
||||
from documents.models import Document, DocumentType
|
||||
from documents.signals import post_document_type_change
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .api import get_metadata_string
|
||||
@@ -57,6 +57,8 @@ class MetadataApp(MayanAppConfig):
|
||||
ModelAttribute(Document, 'metadata__value', label=_('Metadata type value'), type_name='query')
|
||||
ModelAttribute(Document, 'metadata_value_of', label=_('Value of a metadata'), description=_('Return the value of a specific document metadata'), type_name=['property', 'indexing'])
|
||||
|
||||
SourceColumn(source=Document, label=_('Metadata'), attribute=encapsulate(lambda document: get_metadata_string(document)))
|
||||
|
||||
class_permissions(Document, [
|
||||
PERMISSION_METADATA_DOCUMENT_ADD, PERMISSION_METADATA_DOCUMENT_EDIT,
|
||||
PERMISSION_METADATA_DOCUMENT_REMOVE, PERMISSION_METADATA_DOCUMENT_VIEW,
|
||||
@@ -74,9 +76,3 @@ class MetadataApp(MayanAppConfig):
|
||||
post_save.connect(post_document_type_metadata_type_add, dispatch_uid='post_document_type_metadata_type_add', sender=DocumentTypeMetadataType)
|
||||
post_delete.connect(post_document_type_metadata_type_delete, dispatch_uid='post_document_type_metadata_type_delete', sender=DocumentTypeMetadataType)
|
||||
post_document_type_change.connect(post_post_document_type_change_metadata, dispatch_uid='post_post_document_type_change_metadata', sender=Document)
|
||||
|
||||
register_model_list_columns(Document, [
|
||||
{
|
||||
'name': _('Metadata'), 'attribute': encapsulate(lambda x: get_metadata_string(x))
|
||||
},
|
||||
])
|
||||
|
||||
@@ -1 +1 @@
|
||||
from .classes import CombinedSource, Link, Menu # NOQA
|
||||
from .classes import CombinedSource, Link, Menu, SourceColumn # NOQA
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
model_list_columns = {}
|
||||
|
||||
|
||||
def register_model_list_columns(model, columns):
|
||||
"""
|
||||
Define which columns will be displayed in the generic list template
|
||||
for a given model
|
||||
"""
|
||||
|
||||
model_list_columns.setdefault(model, [])
|
||||
model_list_columns[model].extend(columns)
|
||||
@@ -248,6 +248,27 @@ class ModelListColumn(object):
|
||||
self.__class__._model_list_columns[model].extend(columns)
|
||||
|
||||
|
||||
class SourceColumn(object):
|
||||
_registry = {}
|
||||
|
||||
@classmethod
|
||||
def get_for_source(cls, source):
|
||||
try:
|
||||
return cls._registry[source]
|
||||
except KeyError:
|
||||
try:
|
||||
return cls._registry[source.model]
|
||||
except AttributeError:
|
||||
try:
|
||||
return cls._registry[source.__class__]
|
||||
except KeyError:
|
||||
return ()
|
||||
|
||||
def __init__(self, source, label, attribute):
|
||||
self.__class__._registry.setdefault(source, [])
|
||||
self.__class__._registry[source].append({'label': label, 'attribute': attribute})
|
||||
|
||||
|
||||
class CombinedSource(object):
|
||||
"""
|
||||
Class that binds a link to a combination of an object and a view.
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.template import Library
|
||||
|
||||
from ..classes import Menu
|
||||
from ..classes import Menu, SourceColumn
|
||||
from ..forms import MultiItemForm
|
||||
|
||||
register = Library()
|
||||
@@ -35,3 +35,26 @@ def get_multi_item_links_form(context, object_list):
|
||||
form = MultiItemForm(actions=actions)
|
||||
context.update({'multi_item_form': form, 'multi_item_actions': actions})
|
||||
return ''
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_source_columns(source):
|
||||
try:
|
||||
# Is it a query set?
|
||||
source = source.model
|
||||
except AttributeError:
|
||||
# Is not a query set
|
||||
try:
|
||||
# Is iterable?
|
||||
source = source[0]
|
||||
except TypeError:
|
||||
# It is not
|
||||
pass
|
||||
except IndexError:
|
||||
# It a list and it's empty
|
||||
pass
|
||||
except KeyError:
|
||||
# It a list and it's empty
|
||||
pass
|
||||
|
||||
return SourceColumn.get_for_source(source)
|
||||
|
||||
@@ -16,7 +16,7 @@ from documents.models import Document, DocumentVersion
|
||||
from documents.signals import post_version_upload
|
||||
from documents.widgets import document_link
|
||||
from installation import PropertyNamespace
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .handlers import post_version_upload_ocr
|
||||
@@ -54,6 +54,10 @@ class OCRApp(MayanAppConfig):
|
||||
Document.add_to_class('submit_for_ocr', document_ocr_submit)
|
||||
DocumentVersion.add_to_class('submit_for_ocr', document_version_ocr_submit)
|
||||
|
||||
SourceColumn(source=DocumentVersionOCRError, label=_('Document'), attribute=encapsulate(lambda entry: document_link(entry.document_version.document)))
|
||||
SourceColumn(source=DocumentVersionOCRError, label=_('Added'), attribute='datetime_submitted')
|
||||
SourceColumn(source=DocumentVersionOCRError, label=_('Result'), attribute='result')
|
||||
|
||||
class_permissions(
|
||||
Document, [
|
||||
PERMISSION_OCR_DOCUMENT, PERMISSION_OCR_CONTENT_VIEW
|
||||
@@ -98,15 +102,3 @@ class OCRApp(MayanAppConfig):
|
||||
namespace.add_property('unpaper', _('unpaper version'), _('error getting version'), report=True)
|
||||
else:
|
||||
namespace.add_property('unpaper', _('unpaper version'), unpaper('-V').stdout, report=True)
|
||||
|
||||
register_model_list_columns(DocumentVersionOCRError, [
|
||||
{
|
||||
'name': _('Document'), 'attribute': encapsulate(lambda entry: document_link(entry.document_version.document))
|
||||
},
|
||||
{
|
||||
'name': _('Added'), 'attribute': 'datetime_submitted'
|
||||
},
|
||||
{
|
||||
'name': _('Result'), 'attribute': 'result'
|
||||
},
|
||||
])
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from common import MayanAppConfig, menu_setup, menu_object
|
||||
from common.utils import encapsulate
|
||||
from common.widgets import exists_widget
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
|
||||
from .classes import Namespace, Setting
|
||||
from .links import link_namespace_detail, link_namespace_list
|
||||
@@ -21,25 +21,10 @@ class SmartSettingsApp(MayanAppConfig):
|
||||
def ready(self):
|
||||
super(SmartSettingsApp, self).ready()
|
||||
|
||||
SourceColumn(source=Namespace, label=_('Setting count'), attribute=encapsulate(lambda instance: len(instance.settings)))
|
||||
SourceColumn(source=Setting, label=_('Name'), attribute=encapsulate(lambda instance: setting_widget(instance)))
|
||||
SourceColumn(source=Setting, label=_('Value'), attribute='value')
|
||||
SourceColumn(source=Setting, label=_('Found in path'), attribute=encapsulate(lambda instance: exists_widget(instance.value) if instance.is_path else _('n/a')))
|
||||
|
||||
menu_object.bind_links(links=(link_namespace_detail,), sources=(Namespace,))
|
||||
menu_setup.bind_links(links=(link_namespace_list,))
|
||||
|
||||
register_model_list_columns(Namespace, [
|
||||
{
|
||||
'name': _('Setting count'),
|
||||
'attribute': encapsulate(lambda instance: len(instance.settings))
|
||||
},
|
||||
])
|
||||
|
||||
register_model_list_columns(Setting, [
|
||||
{
|
||||
'name': _('Name'),
|
||||
'attribute': encapsulate(lambda instance: setting_widget(instance))
|
||||
},
|
||||
{
|
||||
'name': _('Value'), 'attribute': 'value'
|
||||
},
|
||||
{
|
||||
'name': _('Found in path'), 'attribute': encapsulate(lambda instance: exists_widget(instance.value) if instance.is_path else _('n/a'))
|
||||
},
|
||||
])
|
||||
|
||||
@@ -10,7 +10,7 @@ from common.signals import post_initial_setup
|
||||
from common.utils import encapsulate
|
||||
from converter.links import link_transformation_list
|
||||
from documents.models import Document
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .classes import StagingFile
|
||||
@@ -36,8 +36,11 @@ class SourcesApp(MayanAppConfig):
|
||||
super(SourcesApp, self).ready()
|
||||
|
||||
APIEndPoint('sources')
|
||||
|
||||
MissingItem(label=_('Create a document source'), description=_('Document sources are the way in which new documents are feed to Mayan EDMS, create at least a web form source to be able to upload documents from a browser.'), condition=lambda: not Source.objects.exists(), view='sources:setup_source_list')
|
||||
|
||||
SourceColumn(source=StagingFile, label=_('Thumbnail'), attribute=encapsulate(lambda staging_file: staging_file_thumbnail(staging_file, gallery_name='sources:staging_list', title=staging_file.filename, size='100')))
|
||||
|
||||
menu_front_page.bind_links(links=[link_document_create_multiple])
|
||||
menu_object.bind_links(links=[link_document_create_siblings], sources=[Document])
|
||||
menu_object.bind_links(links=[link_setup_source_edit, link_setup_source_delete, link_transformation_list, link_setup_source_logs], sources=[Source])
|
||||
@@ -46,11 +49,4 @@ class SourcesApp(MayanAppConfig):
|
||||
menu_setup.bind_links(links=[link_setup_sources])
|
||||
menu_sidebar.bind_links(links=[link_upload_version], sources=['documents:document_version_list', 'documents:upload_version', 'documents:document_version_revert'])
|
||||
|
||||
register_model_list_columns(StagingFile, [
|
||||
{
|
||||
'name': _('Thumbnail'), 'attribute':
|
||||
encapsulate(lambda x: staging_file_thumbnail(x, gallery_name='sources:staging_list', title=x.filename, size='100'))
|
||||
},
|
||||
])
|
||||
|
||||
post_initial_setup.connect(create_default_document_source, dispatch_uid='create_default_document_source')
|
||||
|
||||
@@ -9,8 +9,7 @@ from common import (
|
||||
)
|
||||
from common.utils import encapsulate
|
||||
from documents.models import Document
|
||||
from navigation import CombinedSource
|
||||
from navigation.api import register_model_list_columns
|
||||
from navigation import CombinedSource, SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .links import (
|
||||
@@ -36,6 +35,11 @@ class TagsApp(MayanAppConfig):
|
||||
|
||||
APIEndPoint('tags')
|
||||
|
||||
SourceColumn(source=Document, label=_('Tags'), attribute=encapsulate(lambda document: get_tags_inline_widget_simple(document)))
|
||||
|
||||
SourceColumn(source=Tag, label=_('Preview'), attribute=encapsulate(lambda tag: single_tag_widget(tag)))
|
||||
SourceColumn(source=Tag, label=_('Tagged items'), attribute=encapsulate(lambda tag: tag.documents.count()))
|
||||
|
||||
class_permissions(Document, [
|
||||
PERMISSION_TAG_ATTACH, PERMISSION_TAG_REMOVE,
|
||||
])
|
||||
@@ -51,21 +55,3 @@ class TagsApp(MayanAppConfig):
|
||||
menu_object.bind_links(links=[link_tag_tagged_item_list, link_tag_edit, link_tag_acl_list, link_tag_delete], sources=[Tag])
|
||||
menu_secondary.bind_links(links=[link_tag_list, link_tag_create], sources=[Tag, 'tags:tag_list', 'tags:tag_create'])
|
||||
menu_sidebar.bind_links(links=[link_tag_attach], sources=['tags:document_tags', 'tags:tag_remove', 'tags:tag_multiple_remove', 'tags:tag_attach'])
|
||||
|
||||
register_model_list_columns(Document, [
|
||||
{
|
||||
'name': _('Tags'), 'attribute':
|
||||
encapsulate(lambda x: get_tags_inline_widget_simple(x))
|
||||
},
|
||||
])
|
||||
|
||||
register_model_list_columns(Tag, [
|
||||
{
|
||||
'name': _('Preview'),
|
||||
'attribute': encapsulate(lambda x: single_tag_widget(x))
|
||||
},
|
||||
{
|
||||
'name': _('Tagged items'),
|
||||
'attribute': encapsulate(lambda x: x.documents.count())
|
||||
}
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user