当前位置: 首页>>代码示例>>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']方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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', 'uname', 'date', 'time').from_statement("""
        SELECT c.id as cid, c.name as cname, u.id as uid, u.name as uname, 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:adamgr,项目名称:intranet,代码行数:35,代码来源:client.py

示例2: 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:rutral,项目名称:intranet,代码行数:37,代码来源:times.py

示例3: state_get_event_source

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['Cache-Control'] [as 别名]
def state_get_event_source(context, request):
    event_stream = request.headers.get("accept") == "text/event-stream"

    response = Response()
    if event_stream:
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Cache-Control'] = 'no-cache'

    return state_get(context, request, eventSourceStateObserverSet, response, 'text/event-stream', stream = event_stream)
开发者ID:Faqer,项目名称:jarvis,代码行数:11,代码来源:views.py

示例4: portrait_image

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['Cache-Control'] [as 别名]
def portrait_image(model, request):
    """XXX: needs polishing. Return configured default portrait if not set
    on user.
    """
    response = Response()
    cfg = ugm_general(model)
    response.body = model.attrs[cfg.attrs['users_portrait_attr']]
    response.headers['Content-Type'] = 'image/jpeg'
    response.headers['Cache-Control'] = 'max-age=0'
    return response
开发者ID:,项目名称:,代码行数:12,代码来源:

示例5: 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):
    def _format_row(a_row):
        row = list(a_row)
        row[0] = (row[0].name,)                                    #client
        row[1] = (row[1].name,)                                    #project
        row[2] = (row[2],)                                         #ticketid
        row[3] = (row[3].email,)                                   #email
        row[4] = (unicode(row[5]),)                                #desc
        date_xf = xlwt.easyxf(num_format_str='DD/MM/YYYY')
        row[5] = (row[6].strftime('%d/%m/%Y'), date_xf)            #date
        row[6] = (round(row[7], 2),)                               #time
        return row[:7]

    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)

    for j, row in enumerate(entries):
        row = _format_row(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:pytlakp,项目名称:intranet-1,代码行数:48,代码来源:times.py


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