1 # A JSON-based API(view) for your app.
2 # Most rules would look like:
3 # @jsonify.when("isinstance(obj, YourClass)")
4 # def jsonify_yourclass(obj):
5 # return [obj.val1, obj.val2]
6 # @jsonify can convert your objects to following types:
7 # lists, dicts, numbers and strings
9 from turbojson.jsonify import jsonify
11 from turbojson.jsonify import jsonify_sqlobject
12 from sercom.model import User, Group, Permission
14 @jsonify.when('isinstance(obj, Group)')
15 def jsonify_group(obj):
16 result = jsonify_sqlobject( obj )
17 result["users"] = [u.user_name for u in obj.users]
18 result["permissions"] = [p.permission_name for p in obj.permissions]
21 @jsonify.when('isinstance(obj, User)')
22 def jsonify_user(obj):
23 result = jsonify_sqlobject( obj )
24 del result['password']
25 result["groups"] = [g.group_name for g in obj.groups]
26 result["permissions"] = [p.permission_name for p in obj.permissions]
29 @jsonify.when('isinstance(obj, Permission)')
30 def jsonify_permission(obj):
31 result = jsonify_sqlobject( obj )
32 result["groups"] = [g.group_name for g in obj.groups]