From 345c96f99aa98d5e90a46fa3f175ec0a2e6d4f36 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Sat, 9 Jul 2022 11:49:39 +1000 Subject: Fix links-to-node failing on load Was setting SERVER_URL incorrectly Also changed server API to include 'excl' param --- backend/tilo.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'backend/tilo.py') diff --git a/backend/tilo.py b/backend/tilo.py index 2f49baa..f2a177e 100755 --- a/backend/tilo.py +++ b/backend/tilo.py @@ -22,7 +22,8 @@ Expected HTTP query parameters: If 'sugg', reply with a SearchSuggResponse, describing search suggestions for the possibly-partial name. If 'info', reply with an InfoResponse, describing the named node. - toroot: Used with type=node, and causes inclusion of ancestors, and their children. - The value names a node whose ancestors need not be included. + A value of 1 indicates true, and other indicate false +- excl: Used with toroot, and names a node whose ancestors need not be included. - limit: Used with type=sugg to specify the max number of suggestions. - tree: Specifies which tree should be used. May be 'trimmed', 'images', or 'picked', corresponding to the @@ -239,8 +240,8 @@ def handleReq(dbCur, environ): return None # Get data of requested type if reqType == "node": - toroot = queryDict["toroot"][0] if "toroot" in queryDict else None - if toroot == None: + toroot = queryDict["toroot"][0] == '1' if "toroot" in queryDict else False + if not toroot: tolNodes = lookupNodes([name], tree, dbCur) if len(tolNodes) > 0: tolNode = tolNodes[name] @@ -250,15 +251,16 @@ def handleReq(dbCur, environ): else: # Get ancestors to skip inclusion of nodesToSkip = set() - nodeName = toroot - edgesTable = f"edges_{getTableSuffix(tree)}" - while True: - row = dbCur.execute(f"SELECT parent FROM {edgesTable} WHERE child = ?", (nodeName,)).fetchone() - if row == None: - break - parent = row[0] - nodesToSkip.add(parent) - nodeName = parent + nodeName = queryDict["excl"][0] if "excl" in queryDict else None + if nodeName != None: + edgesTable = f"edges_{getTableSuffix(tree)}" + while True: + row = dbCur.execute(f"SELECT parent FROM {edgesTable} WHERE child = ?", (nodeName,)).fetchone() + if row == None: + break + parent = row[0] + nodesToSkip.add(parent) + nodeName = parent # results = {} ranOnce = False -- cgit v1.2.3