Skip to content

Commit

Permalink
Only update row related to affected destination
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Jan 10, 2025
1 parent fdfda05 commit a966c11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
11 changes: 2 additions & 9 deletions src/argus/htmx/destination/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,10 @@ def delete_htmx(request, pk: int) -> HttpResponse:
def update_htmx(request, pk: int) -> HttpResponse:
destination = DestinationConfig.objects.get(pk=pk)
form = DestinationFormUpdate(request.POST or None, instance=destination, request=request)
template = "htmx/destination/_form_list.html"
if form.is_valid():
form.save()
return _render_destination_list(request, template=template)

update_forms = _get_update_forms(request.user)
for index, update_form in enumerate(update_forms):
if update_form.instance.pk == pk:
update_forms[index] = form
break
return _render_destination_list(request, update_forms=update_forms, template=template)
context = {"form": form, "update_error_msg": None}
return render(request, "htmx/destination/_update_and_delete_form.html", context=context)


def _render_destination_list(
Expand Down
3 changes: 2 additions & 1 deletion src/argus/htmx/templates/htmx/destination/_edit_form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<form hx-post="{% url 'htmx:htmx-update' form.instance.id %}"
hx-trigger="submit"
hx-target="#form-list"
hx-target="closest #update-delete-forms"
hx-swap="outerHTML"
class="flex flex-nowrap items-center gap-4">
{% csrf_token %}
<fieldset class="flex flex-nowrap items-center gap-4">
Expand Down

0 comments on commit a966c11

Please sign in to comment.