nti.schema.fieldproperty

Computed attributes based on schema fields.

class AcquisitionFieldProperty(field, name=None)[source]

Bases: zope.schema.fieldproperty.FieldProperty

A field property that supports acquisition. Returned objects will be __of__ the instance, and set objects will always be the unwrapped base.

class AdaptingFieldProperty(field, name=None)[source]

Bases: zope.schema.fieldproperty.FieldProperty

Primarily for legacy support and testing, adds adaptation to an interface when setting a field. This is most useful when the values are simple literals like strings.

class AdaptingFieldPropertyStoredThroughField(field, name=None)[source]

Bases: zope.schema.fieldproperty.FieldPropertyStoredThroughField

Primarily for legacy support and testing, adds adaptation to an interface when setting a field. This is most useful when the values are simple literals like strings.

class UnicodeConvertingFieldProperty(field, name=None)[source]

Bases: zope.schema.fieldproperty.FieldProperty

Accepts bytes input for the unicode property if it can be decoded as UTF-8. This is primarily to support legacy test cases and should be removed when all constants are unicode.

createDirectFieldProperties(__schema, omit=(), adapting=False)[source]

Like zope.schema.fieldproperty.createFieldProperties(), except only creates properties for fields directly contained within the given schema; inherited fields from parent interfaces are assummed to be implemented in a base class of the current class:

>>> from zope import interface
>>> from nti.schema.field import TextLine, Object
>>> class IA(interface.Interface):
...    a = TextLine(title=u"a")

>>> class IB(IA):
...    b = Object(interface.Interface)

>>> class A(object):
...    createFieldProperties(IA)

>>> class B(object):
...    createDirectFieldProperties(IB, adapting=True)

>>> 'a' in A.__dict__
True
>>> 'a' in B.__dict__
False
>>> 'b' in B.__dict__
True
Parameters:adapting – If set to True (not the default), fields that implement IObject will use an AdaptingFieldProperty.
field_name(field)[source]

Produce a clean version of a field’s name.

The zope.schema.fieldproperty.FieldPropertyStoredThroughField class mangles the field name, making it difficult to trace fields back to their intended attribute name. This undoes that mangling if possible.

The field in an interface has a normal name:

>>> from zope.schema.fieldproperty import FieldPropertyStoredThroughField
>>> from zope.schema import Field
>>> from zope import interface
>>> class IA(interface.Interface):
...    a = Field()
>>> IA['a'].__name__
'a'

The field as stored by a FieldProperty has a normal name:

>>> from zope.schema.fieldproperty import FieldProperty
>>> class A(object):
...    createFieldProperties(IA)
>>> A.a.__name__
'a'

But using a FieldPropertyStoredThroughField mangles the name (whether accessed through the FieldPropertyStoredThroughField or directly):

>>> from zope.schema.fieldproperty import FieldPropertyStoredThroughField
>>> class A2(object):
...    a = FieldPropertyStoredThroughField(IA['a'])
>>> A2.a.__name__
'__st_a_st'
>>> A2.a.field.__name__
'__st_a_st'

This function demangles the name (whether accessed through the FieldPropertyStoredThroughField or directly):

>>> from nti.schema.fieldproperty import field_name
>>> field_name(A2.a)
'a'
>>> field_name(A2.a.field)
'a'

Without damaging the names of regular fields or regular FieldProperty fields:

>>> field_name(IA['a'])
'a'
>>> field_name(A.a)
'a'

New in version 1.10.0.