本文整理汇总了Python中transaction.Transaction.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.objects方法的具体用法?Python Transaction.objects怎么用?Python Transaction.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.objects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import objects [as 别名]
def update(self):
with prefix_collections(self.get_collection_name(), System, Node):
cloned_system = System.objects.get(name=self.system.name)
if cloned_system.last_transaction == self.system.last_transaction:
raise NothingToUpdateError("your clone is up-to-date, nothing to do")
if cloned_system.last_transaction is None:
transactions = Transaction.objects(system=self.system).order_by("_id")
else:
transactions = Transaction.objects(system=self.system, id__gt=cloned_system.last_transaction.id).order_by("_id")
operations = []
for transaction in transactions:
transaction.apply(cloned_system, self.get_collection_name())
operations += transaction.operations
for operation in operations:
pass
示例2: merge
# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import objects [as 别名]
def merge(self, message=""):
if len(self.operations) == 0:
raise NothingToMergeError("no operation to merge")
with prefix_collections(self.get_collection_name(), System, Node):
cloned_system = System.objects.get(name=self.system.name)
if self.system.last_transaction != cloned_system.last_transaction:
raise MustUpdateError("modification have been merge with the master, please update")
transaction = Transaction(self.system, self.operations, message)
transaction.save()
if self.system.last_transaction is None:
to_apply = Transaction.objects(system=self.system).order_by("_id")
else:
to_apply = Transaction.objects(system=self.system, id__gt=self.system.last_transaction.id).order_by("_id")
if len(to_apply) != 1:
return #FIXME
to_apply[0].apply(self.system)
to_apply[0].apply(cloned_system, self.get_collection_name())
self.operations = []
self.save()