当前位置: 首页>>代码示例>>Python>>正文


Python schema.getFieldNames函数代码示例

本文整理汇总了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)
开发者ID:khanstark,项目名称:plone.app.users,代码行数:33,代码来源:register.py

示例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)
开发者ID:gu-eresearch,项目名称:plone.app.folderui,代码行数:7,代码来源:defaults.py

示例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)
开发者ID:grodniewicz,项目名称:oship,代码行数:7,代码来源:test_schema.py

示例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)
开发者ID:johnnykitoo,项目名称:collective.loremipsum,代码行数:28,代码来源:utils.py

示例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
开发者ID:cedricmessiant,项目名称:collective.documentfusion,代码行数:35,代码来源:dexterity.py

示例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 )
开发者ID:kapilt,项目名称:zope-alchemist,代码行数:26,代码来源:bind.py

示例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 )
开发者ID:BGCX261,项目名称:zope-alchemist-svn-to-git,代码行数:29,代码来源:property.py

示例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)
开发者ID:davisd50,项目名称:sparc.cache,代码行数:7,代码来源:entity.py

示例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)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:58,代码来源:handler.py

示例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
开发者ID:smcmahon,项目名称:ploneintranet,代码行数:9,代码来源:user_import.py

示例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)
开发者ID:Martronic-SA,项目名称:Products.PloneGetPaid,代码行数:9,代码来源:test_donation.py

示例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'))
开发者ID:eea,项目名称:Products.EEAContentTypes,代码行数:9,代码来源:organisation.py

示例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
开发者ID:infrae,项目名称:mobi.rendering,代码行数:9,代码来源:expressions.py

示例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
开发者ID:4teamwork,项目名称:ftw.globalstatusmessage,代码行数:10,代码来源:controlpanel.py

示例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
开发者ID:Zojax,项目名称:zojax.persistent.fields,代码行数:10,代码来源:field.py


注:本文中的zope.schema.getFieldNames函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。