예제 #1
0
async def themecss(context, request):

    registry = await get_registry()
    settings = registry.for_interface(ICustomTheme)
    resp = Response(status=200)
    resp.content_type = "text/css"
    disposition = 'filename="style.css"'
    resp.headers["CONTENT-DISPOSITION"] = disposition
    resp.content_length = len(settings["css"])
    await resp.prepare(request)
    await resp.write(settings["css"].encode(), eof=True)
    return resp
예제 #2
0
파일: files.py 프로젝트: sunbit/guillotina
    async def serve_file(self, fi):
        filepath = str(fi.file_path.absolute())
        filename = fi.file_path.name
        with open(filepath, "rb") as f:
            resp = Response(status=200)
            resp.content_type, _ = mimetypes.guess_type(filename)

            disposition = 'filename="{}"'.format(filename)
            if "text" not in (resp.content_type or ""):
                disposition = "attachment; " + disposition

            resp.headers["CONTENT-DISPOSITION"] = disposition

            data = f.read()
            resp.content_length = len(data)
            await resp.prepare(self.request)
            await resp.write(data, eof=True)
            return resp