def article_list(): page_size = request.args.get('pageSize', 10) page_number = request.args.get('pageNumber', 0) query = Article.query source = request.args.get("source") if source is not None: query = query.filter(Article.source_id == source) category = request.args.get("category") if category is not None: query = query.filter(Article.articleType_id == category) paginate = query.order_by(Article.create_time.desc()).paginate( int(page_number), per_page=int(page_size), error_out=True) items = paginate.items articles = [] for item in items: article = { 'id': item.id, 'title': item.title, 'create_time': str(item.create_time), 'num_of_view': item.num_of_view, 'source': item.source.name } articles.append(article) result = {'total': paginate.total, 'list': articles} return Response(pickler.encode(result), status=200, mimetype="application/json")
def encode(value, unpicklable=True, make_refs=True, keys=False, max_depth=None, backend=None, warn=False, max_iter=None, numeric_keys=False): """Return a JSON formatted representation of value, a Python object. :param unpicklable: If set to False then the output will not contain the information necessary to turn the JSON data back into Python objects, but a simpler JSON stream is produced. :param max_depth: If set to a non-negative integer then jsonpickle will not recurse deeper than 'max_depth' steps into the object. Anything deeper than 'max_depth' is represented using a Python repr() of the object. :param make_refs: If set to False jsonpickle's referencing support is disabled. Objects that are id()-identical won't be preserved across encode()/decode(), but the resulting JSON stream will be conceptually simpler. jsonpickle detects cyclical objects and will break the cycle by calling repr() instead of recursing when make_refs is set False. :param keys: If set to True then jsonpickle will encode non-string dictionary keys instead of coercing them into strings via `repr()`. :param warn: If set to True then jsonpickle will warn when it returns None for an object which it cannot pickle (e.g. file descriptors). :param max_iter: If set to a non-negative integer then jsonpickle will consume at most `max_iter` items when pickling iterators. >>> encode('my string') '"my string"' >>> encode(36) '36' >>> encode({'foo': True}) '{"foo": true}' >>> encode({'foo': True}, max_depth=0) '"{\\'foo\\': True}"' >>> encode({'foo': True}, max_depth=1) '{"foo": "True"}' """ if backend is None: backend = json return pickler.encode(value, backend=backend, unpicklable=unpicklable, make_refs=make_refs, keys=keys, max_depth=max_depth, warn=warn, max_iter=max_iter, numeric_keys=numeric_keys)
def encode(value, unpicklable=True, make_refs=True, keys=False, max_depth=None, backend=None): """ Return a JSON formatted representation of value, a Python object. The keyword argument 'unpicklable' defaults to True. If set to False, the output will not contain the information necessary to turn the JSON data back into Python objects. The keyword argument 'max_depth' defaults to None. If set to a non-negative integer then jsonpickle will not recurse deeper than 'max_depth' steps into the object. Anything deeper than 'max_depth' is represented using a Python repr() of the object. The keyword argument 'make_refs' defaults to True. If set to False jsonpickle's referencing support is disabled. Objects that are id()-identical won't be preserved across encode()/decode(), but the resulting JSON stream will be conceptually simpler. jsonpickle detects cyclical objects and will break the cycle by calling repr() instead of recursing when make_refs is set False. The keyword argument 'keys' defaults to False. If set to True then jsonpickle will encode non-string dictionary keys instead of coercing them into strings via `repr()`. >>> encode('my string') '"my string"' >>> encode(36) '36' >>> encode({'foo': True}) '{"foo": true}' >>> encode({'foo': True}, max_depth=0) '"{\\'foo\\': True}"' >>> encode({'foo': True}, max_depth=1) '{"foo": "True"}' """ if backend is None: backend = json return pickler.encode(value, backend=backend, unpicklable=unpicklable, make_refs=make_refs, keys=keys, max_depth=max_depth)
def encode(value, unpicklable=True, make_refs=True, keys=False, max_depth=None, backend=None): """ Return a JSON formatted representation of value, a Python object. The keyword argument 'unpicklable' defaults to True. If set to False, the output will not contain the information necessary to turn the JSON data back into Python objects. The keyword argument 'max_depth' defaults to None. If set to a non-negative integer then jsonpickle will not recurse deeper than 'max_depth' steps into the object. Anything deeper than 'max_depth' is represented using a Python repr() of the object. The keyword argument 'make_refs' defaults to True. If set to False jsonpickle's referencing support is disabled. Objects that are id()-identical won't be preserved across encode()/decode(), but the resulting JSON stream will be conceptually simpler. jsonpickle detects cyclical objects and will break the cycle by calling repr() instead of recursing when make_refs is set False. MSC: if make_refs is None then continues until max_depth is reached. The keyword argument 'keys' defaults to False. If set to True then jsonpickle will encode non-string dictionary keys instead of coercing them into strings via `repr()`. >>> encode('my string') '"my string"' >>> encode(36) '36' >>> encode({'foo': True}) '{"foo": true}' >>> encode({'foo': True}, max_depth=0) '"{\\'foo\\': True}"' >>> encode({'foo': True}, max_depth=1) '{"foo": "True"}' """ if backend is None: backend = json return pickler.encode(value, backend=backend, unpicklable=unpicklable, make_refs=make_refs, keys=keys, max_depth=max_depth)
def chrome_plugin_list(): page_size = request.args.get( 'pageSize', default=current_app.config['PLUGINS_PER_PAGE']) page_number = request.args.get('pageNumber', 0) paginate = ChromePlugin.query.order_by( ChromePlugin.create_time.desc()).paginate(int(page_number), per_page=int(page_size), error_out=True) items = paginate.items result = {'total': paginate.total, 'list': items} return Response(pickler.encode(result), status=200, mimetype="application/json")
def __eq__(self, other): return pickler.encode(self) == pickler.encode(other)
def chrome_plugin_detail(id): plugin = ChromePlugin.query.get_or_404(id) return Response(pickler.encode(plugin), status=200, mimetype="application/json")
def json_response(self, entity): payload = pickler.encode(entity) return Response(response=payload, status=200, mimetype="application/json")