# This file is part of ReportTool # ReportTool (Felicity) is copyright 2004-8 Steve Butterfill. # # ReportTool is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # ReportTool is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with ReportTool. If not, see . # # If you want to use ReportTool under a difference licence, email # s.butterfill@warwick.ac.uk. # A JSON-based API(view) for your app. # Most rules would look like: # # @jsonify.when("isinstance(obj, YourClass)") # def jsonify_yourclass(obj): # return [obj.val1, obj.val2] # # @jsonify can convert your objects to following types: # lists, dicts, numbers and strings from turbojson.jsonify import jsonify from turbojson.jsonify import jsonify_sqlobject from felicity.model import User, Group, Permission @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 @jsonify.when('isinstance(obj, Permission)') def jsonify_permission(obj): result = jsonify_sqlobject( obj ) result["groups"] = [g.group_name for g in obj.groups] return result