Skip to content

Commit 56db60f

Browse files
Fixes #20375: Preserve filter params when performing bulk operations (#20387)
1 parent 3c09ee8 commit 56db60f

File tree

8 files changed

+25
-16
lines changed

8 files changed

+25
-16
lines changed

netbox/netbox/object_actions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def get_url(cls, obj):
5050
except NoReverseMatch:
5151
return
5252

53+
@classmethod
54+
def get_url_params(cls, context):
55+
request = context['request']
56+
params = request.GET.copy()
57+
if 'return_url' in context:
58+
params['return_url'] = context['return_url']
59+
return params
60+
5361
@classmethod
5462
def get_context(cls, context, obj):
5563
"""
@@ -63,6 +71,7 @@ def render(cls, context, obj, **kwargs):
6371
'perms': context['perms'],
6472
'request': context['request'],
6573
'url': cls.get_url(obj),
74+
'url_params': cls.get_url_params(context),
6675
'label': cls.label,
6776
**cls.get_context(context, obj),
6877
**kwargs,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button type="submit" name="_sync" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-primary">
1+
<button type="submit" name="_sync" {% formaction %}="{{ url }}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="btn btn-primary">
22
<i class="mdi mdi-sync" aria-hidden="true"></i> {{ label }}
33
</button>

netbox/templates/dcim/buttons/bulk_add_components.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,63 @@
66
<ul class="dropdown-menu">
77
{% if perms.dcim.add_consoleport %}
88
<li>
9-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_consoleport' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
9+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_consoleport' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
1010
{% trans "Console Ports" %}
1111
</button>
1212
</li>
1313
{% endif %}
1414
{% if perms.dcim.add_consoleserverport %}
1515
<li>
16-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_consoleserverport' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item ">
16+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_consoleserverport' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item ">
1717
{% trans "Console Server Ports" %}
1818
</button>
1919
</li>
2020
{% endif %}
2121
{% if perms.dcim.add_powerport %}
2222
<li>
23-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_powerport' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
23+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_powerport' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
2424
{% trans "Power Ports" %}
2525
</button>
2626
</li>
2727
{% endif %}
2828
{% if perms.dcim.add_poweroutlet %}
2929
<li>
30-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_poweroutlet' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
30+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_poweroutlet' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
3131
{% trans "Power Outlets" %}
3232
</button>
3333
</li>
3434
{% endif %}
3535
{% if perms.dcim.add_interface %}
3636
<li>
37-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_interface' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
37+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_interface' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
3838
{% trans "Interfaces" %}
3939
</button>
4040
</li>
4141
{% endif %}
4242
{% if perms.dcim.add_rearport %}
4343
<li>
44-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_rearport' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
44+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_rearport' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
4545
{% trans "Rear Ports" %}
4646
</button>
4747
</li>
4848
{% endif %}
4949
{% if perms.dcim.add_devicebay %}
5050
<li>
51-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_devicebay' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
51+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_devicebay' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
5252
{% trans "Device Bays" %}
5353
</button>
5454
</li>
5555
{% endif %}
5656
{% if perms.dcim.add_modulebay %}
5757
<li>
58-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_modulebay' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
58+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_modulebay' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
5959
{% trans "Module Bays" %}
6060
</button>
6161
</li>
6262
{% endif %}
6363
{% if perms.dcim.add_inventoryitem %}
6464
<li>
65-
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_inventoryitem' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
65+
<button type="submit" {% formaction %}="{% url 'dcim:device_bulk_add_inventoryitem' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
6666
{% trans "Inventory Items" %}
6767
</button>
6868
</li>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button type="submit" name="_disconnect" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-red">
1+
<button type="submit" name="_disconnect" {% formaction %}="{{ url }}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="btn btn-red">
22
<i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i> {{ label }}
33
</button>

netbox/templates/virtualization/buttons/bulk_add_components.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<ul class="dropdown-menu">
77
{% if perms.virtualization.add_vminterface %}
88
<li>
9-
<button type="submit" {% formaction %}="{% url 'virtualization:virtualmachine_bulk_add_vminterface' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
9+
<button type="submit" {% formaction %}="{% url 'virtualization:virtualmachine_bulk_add_vminterface' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
1010
{% trans "Interfaces" %}
1111
</button>
1212
</li>
1313
{% endif %}
1414
{% if perms.virtualization.add_virtualdisk %}
1515
<li>
16-
<button type="submit" {% formaction %}="{% url 'virtualization:virtualmachine_bulk_add_virtualdisk' %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="dropdown-item">
16+
<button type="submit" {% formaction %}="{% url 'virtualization:virtualmachine_bulk_add_virtualdisk' %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="dropdown-item">
1717
{% trans "Virtual Disks" %}
1818
</button>
1919
</li>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button type="submit" name="_delete" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-red">
1+
<button type="submit" name="_delete" {% formaction %}="{{ url }}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="btn btn-red">
22
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {{ label }}
33
</button>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button type="submit" name="_edit" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-yellow">
1+
<button type="submit" name="_edit" {% formaction %}="{{ url }}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="btn btn-yellow">
22
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
33
</button>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% if url %}
2-
<button type="submit" name="_rename" {% formaction %}="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" class="btn btn-yellow">
2+
<button type="submit" name="_rename" {% formaction %}="{{ url }}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="btn btn-yellow">
33
<i class="mdi mdi-pencil" aria-hidden="true"></i> {{ label }}
44
</button>
55
{% endif %}

0 commit comments

Comments
 (0)