Change tag list, tag documents and document's tags list views to CBV. Link tag_view permission to documents, used to allow showing a document's tags in addition to allowing general tags in the tag list view.
This commit is contained in:
@@ -40,7 +40,7 @@ class TagsApp(MayanAppConfig):
|
||||
|
||||
ModelPermission.register(
|
||||
model=Document, permissions=(
|
||||
permission_tag_attach, permission_tag_remove,
|
||||
permission_tag_attach, permission_tag_remove, permission_tag_view
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from navigation import Link
|
||||
|
||||
from .permissions import (
|
||||
permission_tag_attach, permission_tag_create, permission_tag_delete,
|
||||
permission_tag_edit, permission_tag_remove
|
||||
permission_tag_edit, permission_tag_remove, permission_tag_view
|
||||
)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ link_tag_attach = Link(permissions=[permission_tag_attach], text=_('Attach tag')
|
||||
link_tag_create = Link(permissions=[permission_tag_create], text=_('Create new tag'), view='tags:tag_create')
|
||||
link_tag_delete = Link(permissions=[permission_tag_delete], tags='dangerous', text=_('Delete'), view='tags:tag_delete', args='object.id')
|
||||
link_tag_edit = Link(permissions=[permission_tag_edit], text=_('Edit'), view='tags:tag_edit', args='object.id')
|
||||
link_tag_document_list = Link(permissions=[permission_tag_remove, permission_tag_attach], text=_('Tags'), view='tags:document_tags', args='object.pk')
|
||||
link_tag_document_list = Link(permissions=[permission_tag_view], text=_('Tags'), view='tags:document_tags', args='object.pk')
|
||||
link_tag_list = Link(icon='fa fa-tag', text=_('Tags'), view='tags:tag_list')
|
||||
link_tag_multiple_delete = Link(permissions=[permission_tag_delete], text=_('Delete'), view='tags:tag_multiple_delete')
|
||||
link_tag_tagged_item_list = Link(text=('Documents'), view='tags:tag_tagged_item_list', args='object.id')
|
||||
|
||||
@@ -6,11 +6,11 @@ from .api_views import (
|
||||
APIDocumentTagView, APIDocumentTagListView, APITagDocumentListView,
|
||||
APITagListView, APITagView
|
||||
)
|
||||
from .views import TagTaggedItemListView
|
||||
from .views import DocumentTagListView, TagListView, TagTaggedItemListView
|
||||
|
||||
urlpatterns = patterns(
|
||||
'tags.views',
|
||||
url(r'^list/$', 'tag_list', name='tag_list'),
|
||||
url(r'^list/$', TagListView.as_view(), name='tag_list'),
|
||||
url(r'^create/$', 'tag_create', name='tag_create'),
|
||||
url(r'^(?P<tag_id>\d+)/delete/$', 'tag_delete', name='tag_delete'),
|
||||
url(r'^(?P<tag_id>\d+)/edit/$', 'tag_edit', name='tag_edit'),
|
||||
@@ -23,7 +23,7 @@ urlpatterns = patterns(
|
||||
url(r'^selection/attach/document/(?P<document_id>\d+)/$', 'tag_attach', name='tag_attach'),
|
||||
url(r'^selection/attach/document/multiple/$', 'tag_multiple_attach', name='multiple_documents_tag_attach'),
|
||||
|
||||
url(r'^for/document/(?P<document_id>\d+)/$', 'document_tags', name='document_tags'),
|
||||
url(r'^document/(?P<pk>\d+)/tags/$', DocumentTagListView.as_view(), name='document_tags'),
|
||||
)
|
||||
|
||||
api_urls = patterns(
|
||||
|
||||
@@ -12,6 +12,7 @@ from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from common.views import SingleObjectListView
|
||||
from documents.models import Document
|
||||
from documents.views import DocumentListView
|
||||
from documents.permissions import permission_document_view
|
||||
@@ -108,26 +109,22 @@ def tag_multiple_attach(request):
|
||||
)
|
||||
|
||||
|
||||
def tag_list(request, queryset=None, extra_context=None):
|
||||
context = {
|
||||
'title': _('Tags'),
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
}
|
||||
if extra_context:
|
||||
context.update(extra_context)
|
||||
class TagListView(SingleObjectListView):
|
||||
object_permission = permission_tag_view
|
||||
|
||||
queryset = queryset if not (queryset is None) else Tag.objects.all()
|
||||
def get_tag_queryset(self):
|
||||
return Tag.objects.all()
|
||||
|
||||
try:
|
||||
Permission.check_permissions(request.user, [permission_tag_view])
|
||||
except PermissionDenied:
|
||||
queryset = AccessControlList.objects.filter_by_access(permission_tag_view, request.user, queryset)
|
||||
def get_queryset(self):
|
||||
self.queryset = self.get_tag_queryset()
|
||||
return super(TagListView, self).get_queryset()
|
||||
|
||||
context['object_list'] = queryset
|
||||
|
||||
return render_to_response('appearance/generic_list.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
def get_extra_context(self, **kwargs):
|
||||
return {
|
||||
'title': _('Tags'),
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
}
|
||||
|
||||
|
||||
def tag_delete(request, tag_id=None, tag_id_list=None):
|
||||
@@ -226,21 +223,25 @@ class TagTaggedItemListView(DocumentListView):
|
||||
}
|
||||
|
||||
|
||||
def document_tags(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
class DocumentTagListView(TagListView):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.document = get_object_or_404(Document, pk=self.kwargs['pk'])
|
||||
|
||||
try:
|
||||
Permission.check_permissions(request.user, [permission_document_view])
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(permission_document_view, request.user, document)
|
||||
try:
|
||||
Permission.check_permissions(request.user, [permission_document_view])
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(permission_document_view, request.user, self.document)
|
||||
|
||||
context = {
|
||||
'object': document,
|
||||
'document': document,
|
||||
'title': _('Tags for document: %s') % document,
|
||||
}
|
||||
return super(DocumentTagListView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
return tag_list(request, queryset=document.tags.all(), extra_context=context)
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'object': self.document,
|
||||
'title': _('Tags for document: %s') % self.document,
|
||||
}
|
||||
|
||||
def get_tag_queryset(self):
|
||||
return self.document.tags.all()
|
||||
|
||||
|
||||
def tag_remove(request, document_id=None, document_id_list=None, tag_id=None, tag_id_list=None):
|
||||
|
||||
Reference in New Issue
Block a user