本文整理汇总了Python中object.Object.lastupdate_counter方法的典型用法代码示例。如果您正苦于以下问题:Python Object.lastupdate_counter方法的具体用法?Python Object.lastupdate_counter怎么用?Python Object.lastupdate_counter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object.Object
的用法示例。
在下文中一共展示了Object.lastupdate_counter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_object
# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import lastupdate_counter [as 别名]
def add_object(self, pk, name, value):
''' Create object on server (do not use this function to add
object from a client sync '''
obj = Object(pk=pk, name=name, value=value)
self.counter += 1
obj.lastupdate_counter = self.counter
self.objects.append(obj)
示例2: sync_from_client
# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import lastupdate_counter [as 别名]
def sync_from_client(self, objects):
result = {}
for sob in objects:
exists = False
conflict = False
for o in self.objects:
if o.guid == sob.guid:
exists = True
o.value = sob.value
o.deleted = sob.deleted
self.counter += 1
o.lastupdate_counter = self.counter
elif o.pk == sob.pk:
# pk conflict: do nothing because this should not occur on server
# client will always sync from server to client first and handle
# any pk conflicts before syncing from client to server
exists = True
conflict = True
result['statuscode'] = NOK
if not exists:
no = Object(pk=sob.pk, name=sob.name, value=sob.value, guid=sob.guid)
no.deleted = sob.deleted
self.counter += 1
no.lastupdate_counter = self.counter
self.objects.append(no)
if 'statuscode' not in result:
result['statuscode'] = OK
result['servercounter'] = self.counter
return result
示例3: add_object
# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import lastupdate_counter [as 别名]
def add_object(self, pk, name, value):
''' Create object on client (do not use this function to add object from
a server sync) '''
# Check for duplicate primary key
if any(o.pk == pk for o in self.objects):
print "Error creating new object on client {}: primary key {} already in use".format(self.name, pk)
no = Object(pk, name, value)
self.counter += 1
no.lastupdate_counter = self.counter
self.objects.append(no)
示例4: sync_from_server
# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import lastupdate_counter [as 别名]
def sync_from_server(self):
result = self.server.sync_to_client(self.lastsync_servercounter)
for sob in result['objects']:
exists = False
for o in self.objects:
if o.guid == sob.guid or o.pk == sob.pk:
exists = True
# Handle pk conflict
if o.pk == sob.pk:
o.guid = sob.guid
# Check for conflict (object updated locally since last sync to server)
if o.lastupdate_counter > self.lastsync_counter:
# Decide how to handle conflict
if self.conflict_handling == SERVERPRIORITY:
o.value = sob.value
o.deleted = sob.deleted
elif self.conflict_handling == CLIENTPRIORITY:
''' no change to local object '''
elif self.conflict_handling == TIMESTAMPPRIORITY:
if sob.timestampupdated > o.timestampupdated:
o.value = sob.value
o.deleted = sob.deleted
o.timestampupdated = datetime.now()
else:
# No conflict, update object locally
o.value = sob.value
o.deleted = sob.deleted
if not exists:
no = Object(sob.pk, sob.name, sob.value, sob.guid)
no.deleted = sob.deleted
no.lastupdate_counter = self.counter
self.objects.append(no)
if result['statuscode'] == OK:
self.lastsync_servercounter = result['servercounter']