Build output string in one big expression
Build output string in component_table_entry() as the similar strings in generate_bom(). Repeating a couple of minor if-expressions is small cost to obtain a more compact and readable main expression.
This commit is contained in:
parent
d6d0d2a486
commit
d15eeb1f9f
@ -145,25 +145,18 @@ def component_table_entry(
|
|||||||
mpn: Optional[str] = None,
|
mpn: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Return a diagram node table row string with an additional component."""
|
"""Return a diagram node table row string with an additional component."""
|
||||||
output = f'{qty}'
|
|
||||||
if unit:
|
|
||||||
output += f' {unit}'
|
|
||||||
output += f' x {type}'
|
|
||||||
# print an extra line with part and manufacturer information if provided
|
|
||||||
manufacturer_str = manufacturer_info_field(manufacturer, mpn)
|
manufacturer_str = manufacturer_info_field(manufacturer, mpn)
|
||||||
if pn or manufacturer_str:
|
output = (f'{qty}'
|
||||||
output += '<br/>'
|
+ (f' {unit}' if unit else '')
|
||||||
if pn:
|
+ f' x {type}'
|
||||||
output += f'P/N: {pn}'
|
+ ('<br/>' if pn or manufacturer_str else '')
|
||||||
if manufacturer_str:
|
+ (f'P/N: {pn}' if pn else '')
|
||||||
output += ', '
|
+ (', ' if pn and manufacturer_str else '')
|
||||||
if manufacturer_str:
|
+ (manufacturer_str or ''))
|
||||||
output += manufacturer_str
|
|
||||||
output = html_line_breaks(output)
|
|
||||||
# format the above output as left aligned text in a single visible cell
|
# format the above output as left aligned text in a single visible cell
|
||||||
# indent is set to two to match the indent in the generated html table
|
# indent is set to two to match the indent in the generated html table
|
||||||
return f'''<table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
|
return f'''<table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
|
||||||
<td align="left" balign="left">{output}</td>
|
<td align="left" balign="left">{html_line_breaks(output)}</td>
|
||||||
</tr></table>'''
|
</tr></table>'''
|
||||||
|
|
||||||
def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]:
|
def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user