DenesL
unread,Sep 3, 2008, 5:02:45 PM9/3/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web2py Web Framework
Any use for the following validator?
Note 1: IS_NULL_OR would be special case where theset=[""]
Note 2: it can still generate a dropdown with all the values from
self.options() plus self.other.options()
Note 3: gluon/sqlhtml.py modification also required
Note 4: more specific error message handling can be applied to
IS_NULL_OR
class IS_IN_SET_OR(object):
def __init__(self, other, theset=[], labels=None,
error_message='value not in set'):
self.other=other
self.theset=[str(i) for i in theset]
self.labels=labels
self.error_message=error_message
def set_self_id(self,id):
if hasattr(self.other,'set_self_id'):
self.other.set_self_id(id)
def __call__(self,value):
if value in self.theset:
return(value,None)
v,e=self.other(value)
if e:
return(v,'%s and %s'%(self.error_message,e))
else:
return(v,self.error_message)
def formatter(self,value):
if hasattr(self.other,'formatter'):
return self.other.formatter(value)
return value
def options(self):
if self.labels:
return [(k,self.labels[i]) for i,k in
enumerate(self.theset)]
else:
return [(k,k) for k in self.theset]