Skip to content

Commit

Permalink
Added ability to undo an OCR transcription even if it's the first tra…
Browse files Browse the repository at this point in the history
…nscription on an asset (#2541)
  • Loading branch information
joshuastegmaier authored Sep 24, 2024
1 parent 1ae40c3 commit beb29ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions concordia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit beb29ac

Please sign in to comment.