Added tag list view and global tag delete support
This commit is contained in:
@@ -99,6 +99,7 @@
|
||||
{% with subtemplate.main_object as main_object %}
|
||||
{% with subtemplate.hide_link as hide_link %}
|
||||
{% with subtemplate.hide_header as hide_header %}
|
||||
{% with subtemplate.navigation_object_links as navigation_object_links %}
|
||||
|
||||
<div class="grid_{{ subtemplate.grid|default:11 }}">
|
||||
|
||||
@@ -134,6 +135,7 @@
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -24,6 +24,7 @@ from filesystem_serving.api import document_create_fs_links, document_delete_fs_
|
||||
from filesystem_serving.conf.settings import FILESERVING_ENABLE
|
||||
from permissions.api import check_permissions
|
||||
from navigation.utils import resolve_to_name
|
||||
from tags.utils import get_tags_subtemplate
|
||||
|
||||
from documents.conf.settings import DELETE_STAGING_FILE_AFTER_UPLOAD
|
||||
from documents.conf.settings import USE_STAGING_DIRECTORY
|
||||
@@ -289,20 +290,10 @@ def document_view(request, document_id):
|
||||
'object': document,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
subtemplates_dict = []
|
||||
if document.tags.count():
|
||||
subtemplates_dict.append(
|
||||
{
|
||||
'name': 'generic_list_subtemplate.html',
|
||||
'title': _(u'tags'),
|
||||
'object_list': document.tags.all(),
|
||||
'extra_columns': [
|
||||
{'name': _(u'color'), 'attribute': lambda x: u'<div style="width: 20px; height: 20px; border: 1px solid black; background: %s;"></div>' % x.tagproperties_set.get().get_color_code()}
|
||||
],
|
||||
'hide_link': True,
|
||||
}
|
||||
)
|
||||
subtemplates_dict.append(get_tags_subtemplate(document))
|
||||
|
||||
subtemplates_dict.append(
|
||||
{
|
||||
@@ -851,17 +842,7 @@ def document_view_simple(request, document_id):
|
||||
|
||||
subtemplates_dict = []
|
||||
if document.tags.count():
|
||||
subtemplates_dict.append(
|
||||
{
|
||||
'name': 'generic_list_subtemplate.html',
|
||||
'title': _(u'tags'),
|
||||
'object_list': document.tags.all(),
|
||||
'extra_columns': [
|
||||
{'name': _(u'color'), 'attribute': lambda x: u'<div style="width: 20px; height: 20px; border: 1px solid black; background: %s;"></div>' % x.tagproperties_set.get().get_color_code()}
|
||||
],
|
||||
'hide_link': True,
|
||||
}
|
||||
)
|
||||
subtemplates_dict.append(get_tags_subtemplate(document))
|
||||
|
||||
subtemplates_dict.append(
|
||||
{
|
||||
|
||||
@@ -140,6 +140,12 @@ def _get_object_navigation_links(context, menu_name=None, links_dict=object_navi
|
||||
except VariableDoesNotExist:
|
||||
obj = None
|
||||
|
||||
try:
|
||||
navigation_object_links = Variable('navigation_object_links').resolve(context)
|
||||
links_dict = navigation_object_links if navigation_object_links else object_navigation
|
||||
except VariableDoesNotExist:
|
||||
pass
|
||||
|
||||
try:
|
||||
links = links_dict[menu_name][current_view]['links']
|
||||
for link in resolve_links(context, links, current_view, current_path):
|
||||
|
||||
@@ -9,18 +9,26 @@ from taggit.models import Tag
|
||||
|
||||
PERMISSION_TAG_CREATE = 'tag_create'
|
||||
PERMISSION_TAG_ATTACH = 'tag_attach'
|
||||
PERMISSION_TAG_REMOVE = 'tag_remove'
|
||||
PERMISSION_TAG_DELETE = 'tag_delete'
|
||||
PERMISSION_TAG_EDIT = 'tag_edit'
|
||||
|
||||
register_permissions('tags', [
|
||||
{'name': PERMISSION_TAG_CREATE, 'label': _(u'Can create new tags')},
|
||||
{'name': PERMISSION_TAG_ATTACH, 'label': _(u'Can attach exising tags')},
|
||||
{'name': PERMISSION_TAG_DELETE, 'label': _(u'Can delete tags')},
|
||||
{'name': PERMISSION_TAG_CREATE, 'label': _(u'Create new tags')},
|
||||
{'name': PERMISSION_TAG_ATTACH, 'label': _(u'Attach exising tags')},
|
||||
{'name': PERMISSION_TAG_REMOVE, 'label': _(u'Remove tags from documents')},
|
||||
{'name': PERMISSION_TAG_DELETE, 'label': _(u'Delete global tags')},
|
||||
{'name': PERMISSION_TAG_EDIT, 'label': _(u'Edit global tags')},
|
||||
])
|
||||
|
||||
tag_list = {'text': _('tags'), 'view': 'tag_list', 'famfam': 'tag_blue'}
|
||||
tag_delete = {'text': _('delete'), 'view': 'tag_remove', 'args': ['object.id', 'document.id'], 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_DELETE]}}
|
||||
tag_document_remove = {'text': _('delete'), 'view': 'tag_remove', 'args': ['object.id', 'document.id'], 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_REMOVE]}}
|
||||
tag_delete = {'text': _('delete'), 'view': 'tag_delete', 'args': 'object.id', 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_DELETE]}}
|
||||
tag_multiple_delete = {'text': _('delete'), 'view': 'tag_multiple_delete', 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_DELETE]}}
|
||||
|
||||
register_links(Tag, [tag_delete])
|
||||
#register_links(Tag, [tag_delete])
|
||||
|
||||
register_multi_item_links(['tag_list'], [tag_multiple_delete])
|
||||
|
||||
register_sidebar_template(['document_view', 'document_view_simple'], 'tags_sidebar_template.html')
|
||||
|
||||
@@ -32,4 +40,4 @@ tags_menu = [
|
||||
},
|
||||
]
|
||||
|
||||
#register_menu(tags_menu)
|
||||
register_menu(tags_menu)
|
||||
|
||||
@@ -2,6 +2,9 @@ from django.conf.urls.defaults import patterns, url
|
||||
|
||||
urlpatterns = patterns('tags.views',
|
||||
url(r'^list/$', 'tag_list', (), 'tag_list'),
|
||||
url(r'^(?P<tag_id>\d+)/delete/$', 'tag_delete', (), 'tag_delete'),
|
||||
url(r'^multiple/delete/$', 'tag_multiple_delete', (), 'tag_multiple_delete'),
|
||||
|
||||
url(r'^(?P<tag_id>\d+)/remove_from_document/(?P<document_id>\d+)/$', 'tag_remove', (), 'tag_remove'),
|
||||
url(r'^add_to_document/(?P<document_id>\d+)/$', 'tag_add', (), 'tag_add'),
|
||||
)
|
||||
|
||||
19
apps/tags/utils.py
Normal file
19
apps/tags/utils.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from tags import tag_document_remove
|
||||
|
||||
|
||||
def get_tags_subtemplate(obj):
|
||||
return {
|
||||
'name': 'generic_list_subtemplate.html',
|
||||
'title': _(u'tags'),
|
||||
'object_list': obj.tags.all(),
|
||||
'extra_columns': [
|
||||
{'name': _(u'color'), 'attribute': lambda x: u'<div style="width: 20px; height: 20px; border: 1px solid black; background: %s;"></div>' % x.tagproperties_set.get().get_color_code()},
|
||||
],
|
||||
'hide_link': True,
|
||||
'navigation_object_links': {None: {
|
||||
'document_view_simple' : {'links': [tag_document_remove]},
|
||||
'document_view' : {'links': [tag_document_remove]}
|
||||
}}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from permissions.api import check_permissions
|
||||
|
||||
@@ -13,11 +13,11 @@ from documents.models import Document
|
||||
from tags.forms import AddTagForm
|
||||
from tags.models import TagProperties
|
||||
from tags import PERMISSION_TAG_CREATE, PERMISSION_TAG_ATTACH, \
|
||||
PERMISSION_TAG_DELETE
|
||||
PERMISSION_TAG_REMOVE, PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT
|
||||
|
||||
|
||||
def tag_remove(request, tag_id, document_id):
|
||||
check_permissions(request.user, 'tags', [PERMISSION_TAG_DELETE])
|
||||
check_permissions(request.user, 'tags', [PERMISSION_TAG_REMOVE])
|
||||
|
||||
tag = get_object_or_404(Tag, pk=tag_id)
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
@@ -64,14 +64,66 @@ def tag_add(request, document_id):
|
||||
TagProperties(tag=tag, color=form.cleaned_data['color']).save()
|
||||
|
||||
messages.success(request, _(u'Tag "%s" added successfully.') % tag_name)
|
||||
|
||||
|
||||
return HttpResponseRedirect(previous)
|
||||
|
||||
|
||||
def tag_list(request):
|
||||
|
||||
return render_to_response('generic_list.html', {
|
||||
'object_list': Tag.objects.all(),
|
||||
'title': _(u'tags'),
|
||||
'hide_link': True,
|
||||
'multi_select_as_buttons': True,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def tag_delete(request, tag_id=None, tag_id_list=None):
|
||||
check_permissions(request.user, 'tags', [PERMISSION_TAG_DELETE])
|
||||
post_action_redirect = None
|
||||
|
||||
if tag_id:
|
||||
tags = [get_object_or_404(Tag, pk=tag_id)]
|
||||
post_action_redirect = reverse('tag_list')
|
||||
elif tag_id_list:
|
||||
tags = [get_object_or_404(Tag, pk=tag_id) for tag_id in tag_id_list.split(',')]
|
||||
else:
|
||||
messages.error(request, _(u'Must provide at least one tag.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))
|
||||
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/')))
|
||||
|
||||
if request.method == 'POST':
|
||||
for tag in tags:
|
||||
try:
|
||||
tag.delete()
|
||||
messages.success(request, _(u'Tag "%s" deleted successfully.') % tag)
|
||||
except Exception, e:
|
||||
messages.error(request, _(u'Error deleting tag "%(tag)s": %(error)s') % {
|
||||
'tag': tag, 'error': e
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(next)
|
||||
|
||||
context = {
|
||||
'object_name': _(u'tag'),
|
||||
'delete_view': True,
|
||||
'previous': previous,
|
||||
'next': next,
|
||||
}
|
||||
if len(tags) == 1:
|
||||
context['object'] = tags[0]
|
||||
context['title'] = _(u'Are you sure you wish to delete the tag: %s?') % ', '.join([unicode(d) for d in tags])
|
||||
context['message'] = _('Will be removed from all documents.')
|
||||
elif len(tags) > 1:
|
||||
context['title'] = _(u'Are you sure you wish to delete the tags: %s?') % ', '.join([unicode(d) for d in tags])
|
||||
context['message'] = _('Will be removed from all documents.')
|
||||
|
||||
return render_to_response('generic_confirm.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def tag_multiple_delete(request):
|
||||
return tag_delete(
|
||||
request, tag_id_list=request.GET.get('id_list', [])
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user