mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#10054: Simplify cable forms
This commit is contained in:
@@ -15,68 +15,16 @@ def get_cable_form(a_type, b_type):
|
||||
|
||||
for cable_end, term_cls in (('a', a_type), ('b', b_type)):
|
||||
|
||||
attrs[f'termination_{cable_end}_region'] = DynamicModelChoiceField(
|
||||
queryset=Region.objects.all(),
|
||||
label=_('Region'),
|
||||
required=False,
|
||||
initial_params={
|
||||
'sites': f'$termination_{cable_end}_site'
|
||||
}
|
||||
)
|
||||
attrs[f'termination_{cable_end}_sitegroup'] = DynamicModelChoiceField(
|
||||
queryset=SiteGroup.objects.all(),
|
||||
label=_('Site group'),
|
||||
required=False,
|
||||
initial_params={
|
||||
'sites': f'$termination_{cable_end}_site'
|
||||
}
|
||||
)
|
||||
attrs[f'termination_{cable_end}_site'] = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
label=_('Site'),
|
||||
required=False,
|
||||
query_params={
|
||||
'region_id': f'$termination_{cable_end}_region',
|
||||
'group_id': f'$termination_{cable_end}_sitegroup',
|
||||
}
|
||||
)
|
||||
attrs[f'termination_{cable_end}_location'] = DynamicModelChoiceField(
|
||||
queryset=Location.objects.all(),
|
||||
label=_('Location'),
|
||||
required=False,
|
||||
null_option='None',
|
||||
query_params={
|
||||
'site_id': f'$termination_{cable_end}_site'
|
||||
}
|
||||
)
|
||||
|
||||
# Device component
|
||||
if hasattr(term_cls, 'device'):
|
||||
|
||||
attrs[f'termination_{cable_end}_rack'] = DynamicModelChoiceField(
|
||||
queryset=Rack.objects.all(),
|
||||
label=_('Rack'),
|
||||
required=False,
|
||||
null_option='None',
|
||||
initial_params={
|
||||
'devices': f'$termination_{cable_end}_device'
|
||||
},
|
||||
query_params={
|
||||
'site_id': f'$termination_{cable_end}_site',
|
||||
'location_id': f'$termination_{cable_end}_location',
|
||||
}
|
||||
)
|
||||
attrs[f'termination_{cable_end}_device'] = DynamicModelChoiceField(
|
||||
queryset=Device.objects.all(),
|
||||
label=_('Device'),
|
||||
required=False,
|
||||
selector=True,
|
||||
initial_params={
|
||||
f'{term_cls._meta.model_name}s__in': f'${cable_end}_terminations'
|
||||
},
|
||||
query_params={
|
||||
'site_id': f'$termination_{cable_end}_site',
|
||||
'location_id': f'$termination_{cable_end}_location',
|
||||
'rack_id': f'$termination_{cable_end}_rack',
|
||||
}
|
||||
)
|
||||
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
|
||||
@@ -96,12 +44,9 @@ def get_cable_form(a_type, b_type):
|
||||
queryset=PowerPanel.objects.all(),
|
||||
label=_('Power Panel'),
|
||||
required=False,
|
||||
selector=True,
|
||||
initial_params={
|
||||
'powerfeeds__in': f'${cable_end}_terminations'
|
||||
},
|
||||
query_params={
|
||||
'site_id': f'$termination_{cable_end}_site',
|
||||
'location_id': f'$termination_{cable_end}_location',
|
||||
}
|
||||
)
|
||||
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
|
||||
@@ -116,23 +61,12 @@ def get_cable_form(a_type, b_type):
|
||||
# CircuitTermination
|
||||
elif term_cls == CircuitTermination:
|
||||
|
||||
attrs[f'termination_{cable_end}_provider'] = DynamicModelChoiceField(
|
||||
queryset=Provider.objects.all(),
|
||||
label=_('Provider'),
|
||||
initial_params={
|
||||
'circuits': f'$termination_{cable_end}_circuit'
|
||||
},
|
||||
required=False
|
||||
)
|
||||
attrs[f'termination_{cable_end}_circuit'] = DynamicModelChoiceField(
|
||||
queryset=Circuit.objects.all(),
|
||||
label=_('Circuit'),
|
||||
selector=True,
|
||||
initial_params={
|
||||
'terminations__in': f'${cable_end}_terminations'
|
||||
},
|
||||
query_params={
|
||||
'provider_id': f'$termination_{cable_end}_provider',
|
||||
'site_id': f'$termination_{cable_end}_site',
|
||||
}
|
||||
)
|
||||
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
|
||||
|
Reference in New Issue
Block a user