1. hehehe, my "dust" naming convention was inspired from the classic:
char*strstr(const char*haystack, const char*needle)
so that people would easier know the parameter is defining something
to remove, not something to keep (in case of misunderstanding). But
hey, choose whatever name you want. :)
2. No objection to "strip() all input fields except 'text' fields by
default".
3. The new CLEANUP() code looks fine. BTW, does this usage:
Field('foo',requires=[CLEANUP(regex='.'), IS_IN_DB()])
still provide a drop-down list for the filed foo? If not, then the
IS_IN_DB() should better still have a new parameter named "dust" or
whatever you prefer.
On Oct13, 3:04am, mdipierro <[email protected]> wrote:
> I do not like "dust" and I too would like to avoid having to modify
> all validators.
> Is there any reason not to strip() all input fields except 'text'
> fields by default?
> Why would anybody want to have spaces before or after a non-empty
> string?
>
> Massimo
>
> On Oct 12, 1:26 pm, devnull <[email protected]> wrote:
>
>
>
> > Thanks Thadeus, that works for me.
>
> > An alternative to adding a parameter to individual validators for pre-
> > validation steps is to add something optional like [requires] that's
> > called [interprets] or something similar -- for a method or a list of
> > methods to execute before applying all validators.
>
> > One might prefer this if the plan is to trim whitespace before
> > applying 3 validators on one field - you'd only say trim once instead
> > of repeating it three times. It's less flexible though.
>
> > Maybe it's a really bad idea, but there's a chance it might spark a
> > better idea.
>
> > On Oct 12, 3:59 am, Joe Barnhart <[email protected]> wrote:
>
> > > +1 on the idea, but the name "dust" seems a little idiomatic, doesn't it?
>
> > > As an aside, I discovered the absolutely fastest way to remove a set of
> > > characters from text in Python is the string function called "translate".
> > > It's wicked fast at removing as well as translating characters. It's not
> > > unicode, tho.
>
> > > -- Joe
>
> > > On Sat, Oct 10, 2009 at 5:36 PM, Iceberg <[email protected]> wrote:
> > > > How about adding a new parameter for some old validators? That will
> > > > not break backward compatibility. Here is how.
>
> > > > class CLEANUP(Validator):
> > > > def __init__(self,dust=None):
> > > > # dust can be None, or a list of chars (aka string), or a regex.
> > > > # If it is a string, it specifis the set of characters to be
> > > > removed.
> > > > # If omitted or None, defaults to removing whitespace.
> > > > # If it is a regex, it removes chars met by the regex.
> > > > self.dust=dust
> > > > def __call__(self,value):
> > > > # the implementation
>
> > > > And we can add the new parameter dust for IS_IN_DB too.
>
> > > > class IS_IN_DB(Validator):
> > > > def __init__(self, ......, dust=None):
> > > > # mentioned above
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---