當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。