Hi Massimo and Falko Krause,

Since rev 143 ( http://code.google.com/p/web2py/source/detail?r=45d5f2dab0
), the IS_IN_SET() accepts a new syntax:
  ids = ('id1', 'id2')
  labels = ('first label', 'second label')
  combination = [ ids, labels ]
  IS_IN_SET(combination)

I doubt that is worthy, since you can always use the traditional
syntax:
  IS_IN_SET(ids, labels)
or this is not too hard:
  IS_IN_SET( combination[0], combination[1] )

The downside of the rev 143 is that it introduced unnecessary
complexity to the source code, and a side effect. Before rev 143,
IS_IN_SET() accepts even an iterator as its first argument, after rev
143 it generates exception for that.

Anyway, I post a patch here, it accepts all above syntax, and better,
it has enough doctest cases for them.

Sincerely,
Iceberg


diff -r ca439073317c gluon/validators.py
--- a/gluon/validators.py       Fri Feb 19 19:43:22 2010 -0600
+++ b/gluon/validators.py       Tue Feb 23 16:12:14 2010 +0800
@@ -238,6 +238,15 @@
         ('|max|john|', None)
         >>> IS_IN_SET(['max', 'john'], multiple=True)(('bill',
'john'))
         (('bill', 'john'), 'value not allowed')
+        >>> IS_IN_SET(('id1','id2'), ['first label','second label'])
('id1') # Traditional way
+        ('id1', None)
+        >>> IS_IN_SET({'id1':'first label', 'id2':'second label'})
('id1')
+        ('id1', None)
+        >>> import itertools
+        >>> IS_IN_SET(itertools.chain(['1','3','5'],['2','4','6']))
('1')
+        ('1', None)
+        >>> IS_IN_SET([('id1','id2'), ('first label','second label')])
('id1') # Redundant way
+        ('id1', None)
     """

     def __init__(
@@ -250,12 +259,11 @@
         sort=False,
         ):
         self.multiple = multiple
-        self.theset = [str(item) for item in theset]
         if isinstance(theset, dict):
+            self.theset = [str(item) for item in theset]
             self.labels = theset.values()
-        elif theset and (isinstance(theset[0], list) or  \
-                           isinstance(theset[0], tuple)) \
-                           and len(theset[0])==2:
+        elif theset and isinstance(theset, (tuple,list)) \
+            and isinstance(theset[0], (tuple,list)) and
len(theset[0])==2:
             self.theset = [str(item) for item,label in theset]
             self.labels = [str(label) for item,label in theset]
         else:

-- 
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.

Reply via email to