X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/9a938c8b406ce05e3bca4a5a483d473ece9e17b0..ee895cba48224b0e393d58bc5ba2323123c2c204:/src/social/views.py diff --git a/src/social/views.py b/src/social/views.py index 15f01bf45..89661590e 100644 --- a/src/social/views.py +++ b/src/social/views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -10,10 +9,8 @@ from django.views.decorators.http import require_POST from ajaxable.utils import AjaxableFormView from catalogue.models import Book -from ssify import ssi_included from social import forms -from .models import Cite -from social.utils import get_set, likes, set_sets +from wolnelektury.utils import is_ajax # ==================== @@ -23,19 +20,32 @@ from social.utils import get_set, likes, set_sets @require_POST def like_book(request, slug): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden('Login required.') book = get_object_or_404(Book, slug=slug) - if not likes(request.user, book): - tag = get_set(request.user, '') - set_sets(request.user, book, [tag]) - if request.is_ajax(): + book.like(request.user) + + if is_ajax(request): return JsonResponse({"success": True, "msg": "ok", "like": True}) else: return redirect(book) +@require_POST +def unlike_book(request, slug): + if not request.user.is_authenticated: + return HttpResponseForbidden('Login required.') + book = get_object_or_404(Book, slug=slug) + + book.unlike(request.user) + + if is_ajax(request): + return JsonResponse({"success": True, "msg": "ok", "like": False}) + else: + return redirect(book) + + @login_required def my_shelf(request): return render(request, 'social/my_shelf.html', { @@ -58,34 +68,3 @@ class ObjectSetsFormView(AjaxableFormView): def form_args(self, request, obj): return (obj, request.user), {} - - -@require_POST -def unlike_book(request, slug): - if not request.user.is_authenticated(): - return HttpResponseForbidden('Login required.') - book = get_object_or_404(Book, slug=slug) - if likes(request.user, book): - set_sets(request.user, book, []) - - if request.is_ajax(): - return JsonResponse({"success": True, "msg": "ok", "like": False}) - else: - return redirect(book) - - -@ssi_included -def cite(request, pk, main=False): - cite = get_object_or_404(Cite, pk=pk) - return render(request, 'social/cite_promo.html', { - 'main': main, - 'cite': cite, - }) - - -@ssi_included(use_lang=False) -def cite_info(request, pk): - cite = get_object_or_404(Cite, pk=pk) - return render(request, 'social/cite_info.html', { - 'cite': cite, - })