本文整理汇总了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
示例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
示例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