当前位置: 首页>>代码示例>>Python>>正文


Python Response.headers["Cache-Control"]方法代码示例

本文整理汇总了Python中pyramid.response.Response.headers["Cache-Control"]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers["Cache-Control"]方法的具体用法?Python Response.headers["Cache-Control"]怎么用?Python Response.headers["Cache-Control"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.response.Response的用法示例。


在下文中一共展示了Response.headers["Cache-Control"]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dump_entries_to_excel

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers["Cache-Control"] [as 别名]
def dump_entries_to_excel(entries, group_by, bigger_than):
    wbk = xlwt.Workbook()
    sheet = wbk.add_sheet("Hours")

    heading_xf = xlwt.easyxf("font: bold on; align: wrap on, vert centre, horiz center")
    headings = ("Client", "Project", "Ticket id", "Employee", "Description", "Date", "Time")
    headings_width = (x * 256 for x in (20, 30, 10, 40, 100, 12, 10))
    for colx, value in enumerate(headings):
        sheet.write(0, colx, value, heading_xf)
    for i, width in enumerate(headings_width):
        sheet.col(i).width = width

    sheet.set_panes_frozen(True)
    sheet.set_horz_split_pos(1)
    sheet.set_remove_splits(True)

    rows, asum = ExcelRow.from_ordered_data(entries, group_by, bigger_than)
    for j, row in enumerate(rows):
        row = row.pprint_row()
        for i, cell in enumerate(row):
            sheet.write(j + 1, i, *cell)

    file_path = "/tmp/tmp.xls"
    wbk.save(file_path)

    file = open(file_path, "rb")
    response = Response(content_type="application/vnd.ms-excel", app_iter=file)
    response.headers["Cache-Control"] = "no-cache"
    response.content_disposition = 'attachment; filename="report-%s.xls"' % datetime.datetime.now().strftime(
        "%d-%m-%Y--%H-%M-%S"
    )

    return file, response
开发者ID:kalek,项目名称:intranet,代码行数:35,代码来源:times.py

示例2: post

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers["Cache-Control"] [as 别名]
    def post(self):
        rows = (
            self.session.query("cid", "cname", "uid", "uemail", "date", "time")
            .from_statement(
                """
        SELECT c.id as cid, c.name as cname, u.id as uid, u.email as uemail, date_trunc('month', t.date) as date, SUM(t.time) as time
        FROM time_entry t, project p, client c, "user" u
        WHERE t.project_id = p.id AND
              p.client_id = c.id AND
              t.user_id = u.id AND
              t.deleted = false
        GROUP BY c.id, c.name, u.id, u.name, date_trunc('month', t.date)
        ORDER BY date_trunc('month', t.date)
        """
            )
            .all()
        )

        monthly = h.groupby(rows, lambda row: (row[2], row[-2]), lambda row: row[5])

        rows = [(row[1], row[3], row[5], row[4].strftime("%Y-%m-%d"), sum(monthly[row[2], row[-2]])) for row in rows]

        stream = self._to_excel(rows)

        response = Response(content_type="application/vnd.ms-excel", app_iter=stream)
        response.headers["Cache-Control"] = "no-cache"
        response.content_disposition = 'attachment; filename="report-%s.xls"' % datetime.datetime.now().strftime(
            "%d-%m-%Y--%H-%M-%S"
        )

        return response
开发者ID:kalek,项目名称:intranet,代码行数:33,代码来源:client.py

示例3: _imageView

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers["Cache-Control"] [as 别名]
def _imageView(request, default_resp=None):
    iid = request.matchdict["id"]

    if iid == "default" and default_resp:
        resp = default_resp
    else:
        session = request.DBSession
        image = session.query(Image).filter(Image.id == int(iid)).first()
        if not image:
            raise HTTPNotFound()
        resp = Response(content_type=image.mime_type, body=image.data)

    hash = sha1()
    hash.update(resp.body)
    etag = hash.hexdigest()
    if "If-None-Match" in request.headers and request.headers["If-None-Match"] == etag:
        raise HTTPNotModified()

    resp.headers["Cache-Control"] = "max-age=3600"
    resp.headers["ETag"] = etag

    return resp
开发者ID:nicfit,项目名称:mishmash,代码行数:24,代码来源:views.py


注:本文中的pyramid.response.Response.headers["Cache-Control"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。