Hello all,

I'm learning the inner workings of web2py and try to make a custom 
validator called IS_TIME_IN_RANGE (based on the IS_DATE_IN_RANGE 
validator). 

I saved the next code in : 
*www-data/web2py/applications/my_app/modules/customvalidators.py 
: *

*from gluon.validators import IS_TIME*

*class IS_TIME_IN_RANGE(IS_TIME):*

*    def __init__(self,*
*                 minimum=None,*
*                 maximum=None,*
*                 error_message=None):*
*        self.minimum = minimum*
*        self.maximum = maximum*
*        if error_message is None:*
*            if minimum is None:*
*                error_message = "Enter time on or before %(max)s"*
*            elif maximum is None:*
*                error_message = "Enter time on or after %(min)s"*
*            else:*
*                error_message = "Enter time in range %(min)s %(max)s"*
*        IS_TIME.__init__(self,*
*                             error_message=error_message)*
*        self.extremes = dict(min=self.minimum,*
*                             max=self.maximum)*

*    def __call__(self, value):*
*        ovalue = value*
*        (value, msg) = IS_TIME.__call__(self, value)*
*        if msg is not None:*
*            return (value, msg)*
*        if self.minimum and self.minimum > value:*
*            return (ovalue, translate(self.error_message) % self.extremes)*
*        if self.maximum and value > self.maximum:*
*            return (ovalue, translate(self.error_message) % self.extremes)*
*        return (value, None)*

*In models/db.py of my_app I added : *

*from customvalidators import IS_TIME_IN_RANGE*

*The function in controller/default :*

*def Schedule_Edit():*

*    record = db.Schedules(request.args(0)) or redirect(URL('index'))*
*    db.Schedules.Start_Time.requires = IS_TIME_IN_RANGE(minimum= 
'08:00:00',maximum= '10:00:00')*
*    form = SQLFORM(db.Schedules,*
*                   record=record)*
*    if form.process().accepted:*
*        session.flash = 'form accepted'*
*        redirect(URL('Appl'))*
*    elif form.errors:*
*        response.flash = 'errors on form'*
*    return dict(form = form)*

*And the corresponding view :*

*{{extend 'layout.html'}}*
*{{=form}}*

*The table definition "schedule" in models/db1.py :*

*db.define_table('Schedules',*
*                Field('Schedule_Type', 'reference 
Schedule_Type',requires=IS_NOT_EMPTY()),*
*                Field('Days', 'integer', requires=(IS_NOT_EMPTY(), 
IS_INT_IN_RANGE(1,8))),*
*                Field('Start_Time',requires=(IS_TIME(), IS_NOT_EMPTY())),*
*                Field('Stop_Time',requires=(IS_TIME(), IS_NOT_EMPTY())),*
*                Field('Status', 'reference 
Status',requires=IS_NOT_EMPTY()),*
*                auth.signature)*

Whenever I submit a form in Schedule_edit I get this error : 

*<type 'exceptions.Exception'> Validation error, field:Start_Time 
<applications.test_MySQL.modules.customvalidators.IS_TIME_IN_RANGE object 
at 0x79d8b1b0>*

When I place the IS_TIME_IN_RANGE validator directly in models/db.py, I get 
the this error : 

*<type 'exceptions.Exception'> Validation error, field:Start_Time 
<__restricted__.IS_TIME_IN_RANGE object at 0x79df31d0>*

I've tried several hours to fix this problem but I don't know where to 
start exactly.
Any advice would be really appreciated. 

Regards, 

Koen. 

-- 
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.

Reply via email to