Enhance case inline editing and search functionality with improved UI and new subspecialty handling
This commit is contained in:
+57
-18
@@ -761,6 +761,7 @@ CASE_INLINE_FIELD_CONFIG = {
|
||||
"discussion": {"label": "Discussion", "kind": "textarea"},
|
||||
"report": {"label": "Report", "kind": "textarea"},
|
||||
"diagnostic_certainty": {"label": "Diagnostic certainty", "kind": "select"},
|
||||
"subspecialty": {"label": "Subspecialty", "kind": "select"},
|
||||
}
|
||||
|
||||
|
||||
@@ -883,33 +884,69 @@ def case_inline_field(request, pk, field_name):
|
||||
show_label = request.GET.get("show_label", "1") not in ("0", "false", "False")
|
||||
error_message = ""
|
||||
|
||||
if request.method == "POST":
|
||||
if not can_edit:
|
||||
return HttpResponse(status=403)
|
||||
|
||||
editing = True
|
||||
cleaned_value, error_message = _validate_case_inline_value(
|
||||
field_name=field_name,
|
||||
raw_value=request.POST.get("value", ""),
|
||||
)
|
||||
if error_message:
|
||||
value = request.POST.get("value", "")
|
||||
# Special-case handling for many-to-many `subspecialty` field
|
||||
if field_name == "subspecialty":
|
||||
if request.method == "POST":
|
||||
if not can_edit:
|
||||
return HttpResponse(status=403)
|
||||
editing = True
|
||||
# Accept multiple values via POST list
|
||||
posted = request.POST.getlist("value")
|
||||
ids = []
|
||||
for v in posted:
|
||||
try:
|
||||
ids.append(int(v))
|
||||
except Exception:
|
||||
continue
|
||||
# keep only valid existing ids
|
||||
valid_ids = list(
|
||||
Subspecialty.objects.filter(pk__in=ids).values_list("pk", flat=True)
|
||||
)
|
||||
case.subspecialty.set(valid_ids)
|
||||
editing = False
|
||||
value = case.subspecialty.all()
|
||||
else:
|
||||
setattr(case, field_name, cleaned_value)
|
||||
case.save(update_fields=[field_name])
|
||||
editing = False
|
||||
value = getattr(case, field_name)
|
||||
value = case.subspecialty.all()
|
||||
if editing and not can_edit:
|
||||
editing = False
|
||||
else:
|
||||
value = getattr(case, field_name)
|
||||
if editing and not can_edit:
|
||||
editing = False
|
||||
if request.method == "POST":
|
||||
if not can_edit:
|
||||
return HttpResponse(status=403)
|
||||
|
||||
editing = True
|
||||
cleaned_value, error_message = _validate_case_inline_value(
|
||||
field_name=field_name,
|
||||
raw_value=request.POST.get("value", ""),
|
||||
)
|
||||
if error_message:
|
||||
value = request.POST.get("value", "")
|
||||
else:
|
||||
setattr(case, field_name, cleaned_value)
|
||||
case.save(update_fields=[field_name])
|
||||
editing = False
|
||||
value = getattr(case, field_name)
|
||||
else:
|
||||
value = getattr(case, field_name)
|
||||
if editing and not can_edit:
|
||||
editing = False
|
||||
|
||||
if field_name == "diagnostic_certainty":
|
||||
display_value = case.get_diagnostic_certainty_display()
|
||||
select_choices = [(str(choice.value), str(choice.label)) for choice in Case.CertaintyChoices]
|
||||
selected_values = []
|
||||
multiple = False
|
||||
elif field_name == "subspecialty":
|
||||
# For many-to-many, provide choices and selected values
|
||||
display_value = ", ".join([str(s) for s in case.subspecialty.all()])
|
||||
select_choices = [(str(s.pk), str(s.name)) for s in Subspecialty.objects.all()]
|
||||
selected_values = [str(s.pk) for s in case.subspecialty.all()]
|
||||
multiple = True
|
||||
else:
|
||||
display_value = value
|
||||
select_choices = []
|
||||
selected_values = []
|
||||
multiple = False
|
||||
|
||||
endpoint_url = reverse("atlas:case_inline_field", kwargs={"pk": case.pk, "field_name": field_name})
|
||||
if show_label:
|
||||
@@ -934,6 +971,8 @@ def case_inline_field(request, pk, field_name):
|
||||
"error_message": error_message,
|
||||
"suggestions": _get_case_inline_suggestions(case, field_name),
|
||||
"select_choices": select_choices,
|
||||
"selected_values": selected_values,
|
||||
"multiple": multiple,
|
||||
"endpoint_url_default": endpoint_url_default,
|
||||
"endpoint_url_edit": endpoint_url_edit,
|
||||
"container_id": f"case-inline-{field_name}",
|
||||
|
||||
Reference in New Issue
Block a user