Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions books/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,34 @@ def test_dashboard_excludes_full_books(self):
assert resp.status_code == 200
assert b"No books available for recording right now" in resp.content

def test_flagged_recording_shows_book_available(self):
Recording.objects.create(
book=self.book, narrator=self.narrator, status=RecordingStatus.READY,
flagged_for_review=True, flag_reason="Bad audio",
)
resp = self.client.get("/portal/")
assert b"Unique Testbook XYZ" in resp.content

def test_flagged_recording_not_counted_toward_max_narrators(self):
self.book.max_narrators = 1
self.book.save()
other = Narrator.objects.create(name="Other", email="other@test.com", passphrase="other-p2")
Recording.objects.create(
book=self.book, narrator=other, status=RecordingStatus.READY,
flagged_for_review=True, flag_reason="Noise",
)
resp = self.client.get("/portal/")
assert b"Unique Testbook XYZ" in resp.content

def test_flagged_recording_detail_shows_rerecord_link(self):
recording = Recording.objects.create(
book=self.book, narrator=self.narrator, status=RecordingStatus.READY,
flagged_for_review=True, flag_reason="Background noise",
)
resp = self.client.get(f"/portal/recording/{recording.id}/")
assert b"Re-record this book" in resp.content
assert f"/portal/preflight/{self.book.id}/".encode() in resp.content

def test_invalid_narrator_in_session_redirects(self):
client = Client()
session = client.session
Expand Down
16 changes: 16 additions & 0 deletions books/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ def test_successful_upload_creates_recording_and_attestation(self):
assert recording.duration_seconds == 120
assert Attestation.objects.filter(recording=recording).exists()

def test_reupload_deletes_flagged_recording(self):
from books.models import RecordingStatus

flagged = Recording.objects.create(
book=self.book, narrator=self.narrator, status=RecordingStatus.READY,
flagged_for_review=True, flag_reason="Bad audio",
)
audio = SimpleUploadedFile("test.webm", b"fake audio", content_type="audio/webm")
resp = self.client.post(
f"/portal/upload/{self.book.id}/",
{"audio": audio, "duration": "90", "attestation_text": "I attest again"},
)
assert resp.status_code == 200
assert not Recording.objects.filter(id=flagged.id).exists()
assert Recording.objects.filter(book=self.book, narrator=self.narrator).count() == 1

def test_upload_requires_login(self):
client = Client()
audio = SimpleUploadedFile("test.webm", b"fake audio", content_type="audio/webm")
Expand Down
8 changes: 6 additions & 2 deletions books/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

from django.conf import settings
from django.db.models import Count
from django.db.models import Count, Q
from django.http import FileResponse, Http404, HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
Expand Down Expand Up @@ -108,7 +108,7 @@ def dashboard(request):

available_books = (
Book.objects.exclude(id__in=unflagged_book_ids)
.annotate(recording_count=Count("recordings"))
.annotate(recording_count=Count("recordings", filter=Q(recordings__flagged_for_review=False)))
)

books_with_availability = []
Expand Down Expand Up @@ -220,6 +220,10 @@ def upload_recording(request, book_id):
"error": "Something went wrong saving your recording. Please let an admin know."
}, status=500)

Recording.objects.filter(
book=book, narrator=narrator, flagged_for_review=True
).exclude(id=recording.id).delete()

spawn_remux(recording.id)

request.session.pop(f"preflight_{book_id}", None)
Expand Down
3 changes: 3 additions & 0 deletions templates/books/recording_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ <h3>Your Recording</h3>
<h3>Flagged for Admin Review</h3>
<p>{{ recording.flag_reason }}</p>
</div>
<p class="mt-1">
<a href="{% url 'portal:preflight' book_id=recording.book.id %}" class="btn btn-primary">Re-record this book</a>
</p>
</div>
{% else %}
<div class="section">
Expand Down