From 3d0de5bea8c367ebe47e38157f23abbc38532f5b Mon Sep 17 00:00:00 2001 From: Pablo Barton Date: Sun, 18 Apr 2021 11:15:42 -0400 Subject: [PATCH] approving list items puts them at the end of the list --- bookwyrm/views/list.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index a295806b..b5d8c682 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -4,7 +4,7 @@ from django.core.paginator import Paginator from django.db import IntegrityError, transaction from django.db.models import Avg, Count, Q, Max from django.db.models.functions import Coalesce -from django.http import HttpResponseNotFound, HttpResponseBadRequest +from django.http import HttpResponseNotFound, HttpResponseBadRequest, HttpResponse from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator @@ -211,7 +211,13 @@ class Curate(View): approved = request.POST.get("approved") == "true" if approved: suggestion.approved = True + current_order = suggestion.order + order_max = ( + book_list.listitem_set.aggregate(Max("order"))["order__max"] or 0 + ) + 1 + suggestion.order = order_max suggestion.save() + normalize_book_list_ordering(book_list.id, start=current_order) else: deleted_order = suggestion.order suggestion.delete(broadcast=False) @@ -302,7 +308,7 @@ def set_book_position(request, list_item_id): original_order = list_item.order if original_order == int_position: - return + return HttpResponse(status=204) elif original_order > int_position: list_item.order = -1 list_item.save()