[web2py] Re: IS_TIME format

2015-06-24 Thread Niphlod
if you need a cutsom widget with a custom format, and you already rewrote 
the widget, why don't you rewrite also the validator ?!

On Wednesday, June 24, 2015 at 10:00:46 AM UTC+2, Annet wrote:
>
> I wrote a widget to format time:
>
> def timeplain(field, value):
> if value == None:
> value = ''
> elif 'strftime' in dir(value):
> value = value.strftime('%H:%M')
> id = '%s_%s' % (field._tablename, field.name)
> return INPUT(_type='text', _id=id, _class='form-control time_plain', 
> _name=field.name, value=str(value), requires=field.requires)
>
> and on the fileds of type time I have the following attributes:
>
> istime = dict(type='time', requires=IS_TIME(error_message='Formaat komt 
> niet overeen met HH:MM'), widget=timeplain)
>
>
> This works fine unless the form contains an error on the field of type 
> time, for example I have the following validation function:
>
> def __onvalidation_openinghours(form):
> if form.vars.startTime > form.vars.endTime:
> form.errors.endTime = 'De eind tijd is vroeger dan de start tijd'
>
> In this case the endTime is displayed in the format HH:MM:SS
> The issue can be fixed by adding:
>
> form.vars.endTime = form.vars.endTime.strftime('%H:%M')
>
> after form.errors.endTime, however, I wonder whether there is a way to 
> adjust the timeplain function to solve the issue.
>
>
> Kind regards,
>
> Annet
>
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: IS_TIME(format='%H:%M') unexpected keyword argument format

2012-04-17 Thread villas

>
> IS_TIME() does not format but understands the following formats

hh:mm:ss [am/pm]
hh:mm [am/pm]
hh [am/pm]
 
Otherwise I think you'll have to make your own validator which I don't 
think would be too difficult.


[web2py] Re: IS_TIME(format='%H:%M') unexpected keyword argument format

2012-04-17 Thread Annet
Hi Villas,

Thanks for your reply.

IS_TIME() does not format but understands the following formats
>
>
I thought maybe in line with IS_DATE(format='') and IS_DATETIME(format='') 
IS_TIME would have a format property as well.
 

> Otherwise I think you'll have to make your own validator which I don't 
> think would be too difficult.
>

I'll create my own validator.


Kind regards,

Annet 


[web2py] Re: IS_TIME(format='%H:%M') unexpected keyword argument format

2012-04-18 Thread villas
Hi Annet,   
Yes,  take a look at the code in gluon/validators.py

Best Regards,  D


On Wednesday, 18 April 2012 07:04:46 UTC+1, Annet wrote:
>
> Hi Villas,
>
> Thanks for your reply.
>
> IS_TIME() does not format but understands the following formats
>>
>>
> I thought maybe in line with IS_DATE(format='') and IS_DATETIME(format='') 
> IS_TIME would have a format property as well.
>  
>
>> Otherwise I think you'll have to make your own validator which I don't 
>> think would be too difficult.
>>
>
> I'll create my own validator.
>
>
> Kind regards,
>
> Annet 
>