79760863ebce8e58f205bdce75fa80132fd96cab
[redakcja.git] / src / depot / views.py
1 from django.contrib.auth.mixins import PermissionRequiredMixin
2 from django.shortcuts import get_object_or_404, redirect
3 from django.views import View
4 from documents.models import Book
5 from . import models
6
7
8 class ShopPublishView(PermissionRequiredMixin, View):
9     permission_required = 'depot.add_shopbookpublish'
10
11     def post(self, request, shop_id, book_id):
12         shop = get_object_or_404(models.Shop, pk=shop_id)
13         book = get_object_or_404(Book, pk=book_id)
14         try:
15             publish = models.ShopBookPublish.create_for(book, request.user, shop)
16         except AssertionError:
17             pass
18         return redirect(book.get_absolute_url())