Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid test in to_bool #90

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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