comparison libervia/server/pages.py @ 1304:70e3341d25bf

pages: take care of None/null when exposing a variable
author Goffi <goffi@goffi.org>
date Thu, 16 Jul 2020 09:08:50 +0200
parents 04e7dd6b6f4d
children db9ea167c409
comparison
equal deleted inserted replaced
1303:a48fe20f60c7 1304:70e3341d25bf
552 No check is done for conflicting name, use this carefully 552 No check is done for conflicting name, use this carefully
553 """ 553 """
554 template_data = request.template_data 554 template_data = request.template_data
555 scripts = template_data.setdefault("scripts", utils.OrderedSet()) 555 scripts = template_data.setdefault("scripts", utils.OrderedSet())
556 for name, value in kwargs.items(): 556 for name, value in kwargs.items():
557 scripts.add(Script(content=f"var {name}={value!r};")) 557 if value is None:
558 value = "null"
559 else:
560 value = repr(value)
561 scripts.add(Script(content=f"var {name}={value};"))
558 562
559 def registerURI(self, uri_tuple, get_uri_cb): 563 def registerURI(self, uri_tuple, get_uri_cb):
560 """Register a URI handler 564 """Register a URI handler
561 565
562 @param uri_tuple(tuple[unicode, unicode]): type or URIs handler 566 @param uri_tuple(tuple[unicode, unicode]): type or URIs handler