| Trees | Indices | Help |
|---|
|
|
1 # $Id: json.py,v 1.3 2006/12/31 09:10:14 lmacken Exp $
2 # This module provides helper functions for the JSON part of your
3 # view, if you are providing a JSON-based API for your app.
4
5 # Here's what most rules would look like:
6 # @jsonify.when("isinstance(obj, YourClass)")
7 # def jsonify_yourclass(obj):
8 # return [obj.val1, obj.val2]
9 # The goal is to break your objects down into simple values:
10 # lists, dicts, numbers and strings
11 #
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Library General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 from turbojson.jsonify import jsonify
26 from turbojson.jsonify import jsonify_sqlobject
27 from bodhi.model import User, Group, Permission
28
29 @jsonify.when('isinstance(obj, Group)')
31 result = jsonify_sqlobject( obj )
32 result["users"] = [u.user_name for u in obj.users]
33 result["permissions"] = [p.permission_name for p in obj.permissions]
34 return result
35
36 @jsonify.when('isinstance(obj, User)')
38 result = jsonify_sqlobject( obj )
39 del result['password']
40 result["groups"] = [g.group_name for g in obj.groups]
41 result["permissions"] = [p.permission_name for p in obj.permissions]
42 return result
43
44 @jsonify.when('isinstance(obj, Permission)')
46 result = jsonify_sqlobject( obj )
47 result["groups"] = [g.group_name for g in obj.groups]
48 return result
49
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0beta1 on Sun Sep 23 14:46:39 2007 | http://epydoc.sourceforge.net |