本文整理匯總了Python中rpc.RPCProxy.read方法的典型用法代碼示例。如果您正苦於以下問題:Python RPCProxy.read方法的具體用法?Python RPCProxy.read怎麽用?Python RPCProxy.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rpc.RPCProxy
的用法示例。
在下文中一共展示了RPCProxy.read方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ModelRecordGroup
# 需要導入模塊: from rpc import RPCProxy [as 別名]
# 或者: from rpc.RPCProxy import read [as 別名]
class ModelRecordGroup(signal_event.signal_event):
def __init__(self, resource, fields, ids=[], parent=None, context={}, is_wizard=False, screen=None):
super(ModelRecordGroup, self).__init__()
self._readonly = False
self.parent = parent
self._context = context
self._context.update(rpc.session.context)
self.resource = resource
self.rpc = RPCProxy(resource)
self.fields = fields
self.mfields = {}
self.mfields_load(fields.keys(), self)
self.screen = screen
self.models = ModelList(self)
self.current_idx = None
self.load(ids)
self.models_removed = []
self.on_write = ''
self.is_wizard = is_wizard
self.list_parent = False
self.list_group = False
def destroy(self):
for field in self.mfields.values():
field.destroy()
if self.list_group:
self.list_group.destroy()
del self.mfields
del self.fields
del self.list_group
del self.models
def index(self, model):
return self.models.index(model)
def mfields_load(self, fkeys, models):
for fname in fkeys:
fvalue = models.fields[fname]
modelfield = field.ModelField(fvalue['type'])
fvalue['name'] = fname
models.mfields[fname] = modelfield(models, fvalue)
def model_move(self, model, position=0):
self.models.move(model, position)
def set_sequence(self, get_id, rec_id, field='sequence'):
seq_ids = []
index = 0
for model in self.models:
seq_ids += [model[field].get(model)]
index = index +1
set_list = list(set(seq_ids))
if len(seq_ids) != len(set_list):
set_list.sort()
repeat = set_list[-1]
mod_list = seq_ids[len(set_list):]
for e in range(len(mod_list)):
repeat = repeat + 1
mod_list[e]= repeat
final_list = set_list + mod_list
index = 0
for model in self.models:
model[field].set(model, final_list[index], modified=True)
if model.id:
model.save()
index = index +1
else:
seq_id = []
if get_id < rec_id:
for x in range(get_id, rec_id):
seq_id += [self.models[x][field].get(self.models[x])]
sort_seq = [seq_id[-1]] + seq_id[:-1]
index = 0
for x in range(get_id, rec_id):
self.models[x][field].set(self.models[x], sort_seq[index], modified=True)
if self.models[x].id:
self.models[x].save()
index = index +1
else:
for x in range(rec_id,get_id+1):
seq_id += [self.models[x][field].get(self.models[x])]
sort_seq = seq_id[1:] + [seq_id[0]]
index = 0
for x in range(rec_id,get_id+1):
self.models[x][field].set(self.models[x], sort_seq[index], modified=True)
if self.models[x].id:
self.models[x].save()
index = index +1
def save(self):
for model in self.models:
saved = model.save()
self.writen(saved)
#.........這裏部分代碼省略.........
示例2: ModelRecord
# 需要導入模塊: from rpc import RPCProxy [as 別名]
# 或者: from rpc.RPCProxy import read [as 別名]
class ModelRecord(signal_event.signal_event):
def __init__(self, resource, id, group=None, parent=None, new=False ):
super(ModelRecord, self).__init__()
self.resource = str(resource)
self.rpc = RPCProxy(self.resource)
self.id = id
self._loaded = False
self.parent = parent
self.mgroup = group
self.value = {}
self.state_attrs = {}
self.modified = False
self.modified_fields = {}
self._concurrency_check_data = False
for key,val in self.mgroup.mfields.items():
self.value[key] = val.create(self)
if (new and val.attrs['type']=='one2many') and (val.attrs.get('mode','tree,form').startswith('form')):
mod = self.value[key].model_new()
self.value[key].model_add(mod)
def __getitem__(self, name):
return self.mgroup.mfields.get(name, False)
def __repr__(self):
return '<ModelRecord %[email protected]%s>' % (self.id, self.resource)
def is_modified(self):
return self.modified
def is_wizard(self):
return self.mgroup.is_wizard
def fields_get(self):
return self.mgroup.mfields
def _check_load(self):
if not self._loaded:
self.reload()
return True
return False
def update_context_with_concurrency_check_data(self, context):
if self.id and self.is_modified():
context.setdefault(CONCURRENCY_CHECK_FIELD, {})["%s,%d" % (self.resource, self.id)] = self._concurrency_check_data
for name, field in self.mgroup.mfields.items():
if isinstance(field, O2MField):
if field.name not in self.value.keys():
continue
v = self.value[field.name]
from itertools import chain
for m in chain(v.models, v.models_removed):
m.update_context_with_concurrency_check_data(context)
def get(self, get_readonly=True, includeid=False, check_load=True, get_modifiedonly=False):
if check_load:
self._check_load()
value = []
for name, field in self.mgroup.mfields.items():
if (get_readonly or not field.get_state_attrs(self).get('readonly', False)) \
and (not get_modifiedonly or (field.name in self.modified_fields or isinstance(field, O2MField))):
value.append((name, field.get(self, readonly=get_readonly,
modified=get_modifiedonly)))
value = dict(value)
if includeid:
value['id'] = self.id
return value
def cancel(self):
self._loaded = False
self.reload()
def failed_validation(self):
invalid_fields = self.rpc.get_invalid_fields()
for item in invalid_fields:
if item in self.mgroup.mfields:
self.mgroup.mfields[item].get_state_attrs(self)['valid'] = False
def save(self, reload=True):
self._check_load()
if not self.id:
value = self.get(get_readonly=False)
self.id = self.rpc.create(value, self.context_get())
if not self.id:
self.failed_validation()
else:
if not self.is_modified():
return self.id
value = self.get(get_readonly=False, get_modifiedonly=True)
context = self.context_get().copy()
self.update_context_with_concurrency_check_data(context)
if not self.rpc.write([self.id], value, context):
self.failed_validation()
return False
self._loaded = False
if reload:
self.reload()
else:
# just reload the CONCURRENCY_CHECK_FIELD
#.........這裏部分代碼省略.........