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


Python SavedBasicExport.set_payload方法代码示例

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


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

示例1: test_file_save_and_load

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import set_payload [as 别名]
 def test_file_save_and_load(self):
     payload = 'something small and simple'
     for name in ['normal', u'हिंदी', None]:
         saved = SavedBasicExport(configuration=_mk_config(name))
         saved.save()
         saved.set_payload(payload)
         self.assertEqual(payload, saved.get_payload())
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:9,代码来源:test_saved.py

示例2: rebuild_export

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import set_payload [as 别名]
def rebuild_export(config, schema, output_dir, last_access_cutoff=None, filter=None):
    if output_dir == "couch":
        saved = get_saved_export_and_delete_copies(config.index)
        if last_access_cutoff and saved and saved.last_accessed and \
                saved.last_accessed < last_access_cutoff:
            # ignore exports that haven't been accessed since last_access_cutoff
            return

    try:
        files = schema.get_export_files(format=config.format, filter=filter)
    except SchemaMismatchException:
        # fire off a delayed force update to prevent this from happening again
        rebuild_schemas.delay(config.index)
        raise ExportRebuildError(u'Schema mismatch for {}. Rebuilding tables...'.format(config.filename))

    with files:
        payload = files.file.payload
        if output_dir == "couch":
            if not saved:
                saved = SavedBasicExport(configuration=config)
            else:
                saved.configuration = config

            if saved.last_accessed is None:
                saved.last_accessed = datetime.utcnow()
            saved.last_updated = datetime.utcnow()
            saved.save()
            saved.set_payload(payload)
        else:
            with open(os.path.join(output_dir, config.filename), "wb") as f:
                f.write(payload)
开发者ID:dimagi,项目名称:couchexport,代码行数:33,代码来源:groupexports.py

示例3: export_for_group

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import set_payload [as 别名]
def export_for_group(export_id_or_group, output_dir):
    if isinstance(export_id_or_group, basestring):
        try:
            config = GroupExportConfiguration.get(export_id_or_group)
        except ResourceNotFound:
            raise Exception("Couldn't find an export with id %s" % export_id_or_group)
    else:
        config = export_id_or_group

    for config, schema in config.all_exports:
        try:
            tmp, _ = schema.get_export_files(format=config.format)
        except SchemaMismatchException, e:
            # fire off a delayed force update to prevent this from happening again
            rebuild_schemas.delay(config.index)
            continue

        payload = Temp(tmp).payload
        if output_dir == "couch":
            saved = SavedBasicExport.view("couchexport/saved_exports", 
                                          key=json.dumps(config.index),
                                          include_docs=True,
                                          reduce=False).one()
            if not saved: 
                saved = SavedBasicExport(configuration=config)
            else:
                saved.configuration = config
            saved.last_updated = datetime.utcnow()
            saved.save()
            saved.set_payload(payload)

        else:
            with open(os.path.join(output_dir, config.filename), "wb") as f:
                f.write(payload)
开发者ID:kennknowles,项目名称:couchexport,代码行数:36,代码来源:groupexports.py

示例4: testFileSaveAndLoad

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import set_payload [as 别名]
    def testFileSaveAndLoad(self):
        def _mk_config(name):
            return ExportConfiguration(index="dummy_index", name=name, format="xlsx")

        payload = "something small and simple"
        for name in ["normal", u"हिंदी", None]:
            saved = SavedBasicExport(configuration=_mk_config(name))
            saved.save()
            saved.set_payload(payload)
            self.assertEqual(payload, saved.get_payload())
开发者ID:kennknowles,项目名称:couchexport,代码行数:12,代码来源:test_saved.py

示例5: test_save_basic_export_to_blobdb

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import set_payload [as 别名]
 def test_save_basic_export_to_blobdb(self):
     index = ['single']
     saved_export = SavedBasicExport(configuration=_mk_config(index=index))
     saved_export.save()
     saved_export.set_payload("content")
     name = saved_export.get_attachment_name()
     self.assertTrue(saved_export.has_file())
     self.assertIn(name, saved_export.external_blobs)
     self.assertEqual(saved_export.size, 7)
     with saved_export.get_payload(stream=True) as fh:
         self.assertEqual(fh.read(), "content")
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:13,代码来源:test_saved.py

示例6: _save_export_payload

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import set_payload [as 别名]
def _save_export_payload(files, saved_export, config, is_safe=False):
    payload = files.file.payload
    if not saved_export:
        saved_export = SavedBasicExport(configuration=config)
    else:
        saved_export.configuration = config
    saved_export.is_safe = is_safe

    if saved_export.last_accessed is None:
        saved_export.last_accessed = datetime.utcnow()
    saved_export.last_updated = datetime.utcnow()
    try:
        saved_export.save()
    except ResourceConflict:
        # task was executed concurrently, so let first to finish win and abort the rest
        pass
    else:
        saved_export.set_payload(payload)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:20,代码来源:groupexports.py


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