Add new class based dashboard widget. This new widget supports subclassing and is template based. All exising widgets have been converted. ACL filtering was added to the widget results.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-08-23 03:30:06 -04:00
parent 26b31da443
commit f11eef7445
10 changed files with 188 additions and 110 deletions

View File

@@ -4,78 +4,99 @@ from django.apps import apps
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from common.classes import DashboardWidget
from common.classes import DashboardWidgetNumeric
from .icons import (
icon_dashboard_documents_in_trash, icon_dashboard_document_types,
icon_dashboard_pages_per_month, icon_dashboard_new_documents_this_month,
icon_dashboard_total_document
)
from .permissions import (
permission_document_view, permission_document_type_view
)
from .statistics import (
new_document_pages_this_month, new_documents_this_month,
)
def get_total_documents_queryset():
Document = apps.get_model(
app_label='documents', model_name='Document'
)
return Document.objects.all()
class DashboardWidgetDocumentsTotal(DashboardWidgetNumeric):
icon_class = icon_dashboard_total_document
label = _('Total documents')
link = reverse_lazy('documents:document_list')
def render(self, request):
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
Document = apps.get_model(
app_label='documents', model_name='Document'
)
self.count = AccessControlList.objects.filter_by_access(
permission=permission_document_view, user=request.user,
queryset=Document.objects.filter(is_stub=False)
).count()
return super(DashboardWidgetDocumentsTotal, self).render(request)
def get_document_types_queryset():
DocumentType = apps.get_model(
app_label='documents', model_name='DocumentType'
)
return DocumentType.objects.all()
class DashboardWidgetDocumentsInTrash(DashboardWidgetNumeric):
icon_class = icon_dashboard_documents_in_trash
label = _('Documents in trash')
link = reverse_lazy('documents:document_list_deleted')
def render(self, request):
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
DeletedDocument = apps.get_model(
app_label='documents', model_name='DeletedDocument'
)
self.count = AccessControlList.objects.filter_by_access(
permission=permission_document_view, user=request.user,
queryset=DeletedDocument.objects.all()
).count()
return super(DashboardWidgetDocumentsInTrash, self).render(request)
def get_deleted_documents_queryset():
DeletedDocument = apps.get_model(
app_label='documents', model_name='DeletedDocument'
)
return DeletedDocument.objects.all()
class DashboardWidgetDocumentsTypesTotal(DashboardWidgetNumeric):
icon_class = icon_dashboard_document_types
label = _('Document types')
link = reverse_lazy('documents:document_type_list')
def render(self, request):
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
DocumentType = apps.get_model(
app_label='documents', model_name='DocumentType'
)
self.count = AccessControlList.objects.filter_by_access(
permission=permission_document_type_view, user=request.user,
queryset=DocumentType.objects.all()
).count()
return super(DashboardWidgetDocumentsTypesTotal, self).render(request)
widget_pages_per_month = DashboardWidget(
func=new_document_pages_this_month,
icon_class=icon_dashboard_pages_per_month,
label=_('New pages this month'),
link=reverse_lazy(
'statistics:statistic_detail',
args=('new-document-pages-per-month',)
)
)
widget_new_documents_this_month = DashboardWidget(
func=new_documents_this_month,
icon_class=icon_dashboard_new_documents_this_month,
label=_('New documents this month'),
class DashboardWidgetDocumentsNewThisMonth(DashboardWidgetNumeric):
icon_class = icon_dashboard_new_documents_this_month
label = _('New documents this month')
link=reverse_lazy(
'statistics:statistic_detail',
args=('new-documents-per-month',)
)
)
widget_total_documents = DashboardWidget(
icon_class=icon_dashboard_total_document,
queryset=get_total_documents_queryset,
label=_('Total documents'),
link=reverse_lazy('documents:document_list')
)
def render(self, request):
self.count = new_documents_this_month(user=request.user)
return super(DashboardWidgetDocumentsNewThisMonth, self).render(request)
widget_document_types = DashboardWidget(
icon_class=icon_dashboard_document_types,
queryset=get_document_types_queryset,
label=_('Document types'),
link=reverse_lazy('documents:document_type_list')
)
class DashboardWidgetDocumentsPagesNewThisMonth(DashboardWidgetNumeric):
icon_class = icon_dashboard_pages_per_month
label = _('New pages this month')
link=reverse_lazy(
'statistics:statistic_detail',
args=('new-document-pages-per-month',)
)
widget_documents_in_trash = DashboardWidget(
icon_class=icon_dashboard_documents_in_trash,
queryset=get_deleted_documents_queryset,
label=_('Documents in trash'),
link=reverse_lazy('documents:document_list_deleted')
)
def render(self, request):
self.count = new_document_pages_this_month(user=request.user)
return super(DashboardWidgetDocumentsPagesNewThisMonth, self).render(request)