Ignore:
Timestamp:
13 May 2011, 18:02:38 (14 years ago)
Author:
uli
Message:

Add more reasonable field-property setter -- even usable as a class
decorator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py

    r5988 r6071  
    1010from zope.component.interfaces import IFactory
    1111from zope.interface import implementedBy
     12from zope.schema import getFieldNames
     13from zope.schema.fieldproperty import FieldProperty
    1214
    1315def removeFileOrDirectory(filepath):
     
    351353    html, warnings = ReST2HTML_w_warnings(source_string)
    352354    return html
     355
     356def attrs_to_fields(cls):
     357    """Turn the attributes of a class into FieldProperty instances.
     358    """
     359    iface = list(implementedBy(cls))[0]
     360    for field_name in getFieldNames(iface):
     361        setattr(cls, field_name, FieldProperty(iface[field_name]))
     362    return cls
Note: See TracChangeset for help on using the changeset viewer.