Refactor synonym management: extract synonyms list and add forms for adding synonyms with HTMX support

This commit is contained in:
Ross
2025-11-20 21:59:50 +00:00
parent 21de543313
commit 9d57d03cbb
3 changed files with 71 additions and 27 deletions
+14
View File
@@ -860,6 +860,9 @@ def condition_detail(request, pk):
if form.is_valid():
other = form.cleaned_data.get("condition")
# keep the form (possibly with errors) to render back in HTMX responses
synonym_form = form
# If no autocomplete selection, accept a free-text name
synonym_name = request.POST.get("synonym_name")
if not other and synonym_name:
@@ -874,6 +877,17 @@ def condition_detail(request, pk):
condition.synonym.add(other)
other.synonym.add(condition)
# If this was an HTMX request return the updated synonyms partial so the
# page can be updated without a full redirect. Otherwise perform the
# existing redirect back to the detail page.
if request.htmx:
html = render_to_string(
"atlas/partials/_synonyms_list.html",
{"condition": condition, "synonym_form": synonym_form, "can_merge": can_merge},
request=request,
)
return HttpResponse(html)
return redirect("atlas:condition_detail", pk=condition.pk)
# logging.debug(atlas.subspecialty.first().name.all())