IS_NULL_OR

6 views
Skip to first unread message

Massimo Di Pierro

unread,
Mar 10, 2008, 1:18:41 AM3/10/08
to web...@googlegroups.com
there is a new validator in trunk.

IS_NULL_OR you use it like in

requires=IS_NULL_OR(IS_ALPHANUMERIC())

requires=IS_NULL_OR(IS_DATETIME())

Please try it and see if works for you.

Massimo

limodou

unread,
Mar 10, 2008, 1:24:09 AM3/10/08
to web...@googlegroups.com
Great! I think I like it.

--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou

Massimo Di Pierro

unread,
Mar 10, 2008, 1:27:21 AM3/10/08
to web...@googlegroups.com
:-)

Massimo Di Pierro

unread,
Mar 10, 2008, 1:30:40 AM3/10/08
to web...@googlegroups.com
Mind that if field is a string type you may want to do

requires=IS_NULL_OR(IS_ALPHANUMERIC(),null='')

so that an empty string will be stored as an empty string (null='')
and not as a NULL value (null=None).

On Mar 10, 2008, at 12:24 AM, limodou wrote:

Massimo Di Pierro

unread,
Mar 10, 2008, 3:05:11 AM3/10/08
to web...@googlegroups.com
I would like to release web2py 1.25 by the start of pycon2008 next week.
Is there any open issue that needs to be addressed?

Massimo


limodou

unread,
Mar 10, 2008, 4:18:26 AM3/10/08
to web...@googlegroups.com
On Mon, Mar 10, 2008 at 1:30 PM, Massimo Di Pierro
<mdip...@cs.depaul.edu> wrote:
>
> Mind that if field is a string type you may want to do
>
> requires=IS_NULL_OR(IS_ALPHANUMERIC(),null='')
>
> so that an empty string will be stored as an empty string (null='')
> and not as a NULL value (null=None).
>
I tried, it's good!

DenesL

unread,
Mar 18, 2008, 4:23:33 PM3/18/08
to web2py Web Framework
Can this be used to handle reference fields that might not contain a
reference yet (i.e. linked list) or datetime fields that can be set
later (e.g. closing date) ?.

In the case of a reference the id is an integer so I can not use
IS_IN_DB alone because it can be empty and I can not use
IS_NULL_OR(IS_IN_DB... because then the value is None and accepts
blows up.

If I set it to IS_NULL_OR(IS_IN_DB...,null=0) accepts works but then I
have to keep erasing the value in the form before submitting,
otherwise I get a "value not in database!" error.

Similar situation with empty datetime fields.

Suggestions are welcome. Thanks.

Massimo Di Pierro

unread,
Mar 18, 2008, 11:10:31 PM3/18/08
to web...@googlegroups.com
Need to run some tests here. I am not sure this is something that
should be encouraged.
Can you explain what you mean by "erasing the value in the form"?

DenesL

unread,
Mar 19, 2008, 9:15:01 AM3/19/08
to web2py Web Framework
> Can you explain what you mean by "erasing the value in the form"?

If, for example, this is the requires: IS_NULL_OR(IS_IN_DB...,null=0)
then the corresponding field will end up with a 0 value when it is
left empty. The next time it is shown, let say through the DB
administration, it will have a 0 in it. Since it is supposed to be
empty you have to take out the 0, erasing it from the form, and in the
particular case of a reference you must erase it otherwise you get a
'value not in DB' error.

I think that this suggests the need for a special value that signifies
'empty' that is set accordingly to the field type and is converted to
a null string when it will be displayed. There is always three aspects
to the value of a field: the value stored in the DB, the value as a
Python variable in web2py and the value as displayed in the browser.

In any case I am open to suggestions on how to handle 'empty'
fields.

DenesL

unread,
Mar 20, 2008, 7:21:31 PM3/20/08
to web2py Web Framework
Also note that introducing IS_NULL_OR before an IS_IN_DB cancels the
drop down generation. It should actually create a drop down with an
extra option using an empty string.

But this can introduce a recursive complexity in the validators when
trying to build the drop downs. How many times can you use IS_NULL_OR?
as in IS_NULL_OR(IS_IN_DB...,IS_NULL_OR(...)) a royal headache!.

The current validators are a list of conditions that should be met by
the field: field complies with cond1 AND also with cond2 AND so on.
So a validator is currently [ cond1 AND cond2 AND ...]
We could express OR conditions in terms of AND condition using De
Morgan's laws (at least in theory):
[ cond1 OR cond2 ] = not [ not cond1 AND not cond2 ]
but how to implement this is another story.

Massimo Di Pierro

unread,
Mar 21, 2008, 12:01:58 AM3/21/08
to web...@googlegroups.com
hmmm. wil think about this.

For now there is a new version in trunk that let you use IS_NULL_OR
for dates, integers, float, etc.

Massimo

Reply all
Reply to author
Forward
0 new messages