Convert resolved smart link document list view to CBV.

This commit is contained in:
Roberto Rosario
2015-07-02 01:26:35 -04:00
parent dda604dcbb
commit d47091df61
2 changed files with 36 additions and 24 deletions

View File

@@ -3,14 +3,14 @@ from __future__ import unicode_literals
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from .views import ( from .views import (
DocumentSmartLinkListView, SetupSmartLinkDocumentTypesView, DocumentSmartLinkListView, ResolvedSmartLinkView,
SmartLinkListView SetupSmartLinkDocumentTypesView, SmartLinkListView
) )
urlpatterns = patterns( urlpatterns = patterns(
'linking.views', 'linking.views',
url(r'^document/(?P<pk>\d+)/list/$', DocumentSmartLinkListView.as_view(), name='smart_link_instances_for_document'), url(r'^document/(?P<pk>\d+)/list/$', DocumentSmartLinkListView.as_view(), name='smart_link_instances_for_document'),
url(r'^document/(?P<document_id>\d+)/(?P<smart_link_pk>\d+)/$', 'smart_link_instance_view', name='smart_link_instance_view'), url(r'^document/(?P<document_pk>\d+)/(?P<smart_link_pk>\d+)/$', ResolvedSmartLinkView.as_view(), name='smart_link_instance_view'),
url(r'^setup/list/$', SmartLinkListView.as_view(), name='smart_link_list'), url(r'^setup/list/$', SmartLinkListView.as_view(), name='smart_link_list'),
url(r'^setup/create/$', 'smart_link_create', name='smart_link_create'), url(r'^setup/create/$', 'smart_link_create', name='smart_link_create'),

View File

@@ -17,7 +17,7 @@ from common.views import AssignRemoveView, SingleObjectListView
from common.widgets import two_state_template from common.widgets import two_state_template
from documents.models import Document, DocumentType from documents.models import Document, DocumentType
from documents.permissions import permission_document_view from documents.permissions import permission_document_view
from documents.views import document_list from documents.views import DocumentListView
from permissions import Permission from permissions import Permission
from .forms import SmartLinkConditionForm, SmartLinkForm from .forms import SmartLinkConditionForm, SmartLinkForm
@@ -61,31 +61,43 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
return data return data
def smart_link_instance_view(request, document_id, smart_link_pk): class ResolvedSmartLinkView(DocumentListView):
document = get_object_or_404(Document, pk=document_id) def dispatch(self, request, *args, **kwargs):
smart_link = get_object_or_404(SmartLink, pk=smart_link_pk) self.document = get_object_or_404(Document, pk=self.kwargs['document_pk'])
self.smart_link = get_object_or_404(SmartLink, pk=self.kwargs['smart_link_pk'])
try:
Permission.check_permissions(request.user, [permission_document_view])
except PermissionDenied:
AccessControlList.objects.check_access(permission_document_view, request.user, self.document)
try: try:
Permission.check_permissions(request.user, [permission_smart_link_view]) Permission.check_permissions(request.user, [permission_smart_link_view])
except PermissionDenied: except PermissionDenied:
AccessControlList.objects.check_access(permission_smart_link_view, request.user, smart_link) AccessControlList.objects.check_access(permission_smart_link_view, request.user, self.smart_link)
return super(ResolvedSmartLinkView, self).dispatch(request, *args, **kwargs)
def get_document_queryset(self):
try: try:
object_list = smart_link.get_linked_document_for(document) queryset = self.smart_link.get_linked_document_for(self.document)
except Exception as exception: except Exception as exception:
object_list = Document.objects.none() queryset = Document.objects.none()
if request.user.is_staff or request.user.is_superuser: if self.request.user.is_staff or self.request.user.is_superuser:
messages.error(request, _('Smart link query error: %s' % exception)) messages.error(request, _('Smart link query error: %s' % exception))
return document_list( return queryset
request,
title=_('Documents in smart link: %s') % smart_link.get_dynamic_title(document), def get_extra_context(self):
object_list=object_list, return {
extra_context={ 'hide_links': True,
'object': document 'object': self.document,
'title': _('Documents in smart link "%(smart_link)s" as relation to "%(document)s"') % {
'document': self.document,
'smart_link': self.smart_link.get_dynamic_title(self.document),
}
} }
)
class SmartLinkListView(SingleObjectListView): class SmartLinkListView(SingleObjectListView):