Scrollable upload grid and bulk rating for the pending backlog
Upload board: - the tile grid no longer re-sorts itself as files finish (that reshuffled the list under the cursor); it keeps insertion order, uses auto-fill tiles of ~150px so they hold a readable size, scrolls inside a 60vh area and no longer chains the page scroll (overscroll-contain); - the files currently in flight are pinned in a small live strip above the grid (name, percent, bar) so progress stays visible while the grid is scrolled with hundreds of tiles. Bulk rating: a 'bulk rate' button in the Pending & Unmatched header opens a large modal with Safe/Questionable/Explicit pills, a tickable thumbnail grid (Select all / Clear) and one confirm that moves every selected upload into the library with that rating. Backed by POST /api/uploads/resolve-bulk/ (temp_ids + rating, own rows only): each staged file is resolved as a custom entry (keeps its staged tags/notes), and already-completed or foreign ids are reported per entry instead of failing the whole batch. Built for the 358-file backlog. Tests: 4 bulk-resolve tests (resolution with the rating, input validation, foreign ids untouched, mixed completed+pending) — full backend suite 53 green. Verified live end to end: staged a file, bulk-resolved it as 'q', saw J-96 created with that rating, then removed the item, temp row and test token.
This commit is contained in:
@@ -17,6 +17,7 @@ from urllib.parse import urlparse
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core import signing
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import Http404
|
||||
from django.utils import timezone
|
||||
from rest_framework import mixins, status, viewsets
|
||||
@@ -328,6 +329,64 @@ class TempUploadViewSet(
|
||||
temp.refresh_from_db()
|
||||
return Response(self.get_serializer(temp).data)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="resolve-bulk")
|
||||
def resolve_bulk(self, request):
|
||||
"""Move many staged uploads into the library with one rating.
|
||||
|
||||
The upload board's bulk tool: pick a rating, tick pending files, and
|
||||
they are all resolved as custom entries (their staged tags/notes are
|
||||
kept). Own rows only, like the rest of the viewset.
|
||||
"""
|
||||
ids = request.data.get("temp_ids")
|
||||
if not isinstance(ids, list) or not ids:
|
||||
return Response(
|
||||
{"detail": "temp_ids must be a non-empty list."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
rating = str(request.data.get("rating") or "").strip()
|
||||
if rating not in {"s", "q", "e"}:
|
||||
return Response(
|
||||
{"detail": "rating must be one of s, q or e."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
try:
|
||||
queryset = self.get_queryset().filter(
|
||||
pk__in=[str(value) for value in ids]
|
||||
)
|
||||
except (ValidationError, ValueError):
|
||||
return Response(
|
||||
{"detail": "One or more ids are not valid upload ids."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
resolved: list[str] = []
|
||||
errors: list[dict[str, str]] = []
|
||||
for temp in queryset:
|
||||
if temp.status == TempUpload.STATUS_COMPLETED:
|
||||
errors.append(
|
||||
{"temp_id": str(temp.id), "error": "already in the library"}
|
||||
)
|
||||
continue
|
||||
temp.custom_rating = rating
|
||||
temp.resolution = TempUpload.RESOLUTION_CUSTOM
|
||||
temp.save(update_fields=["custom_rating", "resolution", "updated_at"])
|
||||
try:
|
||||
complete_temp_upload(temp)
|
||||
except Exception as exc: # noqa: BLE001 - report per-file failures
|
||||
logger.exception("Could not complete staged upload %s", temp.id)
|
||||
temp.status = TempUpload.STATUS_ERROR
|
||||
temp.save(update_fields=["status", "updated_at"])
|
||||
errors.append({"temp_id": str(temp.id), "error": str(exc)})
|
||||
continue
|
||||
resolved.append(str(temp.id))
|
||||
|
||||
found = {str(temp.id) for temp in queryset}
|
||||
for value in sorted({str(value) for value in ids} - found):
|
||||
errors.append({"temp_id": value, "error": "not found"})
|
||||
|
||||
return Response({"resolved": resolved, "errors": errors})
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
if instance.file:
|
||||
instance.file.delete(save=False)
|
||||
|
||||
Reference in New Issue
Block a user