Catch a DocumentNotCheckedOut exception if user tries to view checkout info on a non checked out document

This commit is contained in:
Roberto Rosario
2012-07-19 12:15:52 -04:00
parent 79d50b3f32
commit d7d409582f

View File

@@ -101,9 +101,13 @@ def checkin_document(request, document_pk):
document = get_object_or_404(Document, pk=document_pk) document = get_object_or_404(Document, pk=document_pk)
post_action_redirect = reverse('checkout_info', args=[document.pk]) post_action_redirect = reverse('checkout_info', args=[document.pk])
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 the user trying to check in the document is the same as the check out # If the user trying to check in the document is the same as the check out
# user just check for the normal permission otherwise check for the forceful # user just check for the normal permission otherwise check for the forceful
# checkin permission # checkin permission
try:
if document.checkout_info().user_object == request.user: if document.checkout_info().user_object == request.user:
try: try:
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CHECKIN]) Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CHECKIN])
@@ -114,9 +118,9 @@ def checkin_document(request, document_pk):
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CHECKIN_OVERRIDE]) Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_CHECKIN_OVERRIDE])
except PermissionDenied: except PermissionDenied:
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_CHECKIN_OVERRIDE, request.user, document) AccessEntry.objects.check_access(PERMISSION_DOCUMENT_CHECKIN_OVERRIDE, request.user, document)
except DocumentNotCheckedOut:
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/'))) messages.error(request, _(u'Document has not been checked out.'))
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/'))) return HttpResponseRedirect(previous)
if request.method == 'POST': if request.method == 'POST':
try: try: