diff --git a/accounts/urls.py b/accounts/urls.py index 900deeb14..7a7dba451 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -96,11 +96,9 @@ path('bookmarks/category//delete/', bookmarks.delete_bookmark_category, name="delete-bookmark-category"), path('bookmarks//delete/', bookmarks.delete_bookmark, name="delete-bookmark"), path('bookmarks/category//edit_modal/', bookmarks.edit_bookmark_category, name="edit-bookmark-category"), - re_path(r'^bookmarks/(?P\d+)/download/.*$', bookmarks.download_bookmark_category, name="download-bookmark-category"), + path('bookmarks//download/', bookmarks.download_bookmark_category, name="download-bookmark-category"), path('bookmarks//licenses/', bookmarks.bookmark_category_licenses, name="category-licenses"), - - path('messages/', messages.inbox, name='messages'), path('messages/sent/', messages.sent_messages, name='messages-sent'), path('messages/archived/', messages.archived_messages, name='messages-archived'), diff --git a/bookmarks/views.py b/bookmarks/views.py index aaa2c6726..0f65c28f6 100755 --- a/bookmarks/views.py +++ b/bookmarks/views.py @@ -42,20 +42,23 @@ def bookmarks(request, category_id=None): n_uncat = Bookmark.objects.select_related("sound").filter(user=user, category=None).count() if not category_id: category = None - bookmarked_sounds = Bookmark.objects.select_related("sound", "sound__user").filter(user=user, category=None) + bookmarked_sounds = Bookmark.objects.filter(user=user, category=None) else: category = get_object_or_404(BookmarkCategory, id=category_id, user=user) - bookmarked_sounds = category.bookmarks.select_related("sound", "sound__user").all() + bookmarked_sounds = category.bookmarks.all() bookmark_categories = BookmarkCategory.objects.filter(user=user).annotate(num_bookmarks=Count('bookmarks')) tvars = {'user': user, 'is_owner': is_owner, 'n_uncat': n_uncat, 'category': category, 'bookmark_categories': bookmark_categories} - tvars.update(paginate(request, bookmarked_sounds, settings.BOOKMARKS_PER_PAGE)) + + paginator = paginate(request, bookmarked_sounds, settings.BOOKMARKS_PER_PAGE) + page_sounds = Sound.objects.ordered_ids([bookmark.sound_id for bookmark in paginator['page'].object_list]) + tvars.update(paginator) + tvars['page_bookmarks_and_sound_objects'] = zip(paginator['page'].object_list, page_sounds) return render(request, 'bookmarks/bookmarks.html', tvars) - @redirect_if_old_username_or_404 @raise_404_if_user_is_deleted def bookmarks_for_user(request, username, category_id=None): @@ -88,21 +91,21 @@ def delete_bookmark_category(request, category_id): @login_required @transaction.atomic() def download_bookmark_category(request, category_id): - category = get_object_or_404(BookmarkCategory, id=category_id) - + category = get_object_or_404(BookmarkCategory, id=category_id, user=request.user) bookmarked_sounds = Bookmark.objects.filter(category_id=category.id).values("sound_id") sounds_list = Sound.objects.filter(id__in=bookmarked_sounds, processing_state="OK", moderation_state="OK").select_related('user','license') - licenses_url = (reverse('category-licenses', args=[category_id])) licenses_content = category.get_attribution(sound_qs=sounds_list) # NOTE: unlike pack downloads, here we are not doing any cache check to avoid consecutive downloads return download_sounds(licenses_file_url=licenses_url, licenses_file_content=licenses_content, sounds_list=sounds_list) + def bookmark_category_licenses(category_id): category = get_object_or_404(BookmarkCategory, id=category_id) attribution = category.get_attribution() return HttpResponse(attribution, content_type="text/plain") + @login_required @transaction.atomic() def edit_bookmark_category(request, category_id): diff --git a/templates/bookmarks/bookmarks.html b/templates/bookmarks/bookmarks.html index 2bc1edd9f..9d97263e1 100644 --- a/templates/bookmarks/bookmarks.html +++ b/templates/bookmarks/bookmarks.html @@ -35,11 +35,11 @@

Bookmark categories

Category: {% if category %}{{category.name}}{% else %}Uncategorized{% endif %}

- {% if page.object_list %} + {% if page_bookmarks_and_sound_objects %}
- {% for bookmark in page.object_list %} + {% for bookmark, sound in page_bookmarks_and_sound_objects %}
- {% display_sound_small bookmark.sound %} + {% display_sound_small sound %} {% if is_owner %} {% endif %}