本文整理汇总了Python中Products.Archetypes.public.ObjectField类的典型用法代码示例。如果您正苦于以下问题:Python ObjectField类的具体用法?Python ObjectField怎么用?Python ObjectField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
def set(self, instance, value, **kwargs):
"""
"""
if value is None:
ObjectField.set(self, instance, value, **kwargs)
return
if self.multiValued and not isinstance(value, (list, tuple)):
value = value,
elif not self.multiValued and isinstance(value, (list, tuple)):
if len(value) > 1:
raise ValueError(
"Multiple values given for single valued field %r" % self)
value = value[0]
intid_tool = getUtility(IIntIds)
#convert objects to intids if necessary
if self.multiValued:
result = []
for v in value:
if isinstance(v, (basestring, int)):
result.append(RelationValue(int(v)))
else:
result.append(RelationValue(intid_tool.getId(v)))
else:
if isinstance(value, (basestring, int)):
result = RelationValue(int(value))
else:
result = RelationValue(intid_tool.getId(value))
ObjectField.set(self, instance, result, **kwargs)
示例2: set
def set(self, instance, value, **kwargs):
if not isinstance(value, PythonScript):
s = self._seperator
body = "%s\n%s%s\n%s%s" % (self.header, s, value, s, self.footer)
script = PythonScript(self.getName())
script.ZPythonScript_edit('**options', body)
value = script
ObjectField.set(self, instance, value, **kwargs)
示例3: get
def get(self, instance, **kwargs):
value = ObjectField.get(self, instance, **kwargs)
if type(value) in types.StringTypes:
# migration from TextField
zpt = ZopePageTemplate(self.getName())
ObjectField.set(self, instance, zpt, **kwargs)
value = ObjectField.get(self, instance, **kwargs)
return value.pt_render(extra_context={'options': kwargs})
示例4: set
def set(self, instance, value, **kwargs):
""" test"""
#log("Set: value = %s, specific=%s" % (value, kwargs.get('specific','wer')))
if value == 'specific':
if kwargs.has_key('specific'):
value = kwargs['specific']
else:
value = 'latest'
ObjectField.set(self, instance, value, **kwargs)
示例5: _render_output_html
def _render_output_html(self):
""" Return rendered newsletter
with header+body+footer (raw html).
"""
enl = self.getNewsletter()
# get out_template from ENL object and render it in context of issue
out_template_pt_field = enl.getField('out_template_pt')
ObjectField.set(out_template_pt_field, self, ZopePageTemplate(
out_template_pt_field.getName(),
enl.getRawOut_template_pt()))
output_html = safe_portal_encoding(self.out_template_pt.pt_render())
output_html = compactify(output_html, filter_tags=False)
return output_html
示例6: get
def get(self, instance, **kwargs):
value = ObjectField.get(self, instance, **kwargs)
if type(value) in types.StringTypes:
# migration from TextField
zpt = ZopePageTemplate(self.getName())
ObjectField.set(self, instance, zpt, **kwargs)
value = ObjectField.get(self, instance, **kwargs)
if config.CATCH_RENDER_ERRORS:
try:
return value.pt_render(extra_context={'options': kwargs})
except Exception, e:
return _(u"zpt_field_render_error",
default=u'<div class="error">An error occured while rendering this field</div>')
示例7: _render_output_html
def _render_output_html(self):
""" Return rendered newsletter
with header+body+footer (raw html).
"""
enl = self.getNewsletter()
props = getToolByName(self, "portal_properties").site_properties
charset = props.getProperty("default_charset")
# get out_template from ENL object and render it in context of issue
out_template_pt_field = enl.getField('out_template_pt')
ObjectField.set(out_template_pt_field, self, ZopePageTemplate(
out_template_pt_field.getName(),
enl.getRawOut_template_pt()))
output_html = safe_portal_encoding(self.out_template_pt.pt_render())
return output_html
示例8: set
def set(self, instance, value, **kwargs):
"""
Check if value is an actual FixedPoint value. If not, attempt to
convert it to one; Raise an error if value is a float. Assign
all properties passed as kwargs to object.
field.set( FixedPoint(10))
field.set( FixedPointInstance)
"""
assert type(value) != type(0.00)
if not value is None and not isinstance(value, FixedPoint):
value = FixedPoint(value)
ObjectField.set(self, instance, value, **kwargs)
示例9: set
def set(self, instance, value, **kwargs):
"""
Tests if all elements in value are numbers and save them as minutes.
@see ObjectField.set
"""
result = []
for item in value:
if self.required or item:
m = re.match('^(\d\d)[.:]?(\d\d)$', item.strip())
result.append((int(m.group(1)) * 60 ) + int(m.group(2)))
else:
result = []
break
ObjectField.set(self, instance, result, **kwargs)
示例10: getRaw
def getRaw(self, instance, **kwargs):
body = ObjectField.get(self, instance, **kwargs).body()
p1 = body.find(self._seperator)
if p1 == -1:
# no seperator: we return the whole body
return body
else:
p1 = p1 + len(self._seperator)
p2 = body.find(self._seperator, p1)
return body[p1:p2]
示例11: validate_required
def validate_required(self, instance, value, errors):
"""
Tests if all elements in value are not None. If one is None a
error message will be returned.
@see ObjectField.validate_required
"""
result = True
for item in value:
if not item:
result = False
break
return ObjectField.validate_required(self, instance, result, errors)
示例12: set
def set(self, instance, value, **kwargs):
"""
Check if value is an actual Money value. If not, attempt
to convert it to one; otherwise, set to None. Assign all
properties passed as kwargs to object.
field.set( Money(10, 'ZAR') )
field.set( money_instance )
"""
if value is not None:
if type(value) in STRING_TYPES:
cur, value = parseString(decode(value, instance))
if self.use_global_currency:
cur = self.getGlobalCurrency()
else:
if cur is None:
cur = self.getDefaultCurrency(instance)
value = Money(value, cur)
assert isinstance(value, Money), (
'value must be Money instance. value == %s' % value)
ObjectField.set(self, instance, value, **kwargs)
示例13: getRaw
def getRaw(self, instance, aslist=False, **kwargs):
"""Return the list of UIDs referenced under this fields
relationship
"""
objects = []
uids = ObjectField.get(self, instance, **kwargs)
if uids is None:
uids = []
if not self.multiValued and not aslist:
if uids:
uids = uids[0]
else:
uids = None
return uids
示例14: get
def get(self, instance, aslist=False, **kwargs):
"""
"""
res = ObjectField.get(self, instance, **kwargs)
if res is None:
return res
if self.multiValued:
resolved = []
for rel in res:
resolved.append(rel.to_object)
else:
resolved = res.to_object
if aslist:
resolved = [resolved]
return resolved
示例15: get
def get(self, instance, aslist=False, **kwargs):
objects = []
rc = getToolByName(instance, REFERENCE_CATALOG)
uids = ObjectField.get(self, instance, **kwargs)
if uids is None:
uids = []
for uid in uids:
if uid:
objects.append(rc.lookupObject(uid))
if objects:
if not self.multiValued:
return objects[0]
else:
return objects
return []