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


Python FileResponse.content_type方法代码示例

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


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

示例1: export_to_moe_view

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import content_type [as 别名]
def export_to_moe_view(request):
    import io, re
    from tempfile import NamedTemporaryFile
    import xlwt
    from pyramid_sqlalchemy import Session
    from ..models import NewStudentModel
    from pyramid.response import FileResponse

    with NamedTemporaryFile(delete=True) as f:
        
        wb = xlwt.Workbook()
        ws = wb.add_sheet('sheet1')
        ws.write(0, 0, '姓名')
        ws.write(0, 1, '身分證號')

        regex = re.compile(r'^[A-Z]\d{9}$') # 比對是否為身分證號
        
        counter = 1
        for each_new_student in Session.query(NewStudentModel).filter(NewStudentModel.status==1):
            if regex.match(each_new_student.id_number):
                ws.write(counter, 0, each_new_student.name)
                ws.write(counter, 1, each_new_student.id_number)
                counter += 1

        wb.save(f.name)

        f.flush()
        f.seek(0)

        response = FileResponse(f.name)
        response.content_type = 'application/octet-stream'
        response.content_disposition = 'attachment; filename="moe.xls"'
        
        return response
开发者ID:fosstp,项目名称:newcomer,代码行数:36,代码来源:export.py

示例2: __call__

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import content_type [as 别名]
    def __call__(self):
        params = self.request.params

        doc_data = {
            'year': params['year'],
            'regiontype': params['regiontype'],
            'regionid': params['region'],
            'selected_sections': params['sections'].split(' '),
            'format_dest': 'pdf'
        }

        root_section = SectionData(self.request.registry.settings['climas.report_section_path'])

        da = DocAssembler(
            doc_data,
            root_section,
            settings={
                'region_url_pattern': 'http://localhost:8080/regiondata/${region_type}/${region_id}',
                'region_data_path_pattern': self.request.registry.settings['climas.region_data_path'] + '/${region_type}/${region_id}',
                'section_debug': False
            },
        )

        with NamedTemporaryFile(prefix='CliMAS-Report-', suffix='.pdf', delete=True) as tf:
            tfpath = os.path.abspath(tf.name)

            doc = pypandoc.convert(da.result(), 'latex', format='markdown', extra_args=(
                '-o', tfpath,
                '--latex-engine=/usr/local/texlive/2014/bin/x86_64-linux/pdflatex',
                '--template=' + self.request.registry.settings['climas.doc_template_path'] + '/default.latex'
            ))

            response = FileResponse(tfpath)
            # response.content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            # response.content_disposition = "attachment; filename=CliMAS-Report.docx"
            response.content_type = "application/pdf"
            response.content_disposition = "attachment; filename=CliMAS-Report.pdf"
            return response
开发者ID:jcu-eresearch,项目名称:climas-ng,代码行数:40,代码来源:regionreportview.py

示例3: export_to_ecard_view

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import content_type [as 别名]
def export_to_ecard_view(request):
    import os, glob
    from pkg_resources import resource_filename
    from zipfile import ZipFile
    from tempfile import NamedTemporaryFile
    from pyramid.response import FileResponse

    with NamedTemporaryFile(delete=True) as f:

        os.chdir(resource_filename('tp_enroll', 'static/pictures'))

        with ZipFile(f.name, 'w') as z:
            for i in glob.glob('*'):
                z.write(i)

        f.flush()
        f.seek(0)

        response = FileResponse(f.name)
        response.content_type = 'application/octet-stream'
        response.content_disposition = 'attachment; filename="ecard.zip"'

        return response
开发者ID:fosstp,项目名称:newcomer,代码行数:25,代码来源:export.py


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