[storm] Size Validation
Gerdus van Zyl
gerdusvanzyl at gmail.com
Sun Jul 6 16:30:49 BST 2008
Hi,
Is there any already built in method in storm to specify the size of a
varchar ? eg. varchar(25) that throws an exception if the string is
more than 25 chars long. On a similar note: you can currently prevent
the use of None for notnull columns using allow_none=False; is there
something that prevent an empty string?
If the above does not exist and is not planned, please take a look
below and tell me if this is close to the recommended solution:
class dcUnicode(Unicode):
def __init__(self, name=None, primary=False,size=10, **kwargs):
self.__size = size
Unicode.__init__(self, name, primary, **kwargs)
def __set__(self, obj, value):
if isinstance(value,str):
value = unicode(value)
if not value == None and len(value) == 0:
raise Exception("Empty string not allowed")
if not value == None and len(value) == self.__size:
raise Exception("string longer than " + str(self.__size))
Unicode.__set__(self, obj, value)
Thank you,
Gerdus van Zyl
More information about the storm
mailing list