mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Closes #17221: Extend ObjectEditView to support HTMX requests
This commit is contained in:
parent
fb6c7d7619
commit
91df0c0686
@ -234,6 +234,8 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
||||
# If this is an HTMX request, return only the rendered form HTML
|
||||
if htmx_partial(request):
|
||||
return render(request, self.htmx_template_name, {
|
||||
'model': model,
|
||||
'object': obj,
|
||||
'form': form,
|
||||
})
|
||||
|
||||
@ -288,6 +290,7 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
||||
msg = f'{msg} {obj}'
|
||||
messages.success(request, msg)
|
||||
|
||||
# If adding another object, redirect back to the edit form
|
||||
if '_addanother' in request.POST:
|
||||
redirect_url = request.path
|
||||
|
||||
@ -303,6 +306,12 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
||||
|
||||
return_url = self.get_return_url(request, obj)
|
||||
|
||||
# If the object has been created or edited via HTMX, return an HTMX redirect to the object view
|
||||
if request.htmx:
|
||||
return HttpResponse(headers={
|
||||
'HX-Location': return_url,
|
||||
})
|
||||
|
||||
return redirect(return_url)
|
||||
|
||||
except (AbortRequest, PermissionsViolation) as e:
|
||||
|
Loading…
Reference in New Issue
Block a user