1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#11625: Employ HTMX form rendering for device & VM interfaces

This commit is contained in:
jeremystretch
2023-02-18 15:32:26 -05:00
parent 368e774ceb
commit c84f0de8f8
13 changed files with 75 additions and 274 deletions

View File

@ -12,6 +12,7 @@ __all__ = (
'expand_alphanumeric_pattern',
'expand_ipaddress_pattern',
'form_from_model',
'get_field_value',
'get_selected_values',
'parse_alphanumeric_range',
'parse_numeric_range',
@ -113,6 +114,21 @@ def expand_ipaddress_pattern(string, family):
yield ''.join([lead, format(i, 'x' if family == 6 else 'd'), remnant])
def get_field_value(form, field_name):
"""
Return the current bound or initial value associated with a form field, prior to calling
clean() for the form.
"""
field = form.fields[field_name]
if form.is_bound:
if data := form.data.get(field_name):
if field.valid_value(data):
return data
return form.get_initial_for_field(field, field_name)
def get_selected_values(form, field_name):
"""
Return the list of selected human-friendly values for a form field