viewer_tools.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:fieldsight-kobocat 作者: awemulya 项目源码 文件源码
def create_attachments_zipfile(attachments, temporary_file=None):
    if not temporary_file:
        temporary_file = NamedTemporaryFile()

    storage = get_storage_class()()
    with zipfile.ZipFile(temporary_file, 'w', zipfile.ZIP_STORED, allowZip64=True) as zip_file:
        for attachment in attachments:
            if storage.exists(attachment.media_file.name):
                try:
                    with storage.open(attachment.media_file.name, 'rb') as source_file:
                        zip_file.writestr(attachment.media_file.name, source_file.read())
                except Exception, e:
                    report_exception("Error adding file \"{}\" to archive.".format(attachment.media_file.name), e)

    # Be kind; rewind.
    temporary_file.seek(0)

    return temporary_file
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号