class AccountRegister(MappingSchema): name = SchemaNode(String(), validator=Regex(REGISTER_NAME_RE)) fullname = SchemaNode(String()) email = SchemaNode(String(), validator=Email()) public_email = SchemaNode(Boolean(), missing=False) password1 = SchemaNode(String(), validator=Length(min=4)) password2 = SchemaNode(String(), validator=Length(min=4)) terms = SchemaNode(Boolean())
class EditGameDepSchema(MappingSchema): name = SchemaNode(String(), widget=TextInputWidget(size=40), validator=Regex( "^[a-zA-Z_0-9]*$", "Only characters a-z A-Z 0-9 _ " + "are accepted.")) display_name = SchemaNode(String(), widget=TextInputWidget(size=40)) description = SchemaNode(String(), widget=TextAreaWidget(cols=80, rows=20)) tags = SchemaNode(String(), widget=TextInputWidget(size=40), missing='')
class MySchema(MappingSchema): url = SchemaNode( String(), title='', css_class='wiki-input', # Broken mask_placeholder='http://en.wikipedia.org/wiki/Wikipedia', # Broken validator=Regex('(https|http):\/\/.*.wikipedia.org\/', msg='Invalid wikipedia url was entered'), missing_msg='Invalid wikipedia url was entered')
class AbsolutePath(SchemaNode): """Absolute path made with Identifier Strings. Example value: /bluaABC/_123/3 """ schema_type = StringType relative_regex = '/[a-zA-Z0-9\_\-\.\/]+' validator = Regex('^' + relative_regex + '$')
class Identifier(colander.SchemaNode): """Alpha/numeric/_ String, encoding utf-8 A global unique identifier. Example value: bluABC_123 """ schema_type = colander.String validator = Regex(u'^[a-zA-Z0-9_]+$') title = u"dd"
class RelativeFilePathUnix(colander.SchemaNode): """Relative path string, utf-8 encoding Example values: - folder1/file - ./folder1/file - file """ schema_type = colander.String validator = Regex(u'^[a-zA-Z0-9\_\-\.][a-zA-Z0-9_\-/\.]+$')
class Identifier(SchemaNode): """Like :class:`Name`, but doesn't check uniqueness.. Example value: blu.ABC_12-3 """ schema_type = StringType default = '' missing = drop relative_regex = '[a-zA-Z0-9\_\-\.]+' validator = All(Regex('^' + relative_regex + '$'), Length(min=1, max=100))
def deferred_validate_activation_path(node: SchemaNode, kw: dict) -> All: """Validate activation path and add user.""" context = kw['context'] request = kw['request'] registry = kw['registry'] return All( Regex('^/activate/'), create_validate_activation_path( context, request, registry, ), )
def definition(cls, **kwargs): schema = SchemaNode(Mapping(unknown="preserve")) if kwargs.get('named', True): schema.add( SchemaNode(String(), name='name', validator=Regex(r'^[a-zA-Z][a-zA-Z0-9_\-]*$'))) schema.add(SchemaNode(String(), name='label', missing=u'')) schema.add(SchemaNode(String(), name='hint', missing=cls.hint)) schema.add(SchemaNode(Boolean(), name='required', missing=cls.required)) schema.add( SchemaNode(String(), name='type', validator=OneOf(registry.names))) return schema
def validation(cls, **kwargs): # This one comes from Django # https://github.com/django/django/blob/273b96/ # django/core/validators.py#L45-L52 urlpattern = re.compile( r'^(?:http|ftp)s?://' # http:// or https:// r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... r'localhost|' # localhost... r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4 r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6 r'(?::\d+)?' # optional port r'(?:/?|[/?]\S+)$', re.IGNORECASE) kwargs['validator'] = Regex(urlpattern, msg="Invalid URL") return super(URLField, cls).validation(**kwargs)
class BatchRequestPath(SingleLine): """A path in a batch request. Either a resource url or a preliminary resource path (a relative path preceded by '@') or an absolute path. Example values: '@item/v1', 'http://a.org/adhocracy/item/v1', '/item/v1/' """ default = '' missing = required absolutpath = AbsolutePath.relative_regex preliminarypath = '[a-zA-Z0-9\_\-\.\/]+' validator = All( Regex('^(' + URL_REGEX + '|' + absolutpath + '|@' + preliminarypath + ')$'), Length(min=1, max=8192))
class ISOCountryCode(SchemaNode): """An ISO 3166-1 alpha-2 country code (two uppercase ASCII letters). Example value: US """ schema_type = StringType default = '' missing = drop validator = Regex(r'^[A-Z][A-Z]$|^$') def deserialize(self, cstruct=null): """Deserialize the :term:`cstruct` into an :term:`appstruct`.""" if cstruct == '': return cstruct return super().deserialize(cstruct)
class URL(SchemaNode): """String with a URL. Example value: http://colander.readthedocs.org/en/latest/ """ schema_type = StringType default = '' missing = drop # Note: url doesn't work, hence we use a regex adapted from # django.core.validators.URLValidator regex = re.compile( r'^(http|ftp)s?://' # scheme r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}(?<!-)\.?)|' # domain... r'localhost|' # localhost... r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4 r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6 r'(?::\d+)?' # optional port r'(?:/?|[/?]\S+)$', re.IGNORECASE) validator = Regex(regex, 'Must be a URL')
class FormCadastrar(CSRFSchema): """ Formulário para cadastro de novo usuário falta acesso para termos e condições de uso """ nome = SchemaNode( String(), validator=All( Length(max=32), #Function(verif_nome_unico, u"Nome já cadastrado"), Regex("^(\w)*$", "Usar apenas letras, números ou _"), ), description='Digite seu nome de usuário' ) email = SchemaNode( String(), validator=deferred_verif_email_unico, description='Digite seu e-mail', widget=widget.CheckedInputWidget( subject='Email', confirm_subject='Confirmar e-mail', size=40) ) senha = SchemaNode( String(), validator=Length(min=5, max=32), widget=widget.CheckedPasswordWidget(size=20), description='Digite sua senha (no mínimo 5 caracteres) e a confirme' ) confirmar = SchemaNode( Boolean(), #description='Aceitar termos e condições', label='Aceitar termos e condições', widget=widget.CheckboxWidget(), title='Confirmar', validator=Function(lambda x: x, u'É necessário aceitar as condições'), )
def validation(cls, **kwargs): kwargs['validator'] = Regex(kwargs['regex']) return super(RegexField, cls).validation(**kwargs)
class FormConfigurar(CSRFSchema): """ Formulário para configuração de perfil do usuário """ nome = SchemaNode( String(), validator=All( Length(max=32), #Function(verif_email_unico, u"Nome já cadastrado"), Regex("^(\w)*$", "Usar apenas letras, números ou _"), ), missing=unicode(''), description='Digite seu nome de usuário' ) sobrenome = SchemaNode( String(), validator=All( Length(max=32), #Function(verif_nome_unico, u"Nome já cadastrado"), ), missing=unicode(''), description='Digite seu sobrenome' ) genero = SchemaNode( String(), missing=unicode(''), widget=widget.SelectWidget(values=generos), title = "Gênero", ) nascimento = SchemaNode( String(), #máscara não funciona.... #Date(), missing=unicode(''), description='Digite a data de nascimento', #DateInputWidget não dá erro pelo menos.. widget= widget.TextInputWidget(mask='99/99/9999') ) """ erro foto = SchemaNode( deform.FileData(), widget=widget.FileUploadWidget(tmpstore), missing=unicode(''), description='Carregar foto' ) """ rua = SchemaNode( String(), missing=unicode(''), description='Digite sua rua') bairro = SchemaNode( String(), missing=unicode(''), description='Digite seu bairro') cidade = SchemaNode( String(), missing=unicode(''), description='Digite sua cidade') estado = SchemaNode( String(), missing=unicode(''), widget=widget.SelectWidget(values=estados)) informacoes = SchemaNode( String(), missing=unicode(''), description='Digite informações sobre você', title='Informações', validator=Length(max=100), widget=widget.TextAreaWidget(rows=10, cols=60) ) senha = SchemaNode( String(), missing=unicode(''), validator=Length(min=5, max=32), widget=widget.CheckedPasswordWidget(size=20), description='Alterar sua senha (no mínimo 5 caracteres) e a confirme' ) notificacoes_site = SchemaNode( Boolean(), label='Receber notificações pelo site', widget=widget.CheckboxWidget(), title='Notificações', missing=unicode(''), ) notificacoes_email = SchemaNode( Boolean(), label='Receber notificações pelo email', widget=widget.CheckboxWidget(), title='Notificações', missing=unicode(''), ) atualizacoes_pontos = SchemaNode( Boolean(), label='Atualizações de pontos próximos ao endereço cadastrado', widget=widget.CheckboxWidget(), title='Atualização', missing=unicode(''), ) atualizacoes_eventos = SchemaNode( Boolean(), label='Eventos próximos ao endereço cadastrado', widget=widget.CheckboxWidget(), title='Atualização', missing=unicode(''), )