Add support for sortable columns
Add a new argument to the SourceColumn class to flag a column as sortable. The SourceColum will generate a request querystring to be used as the table header archor href. The SingleObjectListView will capture the querystring and call the order_by on the queryset to sort it. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -233,15 +233,25 @@ class DocumentsApp(MayanAppConfig):
|
||||
document_page_thumbnail_widget = DocumentPageThumbnailWidget()
|
||||
|
||||
# Document
|
||||
SourceColumn(
|
||||
attribute='label', is_absolute_url=True, is_identifier=True,
|
||||
is_sortable=True, source=Document
|
||||
)
|
||||
SourceColumn(
|
||||
func=lambda context: document_page_thumbnail_widget.render(
|
||||
instance=context['object']
|
||||
), label=_('Thumbnail'), source=Document
|
||||
)
|
||||
SourceColumn(
|
||||
attribute='document_type', label=_('Type'), source=Document
|
||||
attribute='document_type', is_sortable=True, label=_('Type'),
|
||||
source=Document
|
||||
)
|
||||
SourceColumn(attribute='get_page_count', source=Document)
|
||||
SourceColumn(
|
||||
attribute='date_added', is_sortable=True, source=Document, views=(
|
||||
'documents:document_list_recent_added',
|
||||
)
|
||||
)
|
||||
|
||||
# DocumentPage
|
||||
SourceColumn(
|
||||
@@ -262,6 +272,10 @@ class DocumentsApp(MayanAppConfig):
|
||||
)
|
||||
|
||||
# DocumentType
|
||||
SourceColumn(
|
||||
attribute='label', is_identifier=True, is_sortable=True,
|
||||
source=DocumentType
|
||||
)
|
||||
SourceColumn(
|
||||
func=lambda context: context['object'].get_document_count(
|
||||
user=context['request'].user
|
||||
@@ -269,11 +283,19 @@ class DocumentsApp(MayanAppConfig):
|
||||
)
|
||||
|
||||
SourceColumn(
|
||||
attribute='enabled', source=DocumentTypeFilename,
|
||||
attribute='filename', is_identifier=True, is_sortable=True,
|
||||
source=DocumentTypeFilename
|
||||
)
|
||||
SourceColumn(
|
||||
attribute='enabled', is_sortable=True, source=DocumentTypeFilename,
|
||||
widget=TwoStateWidget
|
||||
)
|
||||
|
||||
# DeletedDocument
|
||||
SourceColumn(
|
||||
attribute='label', is_identifier=True, is_sortable=True,
|
||||
source=DeletedDocument
|
||||
)
|
||||
SourceColumn(
|
||||
func=lambda context: document_page_thumbnail_widget.render(
|
||||
instance=context['object']
|
||||
@@ -281,7 +303,7 @@ class DocumentsApp(MayanAppConfig):
|
||||
)
|
||||
|
||||
SourceColumn(
|
||||
attribute='document_type', source=DeletedDocument
|
||||
attribute='document_type', is_sortable=True, source=DeletedDocument
|
||||
)
|
||||
SourceColumn(
|
||||
attribute='get_rendered_deleted_date_time', source=DeletedDocument
|
||||
@@ -298,9 +320,15 @@ class DocumentsApp(MayanAppConfig):
|
||||
), label=_('Thumbnail'), source=DocumentVersion
|
||||
)
|
||||
SourceColumn(attribute='get_page_count', source=DocumentVersion)
|
||||
SourceColumn(attribute='mimetype', source=DocumentVersion)
|
||||
SourceColumn(attribute='encoding', source=DocumentVersion)
|
||||
SourceColumn(attribute='comment', source=DocumentVersion)
|
||||
SourceColumn(
|
||||
attribute='mimetype', is_sortable=True, source=DocumentVersion
|
||||
)
|
||||
SourceColumn(
|
||||
attribute='encoding', is_sortable=True, source=DocumentVersion
|
||||
)
|
||||
SourceColumn(
|
||||
attribute='comment', is_sortable=True, source=DocumentVersion
|
||||
)
|
||||
|
||||
# DuplicatedDocument
|
||||
SourceColumn(
|
||||
|
||||
@@ -115,6 +115,7 @@ class DocumentTypeListView(SingleObjectListView):
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
'no_results_icon': icon_document_type_setup,
|
||||
'no_results_main_link': link_document_type_create.resolve(
|
||||
context=RequestContext(request=self.request)
|
||||
@@ -224,6 +225,7 @@ class DocumentTypeFilenameListView(SingleObjectListView):
|
||||
return {
|
||||
'document_type': self.get_document_type(),
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
'navigation_object_list': ('document_type',),
|
||||
'no_results_icon': icon_document_type_filename,
|
||||
'no_results_main_link': link_document_type_filename_create.resolve(
|
||||
|
||||
@@ -84,6 +84,7 @@ class DocumentListView(SingleObjectListView):
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'hide_links': True,
|
||||
'hide_object': True,
|
||||
'list_as_items': True,
|
||||
'no_results_icon': icon_document_list,
|
||||
'no_results_text': _(
|
||||
@@ -963,9 +964,6 @@ class RecentAddedDocumentListView(DocumentListView):
|
||||
context = super(RecentAddedDocumentListView, self).get_extra_context()
|
||||
context.update(
|
||||
{
|
||||
'extra_columns': (
|
||||
{'name': _('Added'), 'attribute': 'date_added'},
|
||||
),
|
||||
'no_results_icon': icon_document_list_recent_added,
|
||||
'no_results_text': _(
|
||||
'This view will list the latest documents uploaded '
|
||||
|
||||
Reference in New Issue
Block a user