Skip to content
Snippets Groups Projects
Commit 7f39c902 authored by Erik Reid's avatar Erik Reid
Browse files

added get_service_users

parent 8b1f511b
No related branches found
No related tags found
No related merge requests found
...@@ -436,3 +436,30 @@ AND circuit_type = 'Path' ...@@ -436,3 +436,30 @@ AND circuit_type = 'Path'
crs.execute(parent_query, [circuit['absid']]) crs.execute(parent_query, [circuit['absid']])
r = _convert_to_dict(crs) r = _convert_to_dict(crs)
return _fields2rsp(r[0]) if r else None return _fields2rsp(r[0]) if r else None
def get_service_users(connection, service_ids):
def _sublists(l, n):
for x in range(0, len(l), n):
yield l[x:x + n]
# not sure how to use a tuple in a prepared statement,
# so this is just doing a dumb string replacement ...
query = (
'select c.absid, o.name'
' from organisation o'
' join circuit_orgs co on co.org_absid=o.absid'
' join circuit c on c.absid=co.circ_absid'
' where co.org_type=\'Circuit User\''
' and c.absid in (%s)')
with db.cursor(connection) as crs:
for chunk in _sublists(service_ids, 20):
crs.execute(query % ','.join([str(x) for x in chunk]))
for r in crs.fetchall():
yield {'service_id': r[0], 'user': r[1]}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment