예제 #1
0
def json_converter(value):
    if value is None:
        return value

    request = get_current_request()
    registry = task_vars.registry.get()
    settings = registry.for_interface(IImagingSettings)
    scales = {}
    url = get_url(request, request.path)
    # TODO: VIRUALHOSTMONSTER
    for size, dimension in settings["allowed_sizes"].items():
        width, _, height = dimension.partition(":")
        scales[size] = {
            "download": url + "/@@images/image/" + size,
            "height": height,
            "width": width,
        }

    return {
        "filename": value.filename,
        "content_type": to_str(value.content_type),
        "size": value.size,
        "extension": value.extension,
        "md5": value.md5,
        "download": f"{url}/@download/image",
        "scales": scales,
    }
예제 #2
0
def test_vhm_url(dummy_guillotina):
    request = make_mocked_request('GET', '/', {
        'X-VirtualHost-Monster': 'https://foobar.com/foo/bar'
    })

    assert get_url(
        request, '/c/d') == 'https://foobar.com/foo/bar/c/d'
예제 #3
0
def test_forwarded_proto_url(dummy_guillotina):
    request = make_mocked_request('GET', '/', {
        'X-Forwarded-Proto': 'https'
    })
    url = get_url(request, '/c/d')
    assert url.startswith('https://')
    assert url.endswith('/c/d')
예제 #4
0
    def __call__(self, relative=False, container_url=False):
        if container_url:
            # we want the url relative to container so remove the container
            path = [x for x in get_physical_path(self.context)]
            path.pop(1)
            path = '/'.join(path)
        else:
            path = '/'.join(get_physical_path(self.context))

        if container_url:
            return path
        elif relative:
            return '/' + self.request._db_id + path
        else:
            return get_url(self.request, self.request._db_id + path)
예제 #5
0
    def __call__(self, relative=False, container_url=False):
        if container_url:
            # we want the url relative to container so remove the container
            path = [x for x in get_physical_path(self.context)]
            path.pop(1)
            path = '/'.join(path)
        else:
            path = '/'.join(get_physical_path(self.context))

        if container_url:
            return path
        elif relative:
            return '/' + self.request._db_id + path
        else:
            return get_url(self.request, self.request._db_id + path)
예제 #6
0
async def render_docs_index(context, request):
    if app_settings["swagger"].get("index_html"):
        index_file = app_settings["swagger"]["index_html"]
    else:
        index_file = os.path.join(here, "index.html")
    with open(index_file) as fi:
        html = fi.read()

    swagger_settings = copy.deepcopy(app_settings["swagger"])
    url = get_url(request, "")
    swagger_settings["initial_swagger_url"] = url
    return html.format(
        swagger_settings=json.dumps(swagger_settings),
        static_url="{}/swagger_static/".format(url if url != "/" else ""),
        title=swagger_settings["base_configuration"]["info"]["title"],
    )
예제 #7
0
    def __call__(self, relative=False, container_url=False):
        if container_url:
            # we want the url relative to container so remove the container
            path = [x for x in get_physical_path(self.context)]
            path.pop(1)
            path = "/".join(path)
        else:
            path = "/".join(get_physical_path(self.context))

        if container_url:
            return path
        elif relative:
            db = task_vars.db.get()
            return "/" + db.id + path
        else:
            db = task_vars.db.get()
            return get_url(self.request, db.id + path)
예제 #8
0
def test_url(dummy_guillotina):
    request = make_mocked_request("GET", "/a/b", query_string=b"include=title")

    assert get_url(request, "/c/d") == "http://localhost/c/d"
예제 #9
0
def test_vh_path_url(dummy_guillotina):
    request = make_mocked_request("GET", "/",
                                  {"X-VirtualHost-Path": "/foo/bar"})

    assert get_url(request, "/c/d").endswith("/foo/bar/c/d")
예제 #10
0
def test_forwarded_proto_url(dummy_guillotina):
    request = make_mocked_request("GET", "/", {"X-Forwarded-Proto": "https"})
    url = get_url(request, "/c/d")
    assert url.startswith("https://")
    assert url.endswith("/c/d")
예제 #11
0
def test_vhm_url(dummy_guillotina):
    request = make_mocked_request(
        "GET", "/", {"X-VirtualHost-Monster": "https://foobar.com/foo/bar"})

    assert get_url(request, "/c/d") == "https://foobar.com/foo/bar/c/d"
예제 #12
0
def test_vhm_url(dummy_guillotina):
    request = make_mocked_request(
        'GET', '/', {'X-VirtualHost-Monster': 'https://foobar.com/foo/bar'})

    assert get_url(request, '/c/d') == 'https://foobar.com/foo/bar/c/d'
예제 #13
0
def test_forwarded_proto_url(dummy_guillotina):
    request = make_mocked_request('GET', '/', {'X-Forwarded-Proto': 'https'})
    url = get_url(request, '/c/d')
    assert url.startswith('https://')
    assert url.endswith('/c/d')