Changeset 6290 for main


Ignore:
Timestamp:
6 Jun 2011, 22:47:53 (14 years ago)
Author:
uli
Message:

Set default for passport image via new
IContextAwareDefaultFactory. This bit is new in latest zope.schema and
enables definition of default values for interface fields, that should
be computed based on specific contexts. A side effect is, that the
default values for such fields are not set 'hardwired' during startup
but only, when a new object has to be created (after startup). So with
an IContextAwareDefaultFactory you can also use utilities and adapters
when defining a default value for some field.

The new zope.interface version we require enables the @provider
decorator we use when defining the new default passport image factory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r6285 r6290  
    2828
    2929from zope import schema
    30 from zope.interface import Interface, Attribute
     30from zope.interface import Interface, Attribute, provider
    3131from zope.component import getUtility, getUtilitiesFor
    3232from zope.pluggableauth.interfaces import IPrincipalInfo
     
    5656    )
    5757
     58@provider(schema.interfaces.IContextAwareDefaultFactory)
     59def default_passport_image(context):
     60    """A default value factory for ImageFile fields.
     61
     62    Returns some default image as WAeUPImageFile. We cannot set the
     63    default directly in ImageFile fields, as, if we want to set
     64    max_size or min_size as well, some utility lookups are needed
     65    which are not possible during startup.
     66
     67    Developers which use IContextAwareDefaultFactories like this one
     68    always should make sure that the delivered default meets all
     69    constraints of the field that makes use of this default value
     70    provider.
     71    """
     72    return DEFAULT_PASSPORT_IMAGE_MALE
     73
    5874class ApplicantContainerProviderSource(BasicSourceFactory):
    5975    """A source offering all available applicants container types.
     
    332348    passport = ImageFile(
    333349        title = u'Passport Photograph',
    334         default = DEFAULT_PASSPORT_IMAGE_MALE,
     350        #default = DEFAULT_PASSPORT_IMAGE_MALE,
     351        defaultFactory = default_passport_image,
    335352        required = True,
    336353        max_size = 20480,
Note: See TracChangeset for help on using the changeset viewer.