本文整理匯總了Python中appy.fields.Field.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Python Field.getValue方法的具體用法?Python Field.getValue怎麽用?Python Field.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類appy.fields.Field
的用法示例。
在下文中一共展示了Field.getValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getValue
# 需要導入模塊: from appy.fields import Field [as 別名]
# 或者: from appy.fields.Field import getValue [as 別名]
def getValue(self, obj, type='objects', noListIfSingleObj=False,
startNumber=None, someObjects=False):
'''Returns the objects linked to p_obj through this Ref field.
- If p_type is "objects", it returns the Appy wrappers;
- If p_type is "zobjects", it returns the Zope objects;
- If p_type is "uids", it returns UIDs of objects (= strings).
* If p_startNumber is None, it returns all referred objects.
* If p_startNumber is a number, it returns self.maxPerPage objects,
starting at p_startNumber.
If p_noListIfSingleObj is True, it returns the single reference as
an object and not as a list.
If p_someObjects is True, it returns an instance of SomeObjects
instead of returning a list of references.'''
uids = getattr(obj.aq_base, self.name, [])
if not uids:
# Maybe is there a default value?
defValue = Field.getValue(self, obj)
if defValue:
# I must prefix call to function "type" with "__builtins__"
# because this name was overridden by a method parameter.
if __builtins__['type'](defValue) in sutils.sequenceTypes:
uids = [o.o.UID() for o in defValue]
else:
uids = [defValue.o.UID()]
# Prepare the result: an instance of SomeObjects, that will be unwrapped
# if not required.
res = gutils.SomeObjects()
res.totalNumber = res.batchSize = len(uids)
batchNeeded = startNumber != None
if batchNeeded:
res.batchSize = self.maxPerPage
if startNumber != None:
res.startNumber = startNumber
# Get the objects given their uids
i = res.startNumber
while i < (res.startNumber + res.batchSize):
if i >= res.totalNumber: break
# Retrieve every reference in the correct format according to p_type
if type == 'uids':
ref = uids[i]
else:
ref = obj.getTool().getObject(uids[i])
if type == 'objects':
ref = ref.appy()
res.objects.append(ref)
i += 1
# Manage parameter p_noListIfSingleObj
if res.objects and noListIfSingleObj:
if self.multiplicity[1] == 1:
res.objects = res.objects[0]
if someObjects: return res
return res.objects
示例2: getValue
# 需要導入模塊: from appy.fields import Field [as 別名]
# 或者: from appy.fields.Field import getValue [as 別名]
def getValue(self, obj):
# Cheat if this field represents p_obj's state
if self.name == 'state': return obj.State()
value = Field.getValue(self, obj)
if not value:
if self.isMultiValued(): return emptyTuple
else: return value
if isinstance(value, basestring) and self.isMultiValued():
value = [value]
elif isinstance(value, tuple):
value = list(value)
return value
示例3: getValue
# 需要導入模塊: from appy.fields import Field [as 別名]
# 或者: from appy.fields.Field import getValue [as 別名]
def getValue(self, obj):
value = Field.getValue(self, obj)
if value: value = sutils.FileWrapper(value)
return value
示例4: getValue
# 需要導入模塊: from appy.fields import Field [as 別名]
# 或者: from appy.fields.Field import getValue [as 別名]
def getValue(self, obj):
'''Never returns "None". Returns always "True" or "False", even if
"None" is stored in the DB.'''
value = Field.getValue(self, obj)
if value == None: return False
return value