Contribution to validators

22 views
Skip to first unread message

Pierre-Antoine Roiron

unread,
Dec 8, 2015, 7:39:33 PM12/8/15
to web...@googlegroups.com
Hi,
I'm working on a web2py project, and I'm slowly learning. Thanks for all the ressources available. I needed a new DAL validator like IS_UPPER() but based on title(), so I looked over the source files and saw validators.py. I added the class IS_TITLE() to it but it doesn't seems to be enough to make it work on my model. Candid developer... What should I do ?
I'd like to contribute to the validators.py file, so here's a new class to add if web2py's team agree :

class IS_TITLE(Validator):
   
"""
    Converts to title ::


        >>> IS_TITLE()('abc-def ghi')
        ('Abc-Def Ghi', None)
        >>> IS_TITLE()('é')
        ('
\xc3\x89', None)


    """



   
def __call__(self, value):
       
return (value.decode('utf8').title().encode('utf8'), None)

And here's the documentation for the book :
IS_TITLE

This validator never returns an error. It converts the value to title case.

requires = IS_TITLE()

Pierre-Antoine Roiron

unread,
Dec 9, 2015, 3:46:11 AM12/9/15
to web...@googlegroups.com
It seems like I forgot to add IS_TITLE() to the __all__ declaration or whatever is its name in validators.py (I am not an developer, sorry for the inapropriate vocabulary). It seems to work for now.

I am still open to some explanations (what is validators.pyc).
Reply all
Reply to author
Forward
0 new messages