Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to undo an OCR transcription even if it's the first transcription on an asset #2541

Merged
merged 1 commit into from
Sep 24, 2024
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
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
Loading