Use thema from audience.
[redakcja.git] / src / depot / views.py
index 91ea44a..7976086 100644 (file)
@@ -1,3 +1,18 @@
-from django.shortcuts import render
+from django.contrib.auth.mixins import PermissionRequiredMixin
+from django.shortcuts import get_object_or_404, redirect
+from django.views import View
+from documents.models import Book
+from . import models
 
-# Create your views here.
+
+class ShopPublishView(PermissionRequiredMixin, View):
+    permission_required = 'depot.add_shopbookpublish'
+
+    def post(self, request, shop_id, book_id):
+        shop = get_object_or_404(models.Shop, pk=shop_id)
+        book = get_object_or_404(Book, pk=book_id)
+        try:
+            publish = models.ShopBookPublish.create_for(book, request.user, shop)
+        except AssertionError:
+            pass
+        return redirect(book.get_absolute_url())