Exception handling, if current item is removed from parent view by user action
This commit is contained in:
parent
8b1612c840
commit
7287643d98
@ -23,7 +23,7 @@ from users.views import profile_pre_actions, profile_post_actions
|
|||||||
from users.forms import UserProfileFormLanguageOnly
|
from users.forms import UserProfileFormLanguageOnly
|
||||||
from .userviews import get_wrapper_instance as get_userview_wrapper_instance
|
from .userviews import get_wrapper_instance as get_userview_wrapper_instance
|
||||||
import zipfile
|
import zipfile
|
||||||
from pygal.views.userviews import query_view
|
from pygal.views.userviews import query_view, ItemDoesNotEsistWithinParent
|
||||||
|
|
||||||
|
|
||||||
def pygal_item_does_not_exist(request, context):
|
def pygal_item_does_not_exist(request, context):
|
||||||
@ -155,7 +155,10 @@ def pygal_userview_infoview(request, responsetype, rel_path):
|
|||||||
#
|
#
|
||||||
if w.may_read():
|
if w.may_read():
|
||||||
context.set_additional_title(w.name)
|
context.set_additional_title(w.name)
|
||||||
return w.render(context)
|
try:
|
||||||
|
return w.render(context)
|
||||||
|
except ItemDoesNotEsistWithinParent:
|
||||||
|
return redirect('?'.join([request.META['PATH_INFO'].replace(rel_path, ''), request.META['QUERY_STRING']]))
|
||||||
else:
|
else:
|
||||||
return pygal_access_denied(request, context)
|
return pygal_access_denied(request, context)
|
||||||
|
|
||||||
@ -244,7 +247,7 @@ def pygal_addtag(request, rel_path):
|
|||||||
tag_context_adaption(context, w, request, get_item_type(full_path) in [TYPE_IMAGE])
|
tag_context_adaption(context, w, request, get_item_type(full_path) in [TYPE_IMAGE])
|
||||||
if request.POST:
|
if request.POST:
|
||||||
tag = Tag(item=w.item)
|
tag = Tag(item=w.item)
|
||||||
form = TagForm(request.POST, instance=tag, factor_to_original=context['factor_to_original'])
|
form = TagForm(request.POST, instance=tag, factor_to_original=context.get('factor_to_original'))
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
messages.info(request, _('Thanks for adding a Tag to %s') % w.name)
|
messages.info(request, _('Thanks for adding a Tag to %s') % w.name)
|
||||||
@ -277,7 +280,7 @@ def pygal_tagedit(request, tag_id):
|
|||||||
context['enable_delete_button'] = True
|
context['enable_delete_button'] = True
|
||||||
if request.POST:
|
if request.POST:
|
||||||
if request.POST.get('save'):
|
if request.POST.get('save'):
|
||||||
form = TagForm(request.POST, instance=t, factor_to_original=context['factor_to_original'])
|
form = TagForm(request.POST, instance=t, factor_to_original=context.get('factor_to_original'))
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
messages.info(request, _('Thanks for editing Tag %(tag_id)d to %(item_name)s') % {'tag_id': tag_id, 'item_name': w.name})
|
messages.info(request, _('Thanks for editing Tag %(tag_id)d to %(item_name)s') % {'tag_id': tag_id, 'item_name': w.name})
|
||||||
@ -287,7 +290,7 @@ def pygal_tagedit(request, tag_id):
|
|||||||
messages.info(request, _('Tag %(tag_id)d of %(item_name)s has been deleted.') % {'tag_id': tag_id, 'item_name': w.name})
|
messages.info(request, _('Tag %(tag_id)d of %(item_name)s has been deleted.') % {'tag_id': tag_id, 'item_name': w.name})
|
||||||
return redirect(get_next(request))
|
return redirect(get_next(request))
|
||||||
else:
|
else:
|
||||||
form = TagForm(instance=t, factor_to_original=context['factor_to_original'])
|
form = TagForm(instance=t, factor_to_original=context.get('factor_to_original'))
|
||||||
context['form'] = form
|
context['form'] = form
|
||||||
return render(request, 'pygal/tagedit.html', context=context)
|
return render(request, 'pygal/tagedit.html', context=context)
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ REPEAT_ENTRY = 'repeat-main'
|
|||||||
SHUFFLE_ENTRY = 'shuffle-main'
|
SHUFFLE_ENTRY = 'shuffle-main'
|
||||||
|
|
||||||
|
|
||||||
|
class ItemDoesNotEsistWithinParent(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_wrapper_class(full_path):
|
def get_wrapper_class(full_path):
|
||||||
return {
|
return {
|
||||||
TYPE_FOLDER: folder_view,
|
TYPE_FOLDER: folder_view,
|
||||||
@ -260,7 +264,10 @@ class base_view(object):
|
|||||||
if direction not in [-1, 1]:
|
if direction not in [-1, 1]:
|
||||||
raise ValueError("Parameter direction is incorrect: %s" % repr(direction))
|
raise ValueError("Parameter direction is incorrect: %s" % repr(direction))
|
||||||
fp_il = random_copy(self.request, self.__parent__().sorted_fullpathlist())
|
fp_il = random_copy(self.request, self.__parent__().sorted_fullpathlist())
|
||||||
i = fp_il.index(self.full_path)
|
try:
|
||||||
|
i = fp_il.index(self.full_path)
|
||||||
|
except ValueError as e:
|
||||||
|
raise ItemDoesNotEsistWithinParent(e)
|
||||||
lgt = len(fp_il)
|
lgt = len(fp_il)
|
||||||
for i in range(i + direction, i + direction * lgt, direction):
|
for i in range(i + direction, i + direction * lgt, direction):
|
||||||
full_path = fp_il[i % lgt]
|
full_path = fp_il[i % lgt]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user