本文整理匯總了Python中zope.schema.interfaces.IChoice.providedBy方法的典型用法代碼示例。如果您正苦於以下問題:Python IChoice.providedBy方法的具體用法?Python IChoice.providedBy怎麽用?Python IChoice.providedBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zope.schema.interfaces.IChoice
的用法示例。
在下文中一共展示了IChoice.providedBy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getFields
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def getFields(self):
fields = []
for schema_name, schema in self._getSchemas():
for field_name, field in getFieldsInOrder(schema):
if IChoice.providedBy(field):
fields.append(StringField(
schema_name + '.' + field.__name__,
required=field.required,
schemata='categorization',
widget=atapi.SelectionWidget(
label = field.title,
description = field.description,
),
vocabulary = atapi.DisplayList([(t.value, t.title or t.token) for t in field.vocabulary]),
))
elif ISet.providedBy(field) and IChoice.providedBy(field.value_type): # XXX should be set
fields.append(LinesField(
schema_name + '.' + field.__name__,
required=field.required,
schemata='categorization',
widget=atapi.MultiSelectionWidget(
label = field.title,
description = field.description,
),
vocabulary = atapi.DisplayList([(t.value, t.title or t.token) for t in field.value_type.vocabulary]),
))
return fields
示例2: handle_field_added
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def handle_field_added(ph_schema, event):
field = event.field
index_name = ph_schema.__name__ + "." + field.__name__
catalog = getToolByName(getSite(), "portal_catalog")
if index_name not in catalog.Indexes:
if ISet.providedBy(field) and IChoice.providedBy(field.value_type):
catalog.addIndex(index_name, "KeywordIndex")
if IChoice.providedBy(field):
catalog.addIndex(index_name, "FieldIndex")
示例3: update
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def update(self):
super(AddForm, self).update()
# set humanized default value for choice fields with no defaults
for widget in self.widgets:
field = widget.context
if IChoice.providedBy(field):
if IGenenerateVocabularyDefault.providedBy(widget):
field.default = widget.getDefaultVocabularyValue()
if IChoice.providedBy(field) and field.default is None:
widget._messageNoValue = _(
"bungeni_widget_no_value", "choose ${title} ...", mapping={"title": field.title}
)
示例4: map_with_vocab
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def map_with_vocab(self, behavior, fieldname, value):
"""Look in the schema for a vocab and return the mapped value
"""
if type(value) == int:
return str(value)
portal = self.layer['portal']
fields = getFieldsInOrder(behavior)
for name, field in fields:
if name == fieldname:
# We have different types of fields, so we have to check,
# that we become the vocabulary
value_type = field
if IList.providedBy(field) or ITuple.providedBy(field):
value_type = field.value_type
if IChoice.providedBy(value_type):
if value_type.vocabulary:
vocab = value_type.vocabulary(portal)
else:
vocab = getVocabularyRegistry().get(
portal, value_type.vocabularyName)
value = vocab.getTerm(value).title
return value
示例5: js
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def js(self):
value_type = self.field.value_type
vocab = None
if IChoice.providedBy(self.field.value_type):
if value_type.vocabulary:
vocab = value_type.vocabulary
if value_type.vocabularyName:
vocab = getVocabularyRegistry().get(
self.context, self.field.value_type.vocabularyName)
values = [(term.token, term.value) for term in vocab]
old_values = self._get_old_values(vocab)
else:
values = enumerate(self.context.portal_catalog.uniqueValuesFor('Subject'))
old_values = enumerate(self.context.Subject())
tags = ""
old_tags = ""
index = 0
for index, value in values:
tags += "{id: '%s', name: '%s'}" % (value.replace("'", "\\'"), value.replace("'", "\\'"))
if values.index((index, value)) < len(values) - 1:
tags += ", "
old_index = 0 # XXX: this is not used
#prepopulate
for index, value in old_values:
old_tags += u"{id: '%s', name: '%s'}" % (value.replace("'", "\\'"), value.replace("'", "\\'"))
if old_values.index((index, value)) < len(old_values) - 1:
old_tags += ", "
result = self.js_template % dict(id=self.id,
klass=self.klass,
newtags=unicode(tags, errors='ignore'),
oldtags=old_tags)
return result
示例6: _validate
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def _validate(self, value):
# XXX HACK: Can't call the super, since it'll check to
# XXX see if we provide DictRow.
# We're only a dict, so we can't.
# super(DictRow, self)._validate(value)
# Validate the dict against the schema
# Pass 1 - ensure fields are present
if value is NO_VALUE:
return
# Treat readonly fields
for field_name in getFields(self.schema).keys():
field = self.schema[field_name]
if field.readonly:
value[field_name] = field.default
errors = []
for field_name in getFields(self.schema).keys():
if field_name not in value:
errors.append(AttributeNotFoundError(field_name, self.schema))
if errors:
raise WrongContainedType(errors, self.__name__)
# Pass 2 - Ensure fields are valid
for field_name, field_type in getFields(self.schema).items():
if IChoice.providedBy(field_type):
# Choice must be bound before validation otherwise
# IContextSourceBinder is not iterable in validation
bound = field_type.bind(value)
bound.validate(value[field_name])
else:
field_type.validate(value[field_name])
示例7: import_node_for_field
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def import_node_for_field(self, field, child):
value = None
# If we have a collection, we need to look at the value_type.
# We look for <element>value</element> child nodes and get the
# value from there
if ICollection.providedBy(field):
value_type = field.value_type
value = []
for element in child.childNodes:
if element.nodeName != 'element':
continue
value.append(self.import_node_for_field(value_type, element))
elif IObject.providedBy(field):
value = {}
for element in child.childNodes:
if element.nodeName != 'property':
continue
property_key = self.extract_text(element.attributes['name'])
property_value = self.import_node_for_field(field.schema[property_key], element)
value[property_key] = property_value
elif IChoice.providedBy(field):
# Choice fields can be optional, so treat an empty contents as None
value = self.extract_text(child)
if not value:
value = None
else:
value = self.from_unicode(field, value)
else:
# Otherwise, just get the value of the <property /> node
value = self.extract_text(child)
if not (field.getName() == 'root' and value in ['', '/']):
value = self.from_unicode(field, value)
value = self.field_typecast(field, value)
return value
示例8: _base_args
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def _base_args(self):
"""Method which will calculate _base class arguments.
Returns (as python dictionary):
- `pattern`: pattern name
- `pattern_options`: pattern options
- `name`: field name
- `value`: field value
:returns: Arguments which will be passed to _base
:rtype: dict
"""
args = super(RelatedItemsWidget, self)._base_args()
args['name'] = self.name
args['value'] = self.value
args.setdefault('pattern_options', {})
if IChoice.providedBy(self.field):
args['pattern_options']['maximumSelectionSize'] = 1
field_name = self.field and self.field.__name__ or None
args['pattern_options'] = dict_merge(
get_relateditems_options(self.context, args['value'],
self.separator, self.vocabulary,
self.vocabulary_view, field_name),
args['pattern_options'])
return args
示例9: verify_registry_key
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def verify_registry_key(self):
registry = queryUtility(IRegistry)
if registry is None:
logger.warning('Plone registry is not available, doing nothing.')
return False
record = registry.records.get(self.name)
if record is None:
logger.warning(
'The registry key for the utility registry `%s` is not '
'registered.', self.name)
return False
if not (IList.providedBy(record.field) and
IChoice.providedBy(record.field.value_type) and
record.field.value_type.vocabularyName == self.available_vocab
):
logger.warning(
'The registry key for the utility registry `%s` is registered '
'incorrectly.', self.name)
return False
return True
示例10: __init__
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def __init__(self, value_type=None, unique=False, **kw):
self.search_view = kw.pop('search_view', None)
self.placeholder = kw.pop('placeholder', '')
if IChoice.providedBy(value_type):
self.add_terms = False
super(Select2MultiField, self).__init__(value_type, unique, **kw)
示例11: additional
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def additional(self):
info = super(ListJsonSchemaProvider, self).additional()
if IChoice.providedBy(self.field.value_type):
info['uniqueItems'] = True
else:
info['uniqueItems'] = False
return info
示例12: update
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def update(self):
super(AddForm, self).update()
# set default values for required choice fields
for widget in self.widgets:
field = widget.context
if IChoice.providedBy(field) and field.required and field.default is None:
for term in field.vocabulary:
field.default = term.value
示例13: _base_args
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def _base_args(self):
"""Method which will calculate _base class arguments.
Returns (as python dictionary):
- `pattern`: pattern name
- `pattern_options`: pattern options
- `name`: field name
- `value`: field value
:returns: Arguments which will be passed to _base
:rtype: dict
"""
args = super(AjaxSelectWidget, self)._base_args()
args["name"] = self.name
args["value"] = self.value
args.setdefault("pattern_options", {})
field_name = self.field and self.field.__name__ or None
context = self.context
# We need special handling for AddForms
if IAddForm.providedBy(getattr(self, "form")):
context = self.form
vocabulary_name = self.vocabulary
field = None
if IChoice.providedBy(self.field):
args["pattern_options"]["maximumSelectionSize"] = 1
field = self.field
elif ICollection.providedBy(self.field):
field = self.field.value_type
if not vocabulary_name and field is not None:
vocabulary_name = field.vocabularyName
args["pattern_options"] = dict_merge(
get_ajaxselect_options(
context, args["value"], self.separator, vocabulary_name, self.vocabulary_view, field_name
),
args["pattern_options"],
)
if field and getattr(field, "vocabulary", None):
form_url = self.request.getURL()
source_url = "%s/++widget++%s/@@getSource" % (form_url, self.name)
args["pattern_options"]["vocabularyUrl"] = source_url
# ISequence represents an orderable collection
if ISequence.providedBy(self.field) or self.orderable:
args["pattern_options"]["orderable"] = True
return args
示例14: get_widgets
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def get_widgets(self):
widgets = form.setUpWidgets(self.form_fields, '', self.context,
self.request,ignore_request=True
)
for widget in widgets:
if IChoice.providedBy(widget.context):
if widget.context.default is None:
widget._messageNoValue = _(u"event_form_field_default",
default=u"choose ${event_field_title}",
mapping={'event_field_title': widget.context.title}
)
yield widget
示例15: update
# 需要導入模塊: from zope.schema.interfaces import IChoice [as 別名]
# 或者: from zope.schema.interfaces.IChoice import providedBy [as 別名]
def update(self):
super(TaskModifiedTemplate, self).update()
task = self.context
ev = self.context0
request = self.request
data = {}
attributes = dict([(attr.interface, list(attr.attributes)) for attr in ev.descriptions])
for iface, fields in attributes.items():
ob = iface(task)
for fieldId in fields:
field = iface[fieldId].bind(ob)
value = field.get(ob)
if IChoice.providedBy(field):
try:
value = field.vocabulary.getTerm(value).title
except LookupError:
pass
if ICollection.providedBy(field) and IChoice.providedBy(field.value_type):
voc = field.value_type.vocabulary
value = u", ".join([voc.getTerm(v).title for v in value])
if IDate.providedBy(field):
value = getFormatter(request, "date", "full").format(value)
if IDatetime.providedBy(field):
value = getFormatter(request, "dateTime", "medium").format(value)
data[field.title] = value
data = data.items()
data.sort()
self.data = data