Merge branch 'master' into ofop
[redakcja.git] / apps / catalogue / views.py
index e09940d..e1dc2a3 100644 (file)
@@ -25,7 +25,7 @@ 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, BookPublishRecord, ChunkPublishRecord, Project
 from fileupload.views import UploadView
 
 #
@@ -429,6 +429,17 @@ def chunk_mass_edit(request):
             for b in books_affected:
                 b.touch()  # cache
 
+        project_id = request.POST.get('project')
+        if project_id:
+            try:
+                project = Project.objects.get(pk=int(project_id))
+            except (Project.DoesNotExist, ValueError), e:
+                project = None
+            for c in chunks:
+                book = c.book
+                book.project = project
+                book.save()
+
         for c in chunks: c.save()
 
         return HttpResponse("", content_type="text/plain")
@@ -477,7 +488,10 @@ def publish(request, slug):
 
 class GalleryView(UploadView):
     def get_object(self, request, slug):
-        return get_object_or_404(Book, slug=slug)
+        book = get_object_or_404(Book, slug=slug)
+        if not book.gallery:
+            raise Http404
+        return book
 
     def breadcrumbs(self):
         return [