From 45e50e9e9329af48ee8592ae15c7941bb48d469c Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 20 Oct 2025 22:35:01 +0100 Subject: [PATCH] Enhance import preview functionality with editable fields and overlay logic for payload updates --- .../sbas/partials/import_preview.html | 303 ++++++++++-------- sbas/views.py | 14 + 2 files changed, 181 insertions(+), 136 deletions(-) diff --git a/sbas/templates/sbas/partials/import_preview.html b/sbas/templates/sbas/partials/import_preview.html index 001fd39b..bbd226c6 100644 --- a/sbas/templates/sbas/partials/import_preview.html +++ b/sbas/templates/sbas/partials/import_preview.html @@ -2,9 +2,14 @@ {% csrf_token %} {% for item in items %} -
+
-
Question {{ item.index|add:1 }}
+
+
Question {{ item.index|add:1 }}
+
+ +
+
{% if item.errors %} {% endif %} - {% if item.payload %} -

Title: {{ item.payload.title|default:'(No title)'|safe }}

-

Stem: {{ item.payload.stem|default:''|safe }}

-

Answers: -

    -
  • A: {{ item.payload.a_answer|default:''|safe }}
  • - {% if item.payload.a_feedback %} -

    A Feedback: {{ item.payload.a_feedback|default:''|safe }}

    - {% endif %} -
  • B: {{ item.payload.b_answer|default:''|safe }}
  • - {% if item.payload.b_feedback %} -

    B Feedback: {{ item.payload.b_feedback|default:''|safe }}

    - {% endif %} -
  • C: {{ item.payload.c_answer|default:''|safe }}
  • - {% if item.payload.c_feedback %} -

    C Feedback: {{ item.payload.c_feedback|default:''|safe }}

    - {% endif %} -
  • D: {{ item.payload.d_answer|default:''|safe }}
  • - {% if item.payload.d_feedback %} -

    D Feedback: {{ item.payload.d_feedback|default:''|safe }}

    - {% endif %} -
  • E: {{ item.payload.e_answer|default:''|safe }}
  • - {% if item.payload.e_feedback %} -

    E Feedback: {{ item.payload.e_feedback|default:''|safe }}

    - {% endif %} - -
-

Best Answer: {{ item.payload.best_answer|default:'' }} -

-

Feedback: {{ item.payload.feedback|default:''|safe }}

-

Sources: - {% if item.payload.sources %} -

    - {% for source in item.payload.sources %} -
  • {{ source }}
  • - {% endfor %} -
- {% else %} - None - {% endif %} -

- {% endif %} -

M2M fields (click to exclude)

-

Green = will be created/attached. Click a value to exclude it (grey).

+ + +
+
+ + +
+
+ +
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + +
+
+ + +
+
Sources: {% if item.payload.sources %}{{ item.payload.sources|join:", " }}{% else %}None{% endif %}
+

M2M fields (click to exclude)

+

Green = will be created/attached. Click a value to exclude it (grey).

+
-
Finding: - {% if item.resolved_m2m.finding %} - {% for val in item.resolved_m2m.finding %} - +
Finding: + {% if item.resolved_m2m.finding %} + {% for val in item.resolved_m2m.finding %} + + {% endfor %} + {% endif %} + {% if item.missing_map.finding %} + {% for val in item.missing_map.finding %} + + {% endfor %} + {% endif %} + + {% if item.missing_map.finding %} +
Would create: {{ item.missing_map.finding|join:", " }}
+ {% endif %} +
+
+ + +
Structure: + {% if item.resolved_m2m.structure %} + {% for val in item.resolved_m2m.structure %} + {% endfor %} {% endif %} - {% if item.missing_map.finding %} - {% for val in item.missing_map.finding %} - + {% if item.missing_map.structure %} + {% for val in item.missing_map.structure %} + {% endfor %} {% endif %} - {% if item.missing_map.finding %} -
Would create: {{ item.missing_map.finding|join:", " }}
+ {% if item.missing_map.structure %} +
Would create: {{ item.missing_map.structure|join:", " }}
{% endif %}
-
- - -
Structure: - {% if item.resolved_m2m.structure %} - {% for val in item.resolved_m2m.structure %} - - {% endfor %} - {% endif %} - {% if item.missing_map.structure %} - {% for val in item.missing_map.structure %} - - {% endfor %} - {% endif %} - - {% if item.missing_map.structure %} -
Would create: {{ item.missing_map.structure|join:", " }}
- {% endif %} -
-
Condition: - {% if item.resolved_m2m.condition %} - {% for val in item.resolved_m2m.condition %} - - {% endfor %} - {% endif %} - {% if item.missing_map.condition %} - {% for val in item.missing_map.condition %} - - {% endfor %} - {% endif %} - - {% if item.missing_map.condition %} -
Would create: {{ item.missing_map.condition|join:", " }}
- {% endif %} -
+
Condition: + {% if item.resolved_m2m.condition %} + {% for val in item.resolved_m2m.condition %} + + {% endfor %} + {% endif %} + {% if item.missing_map.condition %} + {% for val in item.missing_map.condition %} + + {% endfor %} + {% endif %} + + {% if item.missing_map.condition %} +
Would create: {{ item.missing_map.condition|join:", " }}
+ {% endif %} +
-
Presentation: - {% if item.resolved_m2m.presentation %} - {% for val in item.resolved_m2m.presentation %} - - {% endfor %} - {% endif %} - {% if item.missing_map.presentation %} - {% for val in item.missing_map.presentation %} - - {% endfor %} - {% endif %} - - {% if item.missing_map.presentation %} -
Would create: {{ item.missing_map.presentation|join:", " }}
- {% endif %} -
+
Presentation: + {% if item.resolved_m2m.presentation %} + {% for val in item.resolved_m2m.presentation %} + + {% endfor %} + {% endif %} + {% if item.missing_map.presentation %} + {% for val in item.missing_map.presentation %} + + {% endfor %} + {% endif %} + + {% if item.missing_map.presentation %} +
Would create: {{ item.missing_map.presentation|join:", " }}
+ {% endif %} +
-
Subspecialty: - {% if item.resolved_m2m.subspecialty %} - {% for val in item.resolved_m2m.subspecialty %} - - {% endfor %} - {% endif %} - {% if item.missing_map.subspecialty %} - {% for val in item.missing_map.subspecialty %} - - {% endfor %} - {% endif %} - - {% if item.missing_map.subspecialty %} -
Would create: {{ item.missing_map.subspecialty|join:", " }}
- {% endif %} -
- -
Category: - {{ item.payload.category|default:'(none)' }} +
Subspecialty: + {% if item.resolved_m2m.subspecialty %} + {% for val in item.resolved_m2m.subspecialty %} + + {% endfor %} + {% endif %} + {% if item.missing_map.subspecialty %} + {% for val in item.missing_map.subspecialty %} + + {% endfor %} + {% endif %} + + {% if item.missing_map.subspecialty %} +
Would create: {{ item.missing_map.subspecialty|join:", " }}
+ {% endif %} +
+ +
Category: + {{ item.payload.category|default:'(none)' }} -
+
- +
+ +
-
+
+
-
{% endfor %}
@@ -255,3 +267,22 @@ missing_map: {{ item.missing_map|default:"{}" }} + + diff --git a/sbas/views.py b/sbas/views.py index a5d190e2..d2607f71 100644 --- a/sbas/views.py +++ b/sbas/views.py @@ -950,6 +950,20 @@ def import_llm_confirm(request): except Exception: errors.append({"index": idx, "errors": ["Missing candidate"]}) continue + # Overlay any edited fields posted from the preview form (names like payload__stem) + overlay = {} + prefix = f"payload_{idx}_" + for k, v in request.POST.items(): + if k.startswith(prefix): + field = k[len(prefix):] + overlay[field] = v + if overlay: + # apply overlay onto a shallow copy + new_payload = dict(payload) + for fk, fv in overlay.items(): + # convert list-like fields and numeric conversions are not performed here; keep simple strings/lists + new_payload[fk] = fv + payload = new_payload # Strip numeric bracket references here as well, before confirm import payload, stripped = _strip_numeric_refs_in_payload(payload) if stripped: