Beispiel #1
0
def _default_from_schema(context, schema, fieldname):
    """helper to lookup default value of a field
    """
    if schema is None:
        return _marker
    field = schema.get(fieldname, None)
    if field is None:
        return _marker
    if IContextAwareDefaultFactory.providedBy(
            getattr(field, 'defaultFactory', None)):
        bound = field.bind(context)
        return deepcopy(bound.default)
    else:
        return deepcopy(field.default)
    return _marker
Beispiel #2
0
def _default_from_schema(context, schema, fieldname):
    """helper to lookup default value of a field
    """
    if schema is None:
        return _marker
    field = schema.get(fieldname, None)
    if field is None:
        return _marker
    df = getattr(field, 'defaultFactory', None)
    if df is not None:
        if IContextAwareDefaultFactory.providedBy(df):
            return deepcopy(field.defaultFactory(context))
        else:
            return deepcopy(field.defaultFactory())
    else:
        return deepcopy(field.default)
    return _marker
Beispiel #3
0
def get_default_from_schema(context, schema, fieldname, default=None):
    """helper to lookup default value of a field
    """
    if schema is None:
        return default
    field = schema.get(fieldname, None)
    if field is None:
        return default
    df = getattr(field, "defaultFactory", None)
    if df is not None:
        if IContextAwareDefaultFactory.providedBy(df):
            return deepcopy(field.defaultFactory(context))
        else:
            return deepcopy(field.defaultFactory())
    if field.default is not None:
        return deepcopy(field.default)
    if field.default != default:
        return field.default
    return default