本文整理汇总了Python中zope.schema.getFieldNames函数的典型用法代码示例。如果您正苦于以下问题:Python getFieldNames函数的具体用法?Python getFieldNames怎么用?Python getFieldNames使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getFieldNames函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: applyProperties
def applyProperties(self, userid, data):
portal = getToolByName(self.context, 'portal_url').getPortalObject()
mt = getToolByName(self.context, 'portal_membership')
member = mt.getMemberById(userid)
# cache adapters
adapters = {}
# Set any fields that are simply properties for the new user, rather
# than fields to help create the new user
register_fields = getFieldNames(IRegisterSchema) + \
getFieldNames(IAddUserSchema)
for k, value in data.items():
# skip fields not available in the schema
if k in ['login_name', 'user_id']:
continue
# skip fields that are handled exclusively on user registration and
# are not part of personal information form
if k in register_fields:
continue
# get schema adapter
schema = self.fields[k].field.interface
if schema in adapters:
adapter = adapters[schema]
else:
adapters[schema] = adapter = getAdapter(portal, schema)
adapter.context = member
adapter.schema = schema
# finally set value
setattr(adapter, k, value)
示例2: __init__
def __init__(self, **kwargs):
for k,v in kwargs.items():
if k=='value' and isinstance(v, str):
self.value = v.decode('utf=8')
continue
elif k in getFieldNames(IFilterSpecification):
setattr(self, k, v)
示例3: test_getFieldNamesAll
def test_getFieldNamesAll(self):
names = getFieldNames(ISchemaTestSubclass)
self.assertEqual(len(names),4)
self.assert_('title' in names)
self.assert_('description' in names)
self.assert_('spam' in names)
self.assert_('foo' in names)
示例4: populate_dexterity_type
def populate_dexterity_type(obj, data):
request = getRequest()
for schema in get_dexterity_schemas(context=obj):
for name in getFieldNames(schema):
field = schema[name]
autoform_widgets = schema.queryTaggedValue(WIDGETS_KEY, default={})
if name in autoform_widgets:
widgetclass = utils.resolveDottedName(autoform_widgets[name])
widget = widgetclass(field, request)
else:
widget = component.getMultiAdapter((field, request), IFieldWidget)
widget.context = obj
widget.ignoreRequest = True
widget.update()
value = widget.value
if not value or value in [NOT_CHANGED, NO_VALUE] or \
not IDataConverter(widget).toFieldValue(widget.value):
value = get_dummy_dexterity_value(obj, widget, data)
if value:
dm = component.getMultiAdapter((obj, field), IDataManager)
try:
dm.set(value)
except WrongType:
value = IDataConverter(widget).toFieldValue(value)
dm.set(value)
示例5: __call__
def __call__(self):
context = self.context
data = {}
data['document_id'] = context.id
data['url'] = context.absolute_url()
data['path'] = '/'.join(context.getPhysicalPath())
data['uid'] = context.UID()
if base_hasattr(context, 'title') and context.title:
data['Title'] = context.title
if base_hasattr(context, 'creators'):
creator = context.creators[0]
user = api.user.get(creator)
if user:
data['Author'] = user.getProperty('fullname', '') or creator
else:
data['Author'] = creator
if base_hasattr(context, 'description') and context.description:
description = context.description.replace('\n', ' ').strip()
if description:
data['Subject'] = data['Description'] = description
if base_hasattr(context, 'subject') and context.subject:
keywords = tuple([k.strip() for k in context.subject if k.strip()])
data['Keywords'] = keywords
fti = getUtility(IDexterityFTI, name=context.portal_type)
schema = fti.lookupSchema()
for name in getFieldNames(schema):
#@TODO: ignore files
data[name] = getattr(context, name, None)
return data
示例6: bindClass
def bindClass( klass, mapper=None ):
""" insert validated properties into a class based on its primary mapper, and model schemas
"""
# compile the klass mapper, this will add instrumented attributes to the class
# we could alternatively do.. mapper.compile() compiles all extant mappers
if mapper is None:
mapper = getattr( klass, 'mapper')
mapper.compile()
# find all the model schemas implemented by the class
for iface in providedByInstances( klass ):
if not IIModelInterface.providedBy( iface ):
continue
# for any field in the schema, see if we have an sa property
for field_name in schema.getFieldNames( iface ):
v = klass.__dict__.get( field_name )
# if so then wrap it in a field property
if not isinstance( v, attributes.InstrumentedAttribute):
continue
field = iface[ field_name ]
vproperty = ValidatedProperty( field, v, field_name )
setattr( klass, field_name, vproperty )
示例7: bindClass
def bindClass( klass, mapper=None ):
"""
attach validation to a sqlalchemy mapped class, based on its implemented schemas, via property
validators, taking care to wrap sqlalchemy properties.
"""
if mapper is None:
mapper = getattr( klass, 'mapper')
# compile the klass mapper, this will add instrumented attributes to the class
# we could alternatively do.. mapper.compile() compiles all extant mappers
mapper.compile()
# find all the model schemas implemented by the class
for iface in interface.implementedBy( klass ):
if not IIModelInterface.providedBy( iface ):
continue
# for any field in the schema, see if we have an sa property
for field_name in schema.getFieldNames( iface ):
v = klass.__dict__.get( field_name )
# if so then wrap it in a field property
if not isinstance( v, attributes.InstrumentedAttribute):
continue
field = iface[ field_name ]
vproperty = ValidatedProperty( field, v, field_name )
setattr( klass, field_name, vproperty )
示例8: __init__
def __init__(self, context):
self.context = context
attributes = {}
for name in getFieldNames(IEntity):
attributes[name] = getattr(context, name)
super(CachableItemForEntity, self).__init__(key='id',
attributes=attributes)
示例9: importRecords
def importRecords(self, node):
# May raise ImportError if interface can't be found or KeyError if
# attribute is missing.
interfaceName = node.attrib.get('interface', None)
if interfaceName is None:
raise KeyError(u"A <records /> node must have an 'interface' attribute.")
prefix = node.attrib.get('prefix', None) # None means use interface.__identifier__
if node.attrib.get('delete') is not None:
self.logger.warning(u"The 'delete' attribute of <record /> nodes "
u"is deprecated, it should be replaced with "
u"'remove'.")
remove = node.attrib.get('remove', node.attrib.get('delete', 'false')).lower() == 'true'
# May raise ImportError
interface = resolve(interfaceName)
omit = []
values = [] # Fields that should have their value set as they don't exist yet
for child in node:
if not isinstance(child.tag, str):
continue
elif child.tag.lower() == 'omit':
if child.text:
omit.append(unicode(child.text))
elif child.tag.lower() == 'value':
values.append(child)
if remove and values:
raise ValueError("A <records /> node with 'remove=\"true\"' must not contain "
"<value /> nodes.")
elif remove:
for f in getFieldNames(interface):
if f in omit:
continue
child = etree.Element('value', key=f, purge='True')
values.append(child)
# May raise TypeError
self.context.registerInterface(interface, omit=tuple(omit), prefix=prefix)
if not values and not remove:
# Skip out if there are no value records to handle
return
# The prefix we ended up needs to be found
if prefix is None:
prefix = interface.__identifier__
for value in values:
field = etree.Element("record", interface=interface.__identifier__, field=value.attrib["key"], prefix=prefix, remove=repr(remove).lower())
field.append(value)
self.importRecord(field)
示例10: schema_field_mapping
def schema_field_mapping(self):
"""Create a mapping of field_name to schema field object.
This can then be used for validation
"""
field_mapping = {}
for user_schema in self.user_schemata:
for name in schema.getFieldNames(user_schema):
field_mapping[name] = user_schema[name]
return field_mapping
示例11: testHaveFields
def testHaveFields(self):
""" Set and check IDonatableMarker schema """
for f in ('product_code', 'price', 'donation_text', 'made_payable_by'):
self.failUnless(f in getFieldNames(igetpaid.IDonationContent))
#sample for one field
donatable_fields = getFields(igetpaid.IDonationContent)
fieldDonationText = donatable_fields['donation_text']
self.assertRaises(RequiredMissing, fieldDonationText.validate, None)
示例12: __init__
def __init__(self, empInfo):
fieldNSmapping = {}
for fieldName in getFieldNames(IEmployee):
fieldNSmapping[self.NS[fieldName]] = fieldName
# predicate, object
for p, o in empInfo:
fieldName = fieldNSmapping.get(p, None)
if fieldName:
setattr(self, fieldName, o.encode('utf8'))
示例13: get_field
def get_field(context, field_name):
schema_interfaces = []
if hasattr(context, 'schema'):
schema_interfaces = [context.schema]
for interface in (schema_interfaces or providedBy(context)):
if field_name in getFieldNames(interface):
return interface[field_name]
return None
示例14: get_settings_data
def get_settings_data(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(IStatusMessageConfigForm, check=False)
data = {
field_name: getattr(settings, field_name)
for field_name in getFieldNames(IStatusMessageConfigForm)
}
return data
示例15: getContent
def getContent(self):
content = self.wizard.getContent()
data = removeAllProxies(content.getFieldData())
for schema in (removeAllProxies(content).__schema__, IField):
for name in getFieldNames(schema):
field = schema[name].bind(content)
data[name] = field.get(content)
return data