X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/c3af41ec13e26ad2b4cb000291ff989dc1b3686f..0a7090f11131631647db366ff87976407e788412:/src/social/utils.py?ds=inline diff --git a/src/social/utils.py b/src/social/utils.py old mode 100755 new mode 100644 index f8fb2410a..67bc867fa --- a/src/social/utils.py +++ b/src/social/utils.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. # @@ -15,7 +14,7 @@ from social.models import Cite def likes(user, work, request=None): - if not user.is_authenticated(): + if not user.is_authenticated: return False if request is None: @@ -52,6 +51,15 @@ def get_set(user, name): except Tag.DoesNotExist: tag = Tag.objects.create( category='set', user=user, name=name, slug=utils.get_random_hash(name), sort_key=name.lower()) + except Tag.MultipleObjectsReturned: + # fix duplicated noname shelf + tags = list(Tag.objects.filter(category='set', user=user, name=name)) + tag = tags[0] + for other_tag in tags[1:]: + for item in other_tag.items.all(): + Tag.objects.remove_tag(item, other_tag) + Tag.objects.add_tag(item, tag) + other_tag.delete() return tag @@ -106,7 +114,7 @@ def choose_cite(book_id=None, tag_ids=None): def get_or_choose_cite(request, book_id=None, tag_ids=None): try: assert request.user.is_staff - assert 'choose_cite' in request.GET - return Cite.objects.get(pk=request.GET['choose_cite']) + assert 'banner' in request.GET + return Cite.objects.get(pk=request.GET['banner']) except (AssertionError, Cite.DoesNotExist): return choose_cite(book_id, tag_ids)