예제 #1
0
def get_json_by_id(id):
    """Get JSON for an object (or all similar objects)."""
    response.content_type = 'application/json; charset=UTF8'

    all = request.GET.get('all', False)
    enemy = request.GET.get('enemy', False)
    r = models.get_by_id(id, all=all, enemy=enemy)

    if r:
        if hasattr(r, 'jsonify'):
            # This is a single object
            return r.jsonify()
        # We have a list of objects
        return minify_json([i.dict() for i in r])

    response.status = 404
    return minify_json({'success':False, 'error':'No results found'})
예제 #2
0
def get_json_by_id(id):
    """
    Get JSON for an object (or all similar objects).
    """
    response.content_type = "application/json; charset=UTF8"

    all = request.GET.get("all", False)
    enemy = request.GET.get("enemy", False)
    r = models.get_by_id(id, all=all, enemy=enemy)

    if r:
        if hasattr(r, "jsonify"):
            # This is a single object
            return r.jsonify()
        # We have a list of objects
        return minify_json([i.dict() for i in r])

    response.status = 404
    return minify_json({"success": False, "error": "No results found"})
예제 #3
0
def main(iden=None):
    """
    Render a page for a single object.
    Corresponds with url('json_id').
    """
    try:
        iden = int(iden)
    except ValueError:
        o = models.get_by_name(iden)
    else:
        o = models.get_by_id(iden)

    if o is not None:
        context = {"o": o}
        try:
            return context
        except TemplateSyntaxError as e:
            logging.error("{}:{}".format(e.filename, e.lineno))
            logging.error("exc_info=True", exc_info=True)
    abort(404, 'Object "{}" not found'.format(iden))
예제 #4
0
def get_cron(request):
    id_cron = request.match_info.get('id_cron')
    cron = models.get_by_id(models.Cron, id_cron)
    json_cron = str(cron)
    return web.Response(status=200,body=json_cron.encode('utf-8'))
예제 #5
0
def get_app(request):
    id_app = request.match_info.get('id_app')
    app = models.get_by_id(models.App, id_app)
    json_app = str(app)
    return web.Response(status=200,body=json_app.encode('utf-8'))
예제 #6
0
def get_policy(request):
    id_policy = request.match_info.get('id_policy')
    policy = models.get_by_id(models.Policy, id_policy)
    json_policy = str(policy)
    return web.Response(status=200,body=json_policy.encode('utf-8'))
예제 #7
0
def get_cron(request):
    id_cron = request.match_info.get('id_cron')
    cron = models.get_by_id(models.Cron, id_cron)
    json_cron = str(cron)
    return web.Response(status=200, body=json_cron.encode('utf-8'))
예제 #8
0
def get_app(request):
    id_app = request.match_info.get('id_app')
    app = models.get_by_id(models.App, id_app)
    json_app = str(app)
    return web.Response(status=200, body=json_app.encode('utf-8'))
예제 #9
0
def get_policy(request):
    id_policy = request.match_info.get('id_policy')
    policy = models.get_by_id(models.Policy, id_policy)
    json_policy = str(policy)
    return web.Response(status=200, body=json_policy.encode('utf-8'))