示例#1
0
    def __new__(cls, *args, **kwargs):
        # README(shep): This line produces the following DeprecationWarning
        #     DeprecationWarning: object.__new__() takes no parameters
        # obj = super(JsonRenderer, cls).__new__(cls, *args, **kwargs)
        # README(shep): This seems to work and does not throw the warning
        obj = super(JsonRenderer, cls).__new__(cls)
        obj.__dict__['api'] = db_api.api_from_models()
        classname = obj.__class__.__name__.lower()

        obj.__dict__['logger'] = logging.getLogger(
            '%s.%s' % (__name__, classname))
        return obj
示例#2
0
    def jsonify(self, api=None):
        if api is None:
            api = db_api.api_from_models()

        classname = self.__class__.__name__.lower()
        field_list = api._model_get_columns(classname)

        newself = self
        if api != self.api:
            newself = copy.copy(self)
            newself.api = api

        return dict([[c, getattr(newself, c)] for c in field_list])