Enhance migration process for rapids to shorts; skip normal rapids and provide user feedback on migration status
This commit is contained in:
+14
-2
@@ -78,6 +78,7 @@ from django.core.cache import cache
|
||||
from helpers.images import image_as_base64
|
||||
|
||||
import logging
|
||||
from django.contrib import messages
|
||||
from copy import deepcopy
|
||||
from django.forms.models import model_to_dict
|
||||
from rapids.forms import RapidCreationDefaultForm
|
||||
@@ -834,8 +835,14 @@ def question_migrate_to_shorts(request, pk):
|
||||
try:
|
||||
q = ShortQuestion.from_rapid(rapid)
|
||||
except Exception as e:
|
||||
return HttpResponse(f"Migration failed: {e}", status=500)
|
||||
messages.error(request, f"Migration failed: {e}")
|
||||
return redirect("rapids:question_detail", pk=rapid.pk)
|
||||
|
||||
if q is None:
|
||||
messages.info(request, "Question skipped (marked normal) — not migrated.")
|
||||
return redirect("rapids:question_detail", pk=rapid.pk)
|
||||
|
||||
messages.success(request, "Migration complete — redirected to new Short question.")
|
||||
return redirect(q.get_absolute_url())
|
||||
|
||||
|
||||
@@ -855,11 +862,16 @@ def exam_migrate_rapids_to_shorts(request, pk):
|
||||
|
||||
for rapid in exam.exam_questions.all():
|
||||
try:
|
||||
ShortQuestion.from_rapid(rapid)
|
||||
q = ShortQuestion.from_rapid(rapid)
|
||||
if q is None:
|
||||
# skipped normal
|
||||
continue
|
||||
except Exception:
|
||||
# continue on error
|
||||
continue
|
||||
|
||||
messages.success(request, "Exam migration attempted. Normal questions were skipped.")
|
||||
|
||||
# Redirect to the exam overview for shorts if available, otherwise back to rapids exam
|
||||
try:
|
||||
return redirect("shorts:exam_overview", pk=exam.pk)
|
||||
|
||||
Reference in New Issue
Block a user