X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/73ef2b8442dc95f8b7279de812c30ac8626d5f39..e59fb224da39822620eefe8171d8ecad2c69cda6:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 3c37ee60..bc54c3ea 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -23,7 +23,8 @@ from apiclient import NotAuthorizedError from catalogue import forms from catalogue import helpers from catalogue.helpers import active_tab -from catalogue.models import Book, Chunk, BookPublishRecord, ChunkPublishRecord +from catalogue.models import (Book, Chunk, Image, BookPublishRecord, + ChunkPublishRecord, ImagePublishRecord) from catalogue.tasks import publishable_error # @@ -357,8 +358,7 @@ def image(request, slug): form = forms.ReadonlyImageForm(instance=image) editable = False - #publish_error = publishable_error(book) - publish_error = 'Publishing not implemented yet.' + publish_error = publishable_error(image) publishable = publish_error is None return direct_to_template(request, "catalogue/image_detail.html", extra_context={ @@ -480,3 +480,20 @@ def publish(request, slug): return http.HttpResponse(e) else: return http.HttpResponseRedirect(book.get_absolute_url()) + + +@require_POST +@login_required +def publish_image(request, slug): + image = get_object_or_404(Image, slug=slug) + if not image.accessible(request): + return HttpResponseForbidden("Not authorized.") + + try: + image.publish(request.user) + except NotAuthorizedError: + return http.HttpResponseRedirect(reverse('apiclient_oauth')) + except BaseException, e: + return http.HttpResponse(e) + else: + return http.HttpResponseRedirect(image.get_absolute_url())