fix: Template and non-template fields example

This commit is contained in:
kr3ator 2022-04-12 14:50:03 +02:00
parent 57da852af6
commit d482e623df
2 changed files with 6 additions and 6 deletions

View File

@ -31,8 +31,7 @@
# - name_template: ttyS[1-48] # - name_template: ttyS[1-48]
# type: rj-45 # type: rj-45
# power_ports: # power_ports:
# - name: psu0 # both non-template and template field specified; non-template field takes precedence # - name_template: psu[0,1]
# name_template: psu[0,1]
# type: iec-60320-c14 # type: iec-60320-c14
# maximum_draw: 35 # maximum_draw: 35
# allocated_draw: 35 # allocated_draw: 35
@ -46,7 +45,9 @@
# type: 8p8c # type: 8p8c
# positions_template: "[3,2]" # positions_template: "[3,2]"
# device_bays: # device_bays:
# - name_template: bay[0-9] # - name: bay0 # both non-template and template field specified; non-template field takes precedence
# name_template: bay[0-9]
# label: test0
# label_template: test[0-5,9,6-8] # label_template: test[0-5,9,6-8]
# description: Test description # description: Test description
# power_outlets: # power_outlets:

View File

@ -36,14 +36,13 @@ def expand_templates(params: List[dict], device_type: DeviceType) -> List[dict]:
if field in param: if field in param:
has_plain_fields = True has_plain_fields = True
expanded.append(param)
elif template_value: elif template_value:
expanded_fields[field] = list(expand_alphanumeric_pattern(template_value)) expanded_fields[field] = list(expand_alphanumeric_pattern(template_value))
if expanded_fields and has_plain_fields: if expanded_fields and has_plain_fields:
raise ValueError(f"Mix of plain and template keys provided for {templateable_fields}") raise ValueError(f"Mix of plain and template keys provided for {templateable_fields}")
elif not expanded_fields:
if not expanded_fields: expanded.append(param)
continue continue
elements = list(expanded_fields.values()) elements = list(expanded_fields.values())