-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 #12579 create cable and add another error #13007
Fix #12579 create cable and add another error #13007
Conversation
netbox/dcim/views.py
Outdated
@@ -3131,6 +3131,13 @@ def get_object(self, **kwargs): | |||
|
|||
return obj | |||
|
|||
def get_extra_addanother_params(self, request): | |||
return { | |||
'termination_a_device': resolve(request.GET.get('return_url')).kwargs.get('pk'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume the A side will be a device; it could also be a power feed or circuit termination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. I have updated this PR as requested.
netbox/dcim/views.py
Outdated
pk = resolve(request.GET.get('return_url')).kwargs.get('pk') | ||
a_type = CABLE_TERMINATION_TYPES.get(request.GET.get('a_terminations_type')) | ||
|
||
if hasattr(a_type, 'device'): | ||
params.update({'termination_a_device': pk}) | ||
elif hasattr(a_type, 'power_panel'): | ||
params.update({'termination_a_powerpanel': pk}) | ||
elif hasattr(a_type, 'circuit'): | ||
params.update({'termination_a_circuit': pk}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could instead do:
pk = resolve(request.GET.get('return_url')).kwargs.get('pk') | |
a_type = CABLE_TERMINATION_TYPES.get(request.GET.get('a_terminations_type')) | |
if hasattr(a_type, 'device'): | |
params.update({'termination_a_device': pk}) | |
elif hasattr(a_type, 'power_panel'): | |
params.update({'termination_a_powerpanel': pk}) | |
elif hasattr(a_type, 'circuit'): | |
params.update({'termination_a_circuit': pk}) | |
for key in request.POST: | |
if 'device' in key or 'power_panel' in key or 'circuit' in key: | |
params.update({key: request.POST.get(key}) |
This lets you remove the resolve import and also improves the workflow for people adding multiple cables between two separate devices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion. I have updated this PR as requested.
Thanks @netopsab! |
Fixes: #12579
Add
get_extra_addanother_params
function toCableEditView
which return :a_termination_device
ora_termination_powerpanel
ora_termination_circuit
)a_termination_type
andb_termination_type
)