briefcase_client.py 文件源码

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

项目:FormShare 作者: qlands 项目源码 文件源码
def _upload_instance(self, xml_file, instance_dir_path, files):
        xml_doc = clean_and_parse_xml(xml_file.read())
        xml = StringIO()
        de_node = xml_doc.documentElement
        for node in de_node.firstChild.childNodes:
            xml.write(node.toxml())
        new_xml_file = ContentFile(xml.getvalue())
        new_xml_file.content_type = 'text/xml'
        xml.close()
        attachments = []

        for attach in de_node.getElementsByTagName('mediaFile'):
            filename_node = attach.getElementsByTagName('filename')
            filename = filename_node[0].childNodes[0].nodeValue
            if filename in files:
                file_obj = default_storage.open(
                    os.path.join(instance_dir_path, filename))
                mimetype, encoding = mimetypes.guess_type(file_obj.name)
                media_obj = django_file(file_obj, 'media_files[]', mimetype)
                attachments.append(media_obj)

        create_instance(self.user.username, new_xml_file, attachments)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号