[web2py] Re: Formatter and values=None problem

2012-10-25 Thread Paolo Caruccio
Did you try: db.tablename.fieldname.represent= lambda value: value if value else 'NT" ? web2py book reference http://web2py.com/books/default/chapter/29/06?search=represent#Record-representation Il giorno giovedì 25 ottobre 2012 03:20:29 UTC+2, Joe Barnhart ha scritto: > > I have an applicatio

[web2py] Re: Formatter and values=None problem

2012-10-25 Thread Paolo Caruccio
or better def format_function (value) formatted_value = . return formatted_value db.tablename.fieldname.represent= lambda value,row: format_function(value) if value else "Not Standard Time" Il giorno giovedì 25 ottobre 2012 13:31:43 UTC+2, Paolo Caruccio ha scritto: > > Did you

[web2py] Re: Formatter and values=None problem

2012-10-25 Thread Joe Barnhart
Actually Paolo, I have a custom Validator which contains the formatter function. It is supplied automatically when I use the validator, so I do not get a chance to change its calling sequence as you show in the case of using "represents". Here is the validator class: class IS_ELAPSED_TIME(obj

[web2py] Re: Formatter and values=None problem

2012-10-25 Thread Paolo Caruccio
Why don't you manage None values in int_to_hms function? Il giorno giovedì 25 ottobre 2012 21:56:17 UTC+2, Joe Barnhart ha scritto: > > Actually Paolo, I have a custom Validator which contains the formatter > function. It is supplied automatically when I use the validator, so I do > not get a

[web2py] Re: Formatter and values=None problem

2012-10-25 Thread Joe Barnhart
I do manage the "None" value in my formatter, Paulo. But it never gets called because the built-in code of the Field class tests the value for None and then exits before calling my formatter. So it doesn't matter that my formatter can handle None -- it is never called. That's why I posted th

[web2py] Re: Formatter and values=None problem

2012-10-26 Thread Paolo Caruccio
In my opinion, you have mainly two options to bypass None value check that formatter function in DAL does: option 1 : store None in database, delete formatter from validator, use represent in table field (I prefer this approach) class IS_ELAPSED_TIME(object): def __init__(self,error_message=

[web2py] Re: Formatter and values=None problem

2012-10-27 Thread Joe Barnhart
But Paolo -- you forgot the third option... FIX the problem in dal.py so that Validator classes work properly. It has no deleterious effects on other validators (at least so far in my testing) and it permits validators to format None values. -- Joe B. On Friday, October 26, 2012 9:56:57 AM

[web2py] Re: Formatter and values=None problem

2012-10-27 Thread Massimo Di Pierro
You can do db.table.filter_in = lambda value: 'NT' is value is None else value On Saturday, 27 October 2012 02:54:53 UTC-5, Joe Barnhart wrote: > > But Paolo -- you forgot the third option... > > FIX the problem in dal.py so that Validator classes work properly. It has > no deleterious effec

[web2py] Re: Formatter and values=None problem

2012-10-27 Thread Joe Barnhart
But Massimo -- why do an early exit from "Field.formatter" if the value is None? Why not give the formatter object a chance to format None values? I just don't understand this decision. It is expedient for a small number of programs where the user doesn't want to format None, but at the expen

[web2py] Re: Formatter and values=None problem

2012-10-27 Thread Massimo Di Pierro
There are two issues here. One is that validators were originally intended for form input and form input never submit None. They submit '' or missing value but never None. I agree with you that you may want to call validators and pass a None. In that case there is no need to ignore it. One probl

[web2py] Re: Formatter and values=None problem

2012-10-28 Thread Joe Barnhart
Hi Massimo -- The change I made is in the first message of this thread. I just changed one line in the definition of "formatter" in the class Field. -- Joe B. P.S. I need to start using the tools to generate diffs for proper patches. On Saturday, October 27, 2012 10:08:31 PM UTC-7, Massimo Di

[web2py] Re: Formatter and values=None problem

2012-10-28 Thread Massimo Di Pierro
OK. In trunk and let's see if anything breaks. On Sunday, 28 October 2012 04:15:28 UTC-5, Joe Barnhart wrote: > > Hi Massimo -- > > The change I made is in the first message of this thread. I just changed > one line in the definition of "formatter" in the class Field. > > -- Joe B. > > P.S. I ne

[web2py] Re: Formatter and values=None problem

2012-10-29 Thread Friedrich Weber
Hi there! For me, this change breaks optional `date` fields. Until now, I had a field like this: Field('somefield', type='date', label=T('...')), The value could be NULL, in which case `None` was displayed in a `SQLFORM.grid`. Now, this code crashes with: AttributeError: 'NoneT

[web2py] Re: Formatter and values=None problem

2012-10-29 Thread Massimo Di Pierro
This is what was talking about. I have fixed all the validators but think may break third party custom validators this change is not backward compatible. On Monday, 29 October 2012 07:04:05 UTC-5, Friedrich Weber wrote: > > Hi there! > > For me, this change breaks optional `date` fields. Unt

[web2py] Re: Formatter and values=None problem

2012-10-29 Thread Massimo Di Pierro
I am reverting this. sorry. On Monday, 29 October 2012 10:09:35 UTC-5, Massimo Di Pierro wrote: > > This is what was talking about. I have fixed all the validators but think > may break third party custom validators this change is not backward > compatible. > > On Monday, 29 October 2012 07:

[web2py] Re: Formatter and values=None problem

2012-10-30 Thread Joe Barnhart
OK. I will come up with a plan to extend the custom validators and not break backward compatibility. It seems like we could pass a keyword variable to be used instead of None should the value be empty for the formatter. Maybe a separate "empty" value for the parser (input to database) and fo

[web2py] Re: Formatter and values=None problem

2012-11-01 Thread Joe Barnhart
Please see my proposal about changing Field to map None values On Tuesday, October 30, 2012 3:44:03 PM UTC-7, Joe Barnhart wrote: > > OK. I will come up with a plan to extend the custom validators and not > break back

Re: [web2py] Re: Formatter and values=None problem

2012-10-27 Thread Jonathan Lundell
On 27 Oct 2012, at 10:08 PM, Massimo Di Pierro wrote: > There are two issues here. One is that validators were originally intended > for form input and form input never submit None. They submit '' or missing > value but never None. I agree with you that you may want to call validators > and pa