Convert document smart link list view to CBV.
This commit is contained in:
@@ -2,14 +2,17 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from .views import SetupSmartLinkDocumentTypesView
|
from .views import (
|
||||||
|
DocumentSmartLinkListView, SetupSmartLinkDocumentTypesView,
|
||||||
|
SmartLinkListView
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'linking.views',
|
'linking.views',
|
||||||
url(r'^document/(?P<document_id>\d+)/$', 'smart_link_instances_for_document', 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+)/smart_link/(?P<smart_link_pk>\d+)/$', 'smart_link_instance_view', name='smart_link_instance_view'),
|
url(r'^document/(?P<document_id>\d+)/(?P<smart_link_pk>\d+)/$', 'smart_link_instance_view', name='smart_link_instance_view'),
|
||||||
|
|
||||||
url(r'^setup/list/$', 'smart_link_list', 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'),
|
||||||
url(r'^setup/(?P<smart_link_pk>\d+)/delete/$', 'smart_link_delete', name='smart_link_delete'),
|
url(r'^setup/(?P<smart_link_pk>\d+)/delete/$', 'smart_link_delete', name='smart_link_delete'),
|
||||||
url(r'^setup/(?P<smart_link_pk>\d+)/edit/$', 'smart_link_edit', name='smart_link_edit'),
|
url(r'^setup/(?P<smart_link_pk>\d+)/edit/$', 'smart_link_edit', name='smart_link_edit'),
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from acls.models import AccessControlList
|
from acls.models import AccessControlList
|
||||||
from common.utils import encapsulate
|
from common.utils import encapsulate
|
||||||
from common.views import AssignRemoveView
|
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
|
||||||
@@ -88,53 +88,52 @@ def smart_link_instance_view(request, document_id, smart_link_pk):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def smart_link_instances_for_document(request, document_id):
|
class SmartLinkListView(SingleObjectListView):
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
object_permission = permission_smart_link_view
|
||||||
queryset = ResolvedSmartLink.objects.filter(document_types=document.document_type)
|
|
||||||
|
|
||||||
try:
|
def get_queryset(self):
|
||||||
Permission.check_permissions(request.user, (permission_document_view,))
|
self.queryset = self.get_smart_link_queryset()
|
||||||
except PermissionDenied:
|
return super(SmartLinkListView, self).get_queryset()
|
||||||
smart_links = AccessControlList.objects.filter_by_access(permission_document_view, request.user, queryset)
|
|
||||||
else:
|
|
||||||
smart_links = queryset
|
|
||||||
|
|
||||||
context = {
|
def get_smart_link_queryset(self):
|
||||||
'document': document,
|
return SmartLink.objects.all()
|
||||||
'extra_columns': (
|
|
||||||
{'name': _('Title'), 'attribute': encapsulate(lambda smart_link: smart_link.get_dynamic_title(document))},
|
|
||||||
),
|
|
||||||
'hide_object': True,
|
|
||||||
'hide_link': True,
|
|
||||||
'object': document,
|
|
||||||
'object_list': smart_links,
|
|
||||||
'title': _('Smart links for document: %s') % document,
|
|
||||||
}
|
|
||||||
|
|
||||||
return render_to_response(
|
def get_extra_context(self):
|
||||||
'appearance/generic_list.html', context,
|
return {
|
||||||
context_instance=RequestContext(request)
|
'extra_columns': [
|
||||||
)
|
{'name': _('Dynamic title'), 'attribute': 'dynamic_title'},
|
||||||
|
{'name': _('Enabled'), 'attribute': encapsulate(lambda instance: two_state_template(instance.enabled))},
|
||||||
|
],
|
||||||
|
'hide_link': True,
|
||||||
|
'title': _('Smart links'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def smart_link_list(request):
|
class DocumentSmartLinkListView(SmartLinkListView):
|
||||||
qs = SmartLink.objects.all()
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
self.document = get_object_or_404(Document, pk=self.kwargs['pk'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Permission.check_permissions(request.user, [permission_smart_link_view])
|
Permission.check_permissions(request.user, (permission_document_view,))
|
||||||
except PermissionDenied:
|
except PermissionDenied:
|
||||||
qs = AccessControlList.objects.filter_by_access(permission_smart_link_view, request.user, qs)
|
AccessControlList.objects.check_permissions(permission_document_view, request.user, self.document)
|
||||||
|
|
||||||
return render_to_response('appearance/generic_list.html', {
|
return super(DocumentSmartLinkListView, self).dispatch(request, *args, **kwargs)
|
||||||
'title': _('Smart links'),
|
|
||||||
'object_list': qs,
|
|
||||||
'extra_columns': [
|
|
||||||
{'name': _('Dynamic title'), 'attribute': 'dynamic_title'},
|
|
||||||
{'name': _('Enabled'), 'attribute': encapsulate(lambda x: two_state_template(x.enabled))},
|
|
||||||
],
|
|
||||||
'hide_link': True,
|
|
||||||
|
|
||||||
}, context_instance=RequestContext(request))
|
def get_smart_link_queryset(self):
|
||||||
|
return ResolvedSmartLink.objects.filter(document_types=self.document.document_type, enabled=True)
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'document': self.document,
|
||||||
|
'extra_columns': (
|
||||||
|
{'name': _('Title'), 'attribute': encapsulate(lambda smart_link: smart_link.get_dynamic_title(self.document))},
|
||||||
|
),
|
||||||
|
'hide_object': True,
|
||||||
|
'hide_link': True,
|
||||||
|
'object': self.document,
|
||||||
|
'title': _('Smart links for document: %s') % self.document,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def smart_link_create(request):
|
def smart_link_create(request):
|
||||||
|
|||||||
Reference in New Issue
Block a user