本文整理汇总了Python中Products.Archetypes.public.ObjectField.set方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectField.set方法的具体用法?Python ObjectField.set怎么用?Python ObjectField.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.Archetypes.public.ObjectField
的用法示例。
在下文中一共展示了ObjectField.set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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: get
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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})
示例3: set
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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)
示例4: set
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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: set
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
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)
示例11: set
# 需要导入模块: from Products.Archetypes.public import ObjectField [as 别名]
# 或者: from Products.Archetypes.public.ObjectField import set [as 别名]
def set(self, instance, value, **kwargs):
if value is None:
value = ()
if not isinstance(value, (ListType, TupleType)):
value = value,
elif not self.multiValued and len(value) > 1:
raise ValueError, \
"Multiple values given for single valued field %r" % self
# Convert objects to uids if necessary. Compute new references
# as well.
original_uids = []
if not kwargs.get('_initializing_'):
original_uids = self.getRaw(instance, aslist=True)
new_uids = []
uids = []
for v in value:
if type(v) in STRING_TYPES:
uid = v
else:
uid = v.UID()
# Update lists
if uid not in original_uids:
new_uids.append(uid)
if uid not in uids:
uids.append(uid)
ObjectField.set(self, instance, uids)
if not self.set_backreference or kwargs.get('backref'):
return
# Maintain back references
if kwargs.get('_initializing_'):
return
# Compute removed references
removed_uids = set(original_uids) - set(uids)
# Scan the target portal type for a field with a matching
# relationship
backref_field_map = {}
def get_backref_field(ob):
def filter_function(f):
return (f.type in ('reference', 'simplereference')) \
and (f.relationship == self.relationship)
portal_type = ob.portal_type
field = None
if backref_field_map.has_key(self.relationship):
field = backref_field_map[self.relationship]
else:
fields = ob.Schema().filterFields(filter_function)
if fields:
field = fields[0]
backref_field_map[self.relationship] = field
return field
rc = getToolByName(instance, REFERENCE_CATALOG)
# Set new back references
for uid in new_uids:
ob = rc.lookupObject(uid)
field = get_backref_field(ob)
if field is not None:
field.set(
ob,
list(field.getRaw(ob, aslist=True)+[instance.UID()]),
backref=True,
)
# Remove old back references
for uid in removed_uids:
ob = rc.lookupObject(uid)
field = get_backref_field(ob)
if field is not None:
field.set(
ob,
list(set(field.getRaw(ob, aslist=True)) -
set([instance.UID()])),
backref=True,
)