Skip to content

Commit

Permalink
Merge pull request #594 from Gustry/string
Browse files Browse the repository at this point in the history
Bulk conversion to fstring format for tooltip.py
  • Loading branch information
Gustry authored Aug 13, 2024
2 parents 80d2b42 + e8aca64 commit 5ca91a9
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions lizmap/tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def create_popup_node_item_from_form(
if node.idx() < 0:
# The form might have been imported from QML with some not existing fields
LOGGER.warning(
'Layer {} does not have a valid editor field'.format(layer.id()))
f'Layer {layer.id()} does not have a valid editor field')
return html

field = layer.fields()[node.idx()]
Expand Down Expand Up @@ -167,7 +167,7 @@ def create_popup_node_item_from_form(
regex.sub('_', node.name()), active)

if visibility and active:
active = '{} {}'.format(active, visibility)
active = f'{active} {visibility}'
if visibility and not active:
active = visibility
h += '\n' + SPACES
Expand All @@ -177,8 +177,8 @@ def create_popup_node_item_from_form(
headers.append(h)

if lvl > 1:
a += '\n' + SPACES * lvl + '<fieldset class="{}">'.format(visibility)
a += '\n' + SPACES * lvl + '<legend>{}</legend>'.format(node.name())
a += '\n' + SPACES * lvl + f'<fieldset class="{visibility}">'
a += '\n' + SPACES * lvl + f'<legend>{node.name()}</legend>'
a += '\n' + SPACES * lvl + '<div>'

# In case of root children
Expand Down Expand Up @@ -238,7 +238,7 @@ def _generate_eval_visibility(expression: str) -> str:
@staticmethod
def _generate_attribute_editor_relation(label: str, relation_id: str, referencing_layer_id: str) -> str:
""" Generate the div. LWC will manage to include children in the given div."""
result = '\n' + SPACES + '<p><b>{}</b></p>'.format(label)
result = '\n' + SPACES + f'<p><b>{label}</b></p>'
result += '\n' + SPACES
result += (
'<div id="popup_relation_{0}" data-relation-id="{0}" data-referencing-layer-id="{1}" '
Expand All @@ -254,9 +254,9 @@ def _generate_relation_reference(
layer_id: str,
display_expression: str,
) -> str:
expression = '''
"{}" = attribute(@parent, '{}')
'''.format(parent_pk, name)
expression = f'''
"{parent_pk}" = attribute(@parent, '{name}')
'''

field_view = '''
aggregate(
Expand Down Expand Up @@ -315,11 +315,11 @@ def escape_value(value: str) -> str:

# noinspection PyCallByClass,PyArgumentList
hstore = QgsHstoreUtils.build(values)
field_view = '''
field_view = f'''
map_get(
hstore_to_map('{}'),
replace("{}", '\\'', '’')
)'''.format(hstore, name)
hstore_to_map('{hstore}'),
replace("{name}", '\\'', '’')
)'''
return field_view

@staticmethod
Expand Down Expand Up @@ -379,29 +379,26 @@ def _generate_date(widget_config: dict, name: str) -> str:
# Fallback to ISO 8601, when the widget has not been configured yet
date_format = "yyyy-MM-dd"

field_view = '''
field_view = f'''
format_date(
"{}",
'{}'
)'''.format(name, date_format)
"{name}",
'{date_format}'
)'''
return field_view

@staticmethod
def _generate_value_relation(widget_config: dict, name: str) -> str:
vlid = widget_config['Layer']

expression = '''"{}" = attribute(@parent, '{}')'''.format(
widget_config['Key'],
name,
)
expression = f'''"{widget_config['Key']}" = attribute(@parent, '{name}')'''

filter_exp = widget_config.get('FilterExpression', '').strip()
if filter_exp:
# replace @current_geometry only available in form by geometry(@parent) for aggregate
filter_exp = filter_exp.replace('@current_geometry', 'geometry(@parent)')
# replace current_value( only available in form by attribute(@parent, for aggregate
filter_exp = filter_exp.replace('current_value(', 'attribute(@parent, ')
expression += ' AND {}'.format(filter_exp)
expression += f' AND {filter_exp}'

field_view = '''
aggregate(
Expand All @@ -418,14 +415,11 @@ def _generate_value_relation(widget_config: dict, name: str) -> str:

@staticmethod
def _generate_text_label(label: str, expression: str) -> str:
text = '''
<p><strong>{0}</strong>
<div class="field">{1}</div>
text = f'''
<p><strong>{label}</strong>
<div class="field">{expression}</div>
</p>
'''.format(
label,
expression,
)
'''
return text

@staticmethod
Expand Down

0 comments on commit 5ca91a9

Please sign in to comment.