helpers: Enable search for gateways

Introduces two new query parameters:
gw:<mac> looks for routers being aware of the specified gateway
selected:<mac> looks for routers CONNECTED to the specified gw

Both variants support regex.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-01-11 14:18:42 +01:00
parent 386384212e
commit d7bdca4797
1 changed files with 10 additions and 0 deletions

View File

@ -27,6 +27,8 @@ allowed_filters = (
'community',
'neighbor',
'neighbour',
'gw',
'selected',
)
def parse_router_list_search_query(args):
@ -66,6 +68,14 @@ def parse_router_list_search_query(args):
j += " INNER JOIN ( SELECT router, mac FROM router_netif GROUP BY router, mac) AS j ON router.id = j.router "
k = "mac {} REGEXP %s".format(no)
t.append(value.lower())
elif (key == 'gw'):
j += " INNER JOIN router_gw ON router.id = router_gw.router "
k = "router_gw.mac {} REGEXP %s".format(no)
t.append(value.lower())
elif (key == 'selected'):
j += " INNER JOIN router_gw ON router.id = router_gw.router "
k = "router_gw.mac {} REGEXP %s AND router_gw.selected = TRUE".format(no)
t.append(value.lower())
elif (key == 'neighbor') or (key == 'neighbour'):
j += " INNER JOIN ( SELECT router, mac FROM router_neighbor GROUP BY router, mac) AS j ON router.id = j.router "
k = "mac {} REGEXP %s".format(no)