Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10094 - Contact Assignments Create and Add Another #10103

Merged
merged 5 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions netbox/netbox/views/generic/object_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ def alter_object(self, obj, request, url_args, url_kwargs):
"""
return obj

def get_extra_addanother_params(self, request, params):
arthanson marked this conversation as resolved.
Show resolved Hide resolved
"""
Return a QueryDict of extra params to use on the Add Another button.
"""
return params
arthanson marked this conversation as resolved.
Show resolved Hide resolved

#
# Request handlers
#
Expand Down Expand Up @@ -399,6 +405,7 @@ def post(self, request, *args, **kwargs):

# If cloning is supported, pre-populate a new instance of the form
params = prepare_cloned_fields(obj)
params = self.get_extra_addanother_params(request, params)
arthanson marked this conversation as resolved.
Show resolved Hide resolved
if params:
if 'return_url' in request.GET:
params['return_url'] = request.GET.get('return_url')
Expand Down
10 changes: 10 additions & 0 deletions netbox/tenancy/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.contenttypes.models import ContentType
from django.http import QueryDict
from django.shortcuts import get_object_or_404

from circuits.models import Circuit
Expand Down Expand Up @@ -365,6 +366,15 @@ def alter_object(self, instance, request, args, kwargs):
instance.object = get_object_or_404(content_type.model_class(), pk=request.GET.get('object_id'))
return instance

def get_extra_addanother_params(self, request, params: dict):
if not params:
params = QueryDict(mutable=True)

params['content_type'] = request.GET.get('content_type')
params['object_id'] = request.GET.get('object_id')

return params
arthanson marked this conversation as resolved.
Show resolved Hide resolved


class ContactAssignmentDeleteView(generic.ObjectDeleteView):
queryset = ContactAssignment.objects.all()
2 changes: 1 addition & 1 deletion netbox/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def prepare_cloned_fields(instance):
"""
# Generate the clone attributes from the instance
if not hasattr(instance, 'clone'):
return QueryDict()
return QueryDict(mutable=True)
attrs = instance.clone()

# Prepare querydict parameters
Expand Down