Sorry I misunderstood. No objection. I will put it in. Thanks.

Massimo

On Dec 19, 11:59 am, Iceberg <[email protected]> wrote:
> Thanks for the quick feedback, but I don't understand. The hack only
> introduces a new behavior, and still maintain the old behavior. IMHO,
> a superset of feature is always backward compatible.
>
> Not to mention that the current implementation actually contains a bug
> (it can not accept a set although the doc said it can). We shall not
> keep the bug for backward compatibility, shall we?
>
> On Dec20, 1:26am, mdipierro <[email protected]> wrote:
>
> > sorry. it breaks backward compatibility.
>
> > Massimo
>
> > On Dec 19, 4:53 am, Iceberg <[email protected]> wrote:
>
> > > Hi Massimo,
>
> > > According to document, source code and test, currently IS_IN_SET
> > > accepts a list OR A SET as its first parameter "theset", and an
> > > optional list as labels. Actually, something is inconsistent here. How
> > > can an order-less set works with an ordered label? It can't.
>
> > > I am writing to suggest an improvement to IS_IN_SET, to better deal
> > > with order-less set.
>
> > > Let's say I have following field in model.py of a online survey
> > > application:
>
> > > # I like to group the order-less values and their labels in a dict
> > > DO_YOU_LIKE_SUSHI = {
> > >   'yes': 'Like it? I love it!',
> > >   'no': 'Come on, Sushi sucks!',
> > >   'unknown': 'What is Sushi?' }
>
> > > # Currently I have to use it in this style. It is too verbose to
> > > mention DO_YOU_LIKE_SUSHI three times.
> > > SQLField('do_you_like_sushi','text',requires=IS_IN_SET
> > > (DO_YOU_LIKE_SUSHI, DO_YOU_LIKE_SUSHI.values()))
>
> > > # So I suggest this modification in __init__() of class IS_IN_SET, in
> > > validators.py:
> > >       if isinstance(theset,dict): # Iceberg's hack
> > >         self.theset=theset
> > >         self.labels=theset.values()
> > >       else:
> > >         self.theset = [str(item) for item in theset]
> > >         self.labels = labels
>
> > > # Then, I can rewrite the model in this style. Notice the use of
> > > anonymous dict. I think it is clearer.
> > > SQLField('do_you_like_sushi','text',requires=IS_IN_SET(
> > >   {'yes': 'Like it? I love it!',
> > >   'no': 'Come on, Sushi sucks!',
> > >   'unknown': 'What is Sushi?' }
> > >   ))
>
> > > # In case you want to ask, why a hack inside validators.py is the only
> > > way to do this? I tried to define a subclass of IS_IN_SET in my own
> > > model.py, it almost works, but fails when a record is going to be
> > > saved in session (due to some boring pickling problem of __builtin__
> > > naming space issue).
>
> > > Regards,
> > > Iceberg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to