Skip to content

Commit

Permalink
Merge pull request #90 from 3liz/fix-to-bool
Browse files Browse the repository at this point in the history
Fix invalid test in to_bool
  • Loading branch information
dmarteau authored Sep 27, 2024
2 parents 7fa3373 + 88d5655 commit 37bbe34
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lizmap_server/get_legend_graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def responseComplete(self):
if not style:
style = params.get('STYLE', '')

show_feature_count = to_bool(params.get('SHOWFEATURECOUNT'), default_value=False)
show_feature_count = to_bool(params.get('SHOWFEATURECOUNT'))

current_style = ''
layer = find_layer(layer_name, project)
Expand Down
4 changes: 2 additions & 2 deletions lizmap_server/plausible.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def __init__(self):

def request_stat_event(self) -> bool:
""" Request to send an event to the API. """
if to_bool(os.getenv(ENV_SKIP_STATS), default_value=False):
if to_bool(os.getenv(ENV_SKIP_STATS)):
# Disabled by environment variable
return False

if to_bool(os.getenv("CI"), default_value=False):
if to_bool(os.getenv("CI")):
# If running on CI, do not send stats
return False

Expand Down
9 changes: 3 additions & 6 deletions lizmap_server/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
"""


def to_bool(val: Union[str, int, float, bool], default_value: bool = True) -> bool:
def to_bool(val: Union[str, int, float, bool, None]) -> bool:
""" Convert lizmap config value to boolean """
if isinstance(val, str):
# For string, compare lower value to True string
return val.lower() in ('yes', 'true', 't', '1')
elif not val:
# For value like False, 0, 0.0, None, empty list or dict returns False
return False
else:
return default_value
return bool(val)


def version() -> str:
Expand All @@ -49,7 +46,7 @@ def version() -> str:

def check_environment_variable() -> bool:
""" Check the server configuration. """
if not to_bool(os.environ.get('QGIS_SERVER_LIZMAP_REVEAL_SETTINGS', ''), default_value=False):
if not to_bool(os.environ.get('QGIS_SERVER_LIZMAP_REVEAL_SETTINGS', '')):
QgsMessageLog.logMessage(
'The Lizmap API is currently not enabled. Please read the documentation how to enable the Lizmap API '
'on QGIS server side '
Expand Down

0 comments on commit 37bbe34

Please sign in to comment.