Beispiel #1
0
def get_rule(id_or_alias, with_csrf_headers=False):
    rule = dbo.rules.getRule(id_or_alias)
    if not rule:
        return problem(status=404, title="Not Found", detail="Requested rule wasn't found", ext={"exception": "Requested rule does not exist"})

    headers = {"X-Data-Version": rule["data_version"]}
    if with_csrf_headers:
        headers.update(get_csrf_headers())
    return Response(response=json.dumps(rule), mimetype="application/json", headers=headers)
Beispiel #2
0
def get_release_single_locale(release, platform, locale, with_csrf_header=False):
    try:
        locale = dbo.releases.getLocale(release, platform, locale)
    except KeyError as e:
        return problem(404, "Not Found", json.dumps(e.args))
    data_version = dbo.releases.getReleases(name=release)[0]["data_version"]
    headers = {"X-Data-Version": data_version}
    if with_csrf_header:
        headers.update(get_csrf_headers())
    return Response(response=json.dumps(locale), mimetype="application/json", headers=headers)
Beispiel #3
0
def get_release_single_locale(release, platform, locale, with_csrf_header=False):
    try:
        locale = dbo.releases.getLocale(release, platform, locale)
    except KeyError as e:
        return problem(404, "Not Found", json.dumps(e.args))
    data_version = dbo.releases.getReleases(name=release)[0]["data_version"]
    headers = {"X-Data-Version": data_version}
    if with_csrf_header:
        headers.update(get_csrf_headers())
    return Response(response=json.dumps(locale), mimetype="application/json", headers=headers)
Beispiel #4
0
def get_release(release, with_csrf_header=False):
    release = _get_release(release)
    if not release:
        return problem(404, "Not Found", "Release name: %s not found" % release)
    headers = {"X-Data-Version": release["data_version"]}
    if with_csrf_header:
        headers.update(get_csrf_headers())
    if request.args.get("pretty"):
        indent = 4
        separators = (",", ": ")
    else:
        indent = None
        separators = None
    # separators set manually due to https://bugs.python.org/issue16333 affecting Python 2
    return Response(response=json.dumps(release["data"], indent=indent, separators=separators, sort_keys=True), mimetype="application/json", headers=headers)
Beispiel #5
0
def get_release(release, with_csrf_header=False):
    release = _get_release(release)
    if not release:
        return problem(404, "Not Found", "Release name: %s not found" % release)
    headers = {"X-Data-Version": release["data_version"]}
    if with_csrf_header:
        headers.update(get_csrf_headers())
    if request.args.get("pretty"):
        indent = 4
        separators = (",", ": ")
    else:
        indent = None
        separators = None
    # separators set manually due to https://bugs.python.org/issue16333 affecting Python 2
    return Response(response=json.dumps(release["data"], indent=indent, separators=separators, sort_keys=True), mimetype="application/json", headers=headers)
Beispiel #6
0
def get_release_single_locale(release, platform, locale, with_csrf_header=False):
    with dbo.begin() as trans:
        release_row = releases_service.get_release(release, trans)
        if release_row:
            locale_data = get_by_path(release_row["blob"], ("platforms", platform, "locales", locale))
            data_version = get_by_path(release_row["data_versions"], ("platforms", platform, "locales", locale))
        else:
            try:
                locale_data = dbo.releases.getLocale(release, platform, locale, transaction=trans)
            except KeyError as e:
                return problem(404, "Not Found", json.dumps(e.args))
            data_version = dbo.releases.getReleases(name=release, transaction=trans)[0]["data_version"]
        headers = {"X-Data-Version": data_version}
        if with_csrf_header:
            headers.update(get_csrf_headers())
        return Response(response=json.dumps(locale_data), mimetype="application/json", headers=headers)
Beispiel #7
0
def get_release(release, with_csrf_header=False):
    release = _get_release(release)
    if not release:
        return problem(404, "Not Found",
                       "Release name: %s not found" % release)
    headers = {'X-Data-Version': release['data_version']}
    if with_csrf_header:
        headers.update(get_csrf_headers())
    if request.args.get("pretty"):
        indent = 4
    else:
        indent = None
    return Response(response=json.dumps(release['data'],
                                        indent=indent,
                                        sort_keys=True),
                    mimetype='application/json',
                    headers=headers)