mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Fixes #8101: Preserve return URL when using "create and add another" button
This commit is contained in:
parent
f95e510060
commit
e12da72615
@ -22,6 +22,7 @@
|
|||||||
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
|
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
|
||||||
* [#8092](https://github.com/netbox-community/netbox/issues/8092) - Rack elevations should not include device asset tags
|
* [#8092](https://github.com/netbox-community/netbox/issues/8092) - Rack elevations should not include device asset tags
|
||||||
* [#8096](https://github.com/netbox-community/netbox/issues/8096) - Fix DataError during change logging of objects with very long string representations
|
* [#8096](https://github.com/netbox-community/netbox/issues/8096) - Fix DataError during change logging of objects with very long string representations
|
||||||
|
* [#8101](https://github.com/netbox-community/netbox/issues/8101) - Preserve return URL when using "create and add another" button
|
||||||
* [#8102](https://github.com/netbox-community/netbox/issues/8102) - Raise validation error when attempting to assign an IP address to multiple objects
|
* [#8102](https://github.com/netbox-community/netbox/issues/8102) - Raise validation error when attempting to assign an IP address to multiple objects
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -371,8 +371,11 @@ class ObjectEditView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View):
|
|||||||
redirect_url = request.path
|
redirect_url = request.path
|
||||||
|
|
||||||
# If the object has clone_fields, pre-populate a new instance of the form
|
# If the object has clone_fields, pre-populate a new instance of the form
|
||||||
if hasattr(obj, 'clone_fields'):
|
params = prepare_cloned_fields(obj)
|
||||||
redirect_url += f"?{prepare_cloned_fields(obj)}"
|
if 'return_url' in request.GET:
|
||||||
|
params['return_url'] = request.GET.get('return_url')
|
||||||
|
if params:
|
||||||
|
redirect_url += f"?{params.urlencode()}"
|
||||||
|
|
||||||
return redirect(redirect_url)
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ def clone_button(instance):
|
|||||||
url = reverse(_get_viewname(instance, 'add'))
|
url = reverse(_get_viewname(instance, 'add'))
|
||||||
|
|
||||||
# Populate cloned field values
|
# Populate cloned field values
|
||||||
param_string = prepare_cloned_fields(instance)
|
param_string = prepare_cloned_fields(instance).urlencode()
|
||||||
if param_string:
|
if param_string:
|
||||||
url = f'{url}?{param_string}'
|
url = f'{url}?{param_string}'
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from typing import Any, Dict, List, Tuple
|
|||||||
from django.core.serializers import serialize
|
from django.core.serializers import serialize
|
||||||
from django.db.models import Count, OuterRef, Subquery
|
from django.db.models import Count, OuterRef, Subquery
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
|
from django.http import QueryDict
|
||||||
from jinja2.sandbox import SandboxedEnvironment
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
from mptt.models import MPTTModel
|
from mptt.models import MPTTModel
|
||||||
|
|
||||||
@ -249,10 +250,8 @@ def prepare_cloned_fields(instance):
|
|||||||
for tag in instance.tags.all():
|
for tag in instance.tags.all():
|
||||||
params.append(('tags', tag.pk))
|
params.append(('tags', tag.pk))
|
||||||
|
|
||||||
# Concatenate parameters into a URL query string
|
# Return a QueryDict with the parameters
|
||||||
param_string = '&'.join([f'{k}={v}' for k, v in params])
|
return QueryDict('&'.join([f'{k}={v}' for k, v in params]), mutable=True)
|
||||||
|
|
||||||
return param_string
|
|
||||||
|
|
||||||
|
|
||||||
def shallow_compare_dict(source_dict, destination_dict, exclude=None):
|
def shallow_compare_dict(source_dict, destination_dict, exclude=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user