From f4c5b737bf87fb852d422013b0657b34891984a2 Mon Sep 17 00:00:00 2001 From: joshuastegmaier Date: Tue, 24 Sep 2024 09:10:50 -0400 Subject: [PATCH] Added ability to undo an OCR transcription even if it's the first transcription on an asset --- concordia/models.py | 7 +++++-- concordia/views.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/concordia/models.py b/concordia/models.py index 17de74b26..3821a79d0 100644 --- a/concordia/models.py +++ b/concordia/models.py @@ -662,7 +662,6 @@ def can_rollback(self): transcriptions = ( self.transcription_set.exclude(rolled_forward=True) .exclude(source_of__rolled_forward=True) - .exclude(rolled_back=True) .exclude(pk__gte=latest_transcription.pk) .order_by("-pk") ) @@ -677,9 +676,13 @@ def can_rollback(self): transcription_to_rollback_to = None for transcription in transcriptions: + if transcription.source: + transcription_to_check = transcription.source + else: + transcription_to_check = transcription if ( latest_transcription.rolled_back is False - or latest_transcription.supersedes != transcription + or latest_transcription.supersedes != transcription_to_check ): transcription_to_rollback_to = transcription break diff --git a/concordia/views.py b/concordia/views.py index 0f1965de5..2c4621bf5 100644 --- a/concordia/views.py +++ b/concordia/views.py @@ -1568,8 +1568,21 @@ def generate_ocr_transcription(request, *, asset_pk): supersedes_pk = request.POST.get("supersedes") language = request.POST.get("language", None) superseded = get_transcription_superseded(asset, supersedes_pk) - if superseded and isinstance(superseded, HttpResponse): - return superseded + if superseded: + if isinstance(superseded, HttpResponse): + return superseded + else: + # This means this is the first transcription on this asset + # to enable undoing of the OCR transcription, we create + # an empty transcription for the OCR transcription to supersede + superseded = Transcription( + asset=asset, + user=get_anonymous_user(), + text="", + ) + superseded.full_clean() + superseded.save() + transcription_text = asset.get_ocr_transcript(language) transcription = Transcription( asset=asset,