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:
Roberto Rosario
2018-12-23 05:11:14 -04:00
parent 36101dfea6
commit 25edc73100
17 changed files with 308 additions and 106 deletions
+34 -6
View File
@@ -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(