Ejemplo n.º 1
0
    def __call__(self, request):
        if not IQuickChangenoteLayer.providedBy(request):
            return

        # Archetypes will call us three times, and that complicates things.
        # Either the change note is there or it isn't. If its there the first
        # time, its not about to disappear during the processing of the
        # request. Therefore annotate the return value on the request.
        cache_key = "validate_changenote_result"
        _marker = object()
        cache = IAnnotations(request)
        data = cache.get(cache_key, _marker)
        if data is not _marker:
            return data

        context = aq_inner(self.context)
        if IQuickChangenoteLayer.providedBy(request) and \
            changenoteRequired(context) and isVersionable(context) and \
            supportsAutoVersion(context):
                
            value = request.form.get(self.field_name,
                request.get(self.field_name, ''))
            if len(value) == 0:
                errors = {self.field_name: _(
                    u'A change note must be provided')}
                cache[cache_key] = errors
                return errors
        cache[cache_key] = None
        return None
Ejemplo n.º 2
0
 def required(self):
     """ returns whether a change note is required on each save. """
     return changenoteRequired(self.context)