Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@jsonify.when('isinstance(obj, sqlalchemy.orm.query.Query)')
def jsonify_sa_select_results(obj):
'''Transform selectresults into lists.
The one special thing is that we bind the special json_props into each
descendent. This allows us to specify a json_props on the toplevel
query result and it will pass to all of its children.
:arg obj: sqlalchemy Query object to jsonify
:Returns: list representation of the Query with each element in it given
a json_props attributes
'''
if 'json_props' in obj.__dict__:
for element in obj:
element.json_props = obj.json_props
return list(obj)
@jsonify.when('isinstance(obj, Group)')
def jsonify_group(obj):
result = jsonify_sqlobject( obj )
result["users"] = [u.user_name for u in obj.users]
result["permissions"] = [p.permission_name for p in obj.permissions]
return result
@jsonify.when('isinstance(obj, User)')
def jsonify_user(obj):
result = jsonify_sqlobject( obj )
del result['password']
result["groups"] = [g.group_name for g in obj.groups]
result["permissions"] = [p.permission_name for p in obj.permissions]
return result