def __call__(self, value, instance, *args, **kwargs): kw={ 'here':instance, 'object':instance, 'instance':instance, 'value':value, 'chars':self.chars, 'args':args, 'kwargs':kwargs, } # get text if not self.strict: text = value else: ttool = getToolByName(instance, 'portal_transforms') text = ttool.convertToData('text/plain', value) # \xc2\xa0 seems used widely by TinyMCE... stripped = re.sub(r'(\s|\xc2\xa0)', '', text) if len(stripped)>=self.chars: return True kw['current'] = len(stripped) if self.errormsg and type(self.errormsg) == Message: #hack to support including values in i18n message, too. hopefully this works out #potentially it could unintentionally overwrite already present values #self.errormsg.mapping = kw if self.errormsg.mapping: self.errormsg.mapping.update(**kw) return recursiveTranslate(self.errormsg, **kwargs) elif self.errormsg: # support strings as errormsg for backward compatibility return self.errormsg % kw else: msg = _('min_chars_error_msg', default=u'Required min $chars chars, provided ${current}', mapping={'chars': self.chars, 'current': len(stripped)}) return recursiveTranslate(msg, **kwargs)
# -*- coding: utf-8 -*- from Products.validation.validators.RegexValidator import RegexValidator from collective.itvalidators import validatorsMessageFactory as _ baseValidators = [ RegexValidator('isCAP', r'^\d{5}$', title='CAP', description='', errmsg=_(u'is not a valid CAP.')), RegexValidator('isItalianNIN', r'^[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]\d\d[a-eA-EhHlmLMpPr-tR-T]\d\d[a-zA-Z]\d\d\d[a-zA-Z]$', title='Codice fiscale', description='', errmsg=_(u'is not a valid National Insurance Number.')), ]
def __call__(self, value, instance, *args, **kwargs): kw={ 'here': instance, 'object': instance, 'instance': instance, 'value': value, 'observed': self.observed, 'warnValue': self.warnValue, 'wantedValue': self.wantedValue, 'kwargs': kwargs, } form = kwargs['REQUEST'].form # *** Checking warnValue *** if type(self.warnValue)!=bool: # Warn value is a specific value if form.get(self.observed)!=self.warnValue: return True kw['warnValue'] = '"%s"' % self.warnValue else: # boolean values if self.warnValue: if not form.get(self.observed): return True kw['warnValue'] = _(u'not empty') else: if form.get(self.observed): return True kw['warnValue'] = _(u'empy') # *** Checking wantedValue *** if type(self.wantedValue)!=bool: if value==self.wantedValue: return True kw['wantedValue'] = '"%s"' % self.wantedValue elif self.wantedValue: if value and self.eval_DataGridTrueValue(value): return True kw['wantedValue'] = _(u"a value") else: if not value and not self.eval_DataGridTrueValue(value): return True kw['wantedValue'] = _(u"no value") # We are here only when validation fails kw['observed'] = instance.getField(self.observed).widget.label if self.errormsg and type(self.errormsg) == Message: #hack to support including values in i18n message, too. hopefully this works out #potentially it could unintentionally overwrite already present values #self.errormsg.mapping = kw if self.errormsg.mapping: self.errormsg.mapping.update(**kw) return recursiveTranslate(self.errormsg, **kwargs) elif self.errormsg: # support strings as errormsg for backward compatibility return self.errormsg % kw else: msg = _('dependency_check_error_msg', default=u'"$observed" field value is $warnValue. This requires that this field contains $wantedValue.', mapping={'observed': kw['observed'], 'warnValue': kw['warnValue'], 'wantedValue': kw['wantedValue']}) return recursiveTranslate(msg, **kwargs)