Update utils.py

Updated to use the tested and better documented version (Is not tested with Matomo or Django. Only with python)
This commit is contained in:
SilverStrings (Matt) 2021-07-12 18:06:37 -04:00 committed by GitHub
parent 85c651f6f6
commit 3a514444f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,9 +176,10 @@ def build_paq_cmd(cmd, args=[]):
"""
def __to_js_arg(arg):
"""
Turn the argument into a js variable.
True -> true
False -> false
:Args:
- arg: The variable (Matomo argument) to be converted to JS.
:Return:
Javascript version of the passed arg parameter
"""
# Recursively handle dictionaries
if isinstance(arg, dict):
@ -187,18 +188,14 @@ def build_paq_cmd(cmd, args=[]):
arg.pop(k)
arg[__to_js_arg(k)] = __to_js_arg(v)
return arg
# Handle bools
elif isinstance(arg, bool):
if arg:
arg = "true"
else:
arg = "false"
# Handle lists
elif isinstance(arg, list):
for elem_idx in range(len(arg)):
arg[elem_idx] = __to_js_arg(arg[elem_idx])
return arg
paq = "_paq.push(['%s', " % (cmd)