Implemented multi item actions for document tags
This commit is contained in:
@@ -28,6 +28,7 @@ register_permission(PERMISSION_TAG_VIEW)
|
|||||||
|
|
||||||
tag_list = {'text': _(u'tag list'), 'view': 'tag_list', 'famfam': 'tag_blue'}
|
tag_list = {'text': _(u'tag list'), 'view': 'tag_list', 'famfam': 'tag_blue'}
|
||||||
tag_document_remove = {'text': _(u'remove'), 'view': 'tag_remove', 'args': ['object.id', 'document.id'], 'famfam': 'tag_blue_delete', 'permissions': [PERMISSION_TAG_REMOVE]}
|
tag_document_remove = {'text': _(u'remove'), 'view': 'tag_remove', 'args': ['object.id', 'document.id'], 'famfam': 'tag_blue_delete', 'permissions': [PERMISSION_TAG_REMOVE]}
|
||||||
|
tag_document_remove_multiple = {'text': _(u'remove'), 'view': 'tag_multiple_remove', 'args': 'document.id', 'famfam': 'tag_blue_delete', 'permissions': [PERMISSION_TAG_REMOVE]}
|
||||||
tag_document_list = {'text': _(u'tags'), 'view': 'document_tags', 'args': 'object.pk', 'famfam': 'tag_blue', 'permissions': [PERMISSION_TAG_REMOVE]}
|
tag_document_list = {'text': _(u'tags'), 'view': 'document_tags', 'args': 'object.pk', 'famfam': 'tag_blue', 'permissions': [PERMISSION_TAG_REMOVE]}
|
||||||
tag_delete = {'text': _(u'delete'), 'view': 'tag_delete', 'args': 'object.id', 'famfam': 'tag_blue_delete', 'permissions': [PERMISSION_TAG_DELETE]}
|
tag_delete = {'text': _(u'delete'), 'view': 'tag_delete', 'args': 'object.id', 'famfam': 'tag_blue_delete', 'permissions': [PERMISSION_TAG_DELETE]}
|
||||||
tag_edit = {'text': _(u'edit'), 'view': 'tag_edit', 'args': 'object.id', 'famfam': 'tag_blue_edit', 'permissions': [PERMISSION_TAG_EDIT]}
|
tag_edit = {'text': _(u'edit'), 'view': 'tag_edit', 'args': 'object.id', 'famfam': 'tag_blue_edit', 'permissions': [PERMISSION_TAG_EDIT]}
|
||||||
@@ -56,3 +57,5 @@ register_sidebar_template(['document_tags'], 'tags_sidebar_template.html')
|
|||||||
register_top_menu('tags', link={'text': _(u'tags'), 'view': 'tag_list', 'famfam': 'tag_blue'}, children_path_regex=[r'^tags/[^d]/'])
|
register_top_menu('tags', link={'text': _(u'tags'), 'view': 'tag_list', 'famfam': 'tag_blue'}, children_path_regex=[r'^tags/[^d]/'])
|
||||||
|
|
||||||
register_links(Document, [tag_document_list], menu_name='form_header')
|
register_links(Document, [tag_document_list], menu_name='form_header')
|
||||||
|
|
||||||
|
register_multi_item_links(['document_tags'], [tag_document_remove_multiple])
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ urlpatterns = patterns('tags.views',
|
|||||||
url(r'^multiple/delete/$', 'tag_multiple_delete', (), 'tag_multiple_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'^(?P<tag_id>\d+)/remove_from_document/(?P<document_id>\d+)/$', 'tag_remove', (), 'tag_remove'),
|
||||||
|
url(r'^multiple/remove_from_document/(?P<document_id>\d+)/$', 'tag_multiple_remove', (), 'tag_multiple_remove'),
|
||||||
url(r'^document/(?P<document_id>\d+)/add/$', 'tag_add', (), 'tag_add'),
|
url(r'^document/(?P<document_id>\d+)/add/$', 'tag_add', (), 'tag_add'),
|
||||||
url(r'^document/(?P<document_id>\d+)/list/$', 'document_tags', (), 'document_tags'),
|
url(r'^document/(?P<document_id>\d+)/list/$', 'document_tags', (), 'document_tags'),
|
||||||
)
|
)
|
||||||
|
|||||||
+53
-48
@@ -15,56 +15,9 @@ from tags.models import TagProperties
|
|||||||
from tags import PERMISSION_TAG_CREATE, PERMISSION_TAG_ATTACH, \
|
from tags import PERMISSION_TAG_CREATE, PERMISSION_TAG_ATTACH, \
|
||||||
PERMISSION_TAG_REMOVE, PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT, \
|
PERMISSION_TAG_REMOVE, PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT, \
|
||||||
PERMISSION_TAG_VIEW
|
PERMISSION_TAG_VIEW
|
||||||
from tags import tag_document_remove as tag_document_remove_link
|
|
||||||
from tags import tag_tagged_item_list as tag_tagged_item_list_link
|
from tags import tag_tagged_item_list as tag_tagged_item_list_link
|
||||||
|
|
||||||
|
|
||||||
def tag_remove(request, document_id, tag_id=None, tag_id_list=None):
|
|
||||||
check_permissions(request.user, [PERMISSION_TAG_REMOVE])
|
|
||||||
|
|
||||||
post_action_redirect = None
|
|
||||||
|
|
||||||
if tag_id:
|
|
||||||
tags = [get_object_or_404(Tag, pk=tag_id)]
|
|
||||||
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', '/'))
|
|
||||||
|
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
|
||||||
|
|
||||||
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:
|
|
||||||
document.tags.remove(tag)
|
|
||||||
messages.success(request, _(u'Tag "%s" removed successfully.') % tag)
|
|
||||||
except Exception, e:
|
|
||||||
messages.error(request, _(u'Error deleting tag "%(tag)s": %(error)s') % {
|
|
||||||
'tag': tag, 'error': e
|
|
||||||
})
|
|
||||||
|
|
||||||
return HttpResponseRedirect(next)
|
|
||||||
|
|
||||||
context = {
|
|
||||||
'previous': previous,
|
|
||||||
'next': next,
|
|
||||||
'form_icon': u'tag_blue_delete.png',
|
|
||||||
'object': document,
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(tags) == 1:
|
|
||||||
context['title'] = _(u'Are you sure you wish to remove the tag: %s?') % ', '.join([unicode(d) for d in tags])
|
|
||||||
elif len(tags) > 1:
|
|
||||||
context['title'] = _(u'Are you sure you wish to remove the tags: %s?') % ', '.join([unicode(d) for d in tags])
|
|
||||||
|
|
||||||
return render_to_response('generic_confirm.html', context,
|
|
||||||
context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
|
|
||||||
def tag_add(request, document_id):
|
def tag_add(request, document_id):
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
|
|
||||||
@@ -222,9 +175,61 @@ def document_tags(request, document_id):
|
|||||||
'title': _(u'tags for: %s') % document,
|
'title': _(u'tags for: %s') % document,
|
||||||
'object_list': document.tags.all(),
|
'object_list': document.tags.all(),
|
||||||
'hide_link': True,
|
'hide_link': True,
|
||||||
'navigation_object_links': [tag_tagged_item_list_link, tag_document_remove_link],
|
'navigation_object_links': [tag_tagged_item_list_link],
|
||||||
'object': document,
|
'object': document,
|
||||||
'document': document,
|
'document': document,
|
||||||
'disable_auto_focus': True,
|
'disable_auto_focus': True,
|
||||||
|
'multi_select_as_buttons': True,
|
||||||
},
|
},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
def tag_remove(request, document_id, tag_id=None, tag_id_list=None):
|
||||||
|
check_permissions(request.user, [PERMISSION_TAG_REMOVE])
|
||||||
|
|
||||||
|
post_action_redirect = None
|
||||||
|
|
||||||
|
if tag_id:
|
||||||
|
tags = [get_object_or_404(Tag, pk=tag_id)]
|
||||||
|
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', '/'))
|
||||||
|
|
||||||
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
|
|
||||||
|
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:
|
||||||
|
document.tags.remove(tag)
|
||||||
|
messages.success(request, _(u'Tag "%s" removed successfully.') % tag)
|
||||||
|
except Exception, e:
|
||||||
|
messages.error(request, _(u'Error deleting tag "%(tag)s": %(error)s') % {
|
||||||
|
'tag': tag, 'error': e
|
||||||
|
})
|
||||||
|
|
||||||
|
return HttpResponseRedirect(next)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'previous': previous,
|
||||||
|
'next': next,
|
||||||
|
'form_icon': u'tag_blue_delete.png',
|
||||||
|
'object': document,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tags) == 1:
|
||||||
|
context['title'] = _(u'Are you sure you wish to remove the tag: %s?') % ', '.join([unicode(d) for d in tags])
|
||||||
|
elif len(tags) > 1:
|
||||||
|
context['title'] = _(u'Are you sure you wish to remove the tags: %s?') % ', '.join([unicode(d) for d in tags])
|
||||||
|
|
||||||
|
return render_to_response('generic_confirm.html', context,
|
||||||
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
def tag_multiple_remove(request, document_id):
|
||||||
|
return tag_remove(request, document_id=document_id, tag_id_list=request.GET.get('id_list', []))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user