Merge branch 'img-playground' of ssh://git.nowoczesnapolska.org.pl:2223/~/repo/redakc...
[redakcja.git] / apps / catalogue / views.py
index 3c37ee6..bc54c3e 100644 (file)
@@ -23,7 +23,8 @@ from apiclient import NotAuthorizedError
 from catalogue import forms
 from catalogue import helpers
 from catalogue.helpers import active_tab
 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
 
 #
 from catalogue.tasks import publishable_error
 
 #
@@ -357,8 +358,7 @@ def image(request, slug):
         form = forms.ReadonlyImageForm(instance=image)
         editable = False
 
         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={
     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())
         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())