def __init__(self, *args, **kwargs): Schema.__init__(self, *args, **kwargs) def read_challenge(reader): return reader.source("recaptcha_challenge_field") def read_response(reader): return reader.source("recaptcha_response_field") self.add_member(String("challenge", read_request_value=read_challenge)) self.add_member(String("response", read_request_value=read_response)) self.add_validation(ReCaptcha.captcha_validation_rule) self.edit_control = "woost.extensions.recaptcha.ReCaptchaBox"
def _default_validation(self, context): for error in String._default_validation(self, context): yield error if context.value and not self.validate_iban_format(context.value): yield FormatError(context, "IBAN")
def _create_translation_schema(cls, members): bases = tuple(base.translation for base in cls.bases if base.translation) members["_generates_translation_schema"] = False if not bases: bases = (cls._translation_schema_base, ) members["full_name"] = cls.full_name + "Translation" members["translated_object"] = Reference(type=cls, required=True) members["language"] = String(required=True) cls.translation = cls._translation_schema_metaclass( cls.name + "Translation", bases, members) cls.translation.init_instance = _init_translation cls.translation.translation_source = cls # Make the translation class available at the module level, so that its # instances can be pickled setattr(sys.modules[cls.__module__], cls.translation.name, cls.translation) cls.translation.__module__ = cls.__module__
def _create_translations_member(cls): return TranslationsMember( name="translations", required=True, keys=String( required=True, translate_value=lambda value, language=None, **kwargs: "" if not value else translate_locale(value, language)), values=Reference(type=cls.translation), produce_default=TranslationMapping)
def _default_validation(self, context): """Validation rule for european bank account numbers.""" for error in String._default_validation(self, context): yield error if ( isinstance(context.value, str) and not self.checksum(context.value) ): yield BankAccountChecksumError(context)
def _default_validation(self, context): """Validation rule for credit card numbers. Checks the control digit. """ for error in String._default_validation(self, context): yield error if ( isinstance(context.value, str) and not self.checksum(context.value) ): if min is not None and len(context.value) < min: yield CreditCardChecksumError(context)
def __init__(self, *args, **kwargs): kwargs.setdefault("format", color_regexp) String.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): kwargs.setdefault("format", _reg_expr) String.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): kwargs.setdefault("format", r"^\d{8,19}$") String.__init__(self, *args, **kwargs)
def _default_validation(self, context): for error in String._default_validation(self, context): yield error value = context.value if isinstance(value, str): valid = True # Remove the international prefix value = value.strip() if value.startswith("00"): value = value[2:].lstrip() # Obtain the country code if value.startswith("+"): try: prefix, value = value.split(" ", 1) prefix.lstrip("+") prefix = int(prefix) except: valid = False prefix = None country = None else: country = self.get_country_from_prefix(prefix) else: prefix = None country = self.local_country if valid: # Possibly deny international numbers international_numbers = self.resolve_constraint( self.international_numbers, context) if prefix: # - all international numbers if international_numbers == "reject": if country is None or country != self.local_country: yield InternationalPhoneNumbersNotAllowedError( context) # - just a subset else: accepted_countries = self.resolve_constraint( self.accepted_countries, context) if (accepted_countries is not None and (country is None or country not in accepted_countries)): yield InvalidPhoneCountryError(context) # Ignore extensions value = self.split_extension(value)[0] # Validate the country specific format value = value.replace(" ", "") if country: format = self.get_country_format(country) else: format = None if format: valid = format.match(value) else: number = value if prefix is not None: number = str(prefix) + number valid = (len(number) <= 15 and all( (c in digits) for c in number)) if not valid: yield PhoneFormatError(context)