本文整理汇总了Python中temba.flows.models.Flow.get_versions_before方法的典型用法代码示例。如果您正苦于以下问题:Python Flow.get_versions_before方法的具体用法?Python Flow.get_versions_before怎么用?Python Flow.get_versions_before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类temba.flows.models.Flow
的用法示例。
在下文中一共展示了Flow.get_versions_before方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: migrate_flows
# 需要导入模块: from temba.flows.models import Flow [as 别名]
# 或者: from temba.flows.models.Flow import get_versions_before [as 别名]
def migrate_flows(min_version=None): # pragma: no cover
to_version = min_version or get_current_export_version()
# get all flows below the min version
old_versions = Flow.get_versions_before(to_version)
flows_to_migrate = Flow.objects.filter(is_active=True, version_number__in=old_versions)
flow_ids = list(flows_to_migrate.values_list("id", flat=True))
total = len(flow_ids)
if not total:
print("All flows up to date")
return True
print("Found %d flows to migrate to %s..." % (len(flow_ids), to_version))
num_updated = 0
errored = []
for id_batch in chunk_list(flow_ids, 1000):
for flow in Flow.objects.filter(id__in=id_batch):
try:
flow.ensure_current_version(min_version=to_version)
num_updated += 1
except Exception:
print("Unable to migrate flow '%s' (#%d)" % (flow.name, flow.id))
errored.append(flow)
print(" > Flows migrated: %d of %d (%d errored)" % (num_updated, total, len(errored)))
if errored:
print(" > Errored flows: %s" % (", ".join([str(e.id) for e in errored])))
return len(errored) == 0