I promise I will look into this today. Massimo
On Apr 19, 7:05 am, jmverm...@xs4all.nl wrote: > I am still struggling with the formatting of date, I first tried to > solve the problem the best way, when I didn't get that to work I > thought I'd try the quick fix, unfortunately, resulting in the same > errors. > > This works, however, the date is displayed in the format: YYYY-mm-dd, > whereas I need dd-mm-YYYY. > > Validator in model: > > db.event.van_datum.requires=IS_DATE('%Y-%m-%d') > db.event.tot_datum.requires=IS_NULL_OR(IS_DATE('%Y-%m-%d')) > > web2py_ajax.html: > > try {$("input.date").focus( function() {Calendar.setup({ > inputField:this.id, ifFormat:"{{=T('%Y-%m-%d')}}", > showsTime:false}); }); } catch(e) {}; > > try { $("input.datetime").focus( function() {Calendar.setup({ > inputField:this.id, ifFormat:"{{=T('%Y-%m-%d %H:%M:%S')}}", > showsTime: true,timeFormat: "24"}); }); } catch(e) {}; > > try { $("input.time").clockpick({ > starthour:0, endhour:23, showminutes:true, military:true > > }); } catch(e) {}; > > Function in controller: > > def byplace(): > response.functionname=T('Event list by place') > response.image=URL(r=request,c='static',f='media/core/banner.png') > form=form_factory(SQLField('plaats',requires=IS_NOT_EMPTY(),\ > widget=lambda self, value:INPUT > (_id='eventbyplace',_name='plaats',_class='ac_input',_type='text',requires=self.requires)), > SQLField('datum',type='date',requires=IS_DATE('%Y-%m-%d')),\ > SQLField('dagen',requires=IS_IN_SET([7,14,28,56],labels=['1 > week','2 weken','4 weken','8 weken']))) > events=[] > if form.accepts(request.vars,session): > response.flash=T('no results') > fromdate=request.vars.datum > todate=IS_DATE()(fromdate)[0]+datetime.timedelta(days=int > (request.vars.dagen)) > events=db((db.event.plaats==request.vars.plaats)& > (db.event.van_datum>=fromdate)&\ > (db.event.van_datum<=todate)&(db.event.doelgroep=='Consumer')& > (db.event.scope=='Extern'))\ > .select > (db.event.id,db.event.event,db.event.van_datum,db.event.locatie,\ > db.event.eventtype,orderby=db.event.van_datum) > elif form.errors: > response.flash=T('form has errors') > else: > response.flash=T('please fill the form') > return dict(form=form,events=events) > > In the view: > > <td> > {{=event.van_datum}} > </td> > > This doesn't work: > > Validator in model: > > db.event.van_datum.requires=IS_DATE('%d-%m-%Y') > db.event.tot_datum.requires=IS_NULL_OR(IS_DATE('%d-%m-%Y')) > > web2py_ajax.html: > > try {$("input.date").focus( function() {Calendar.setup({ > inputField:this.id, ifFormat:"{{=T('%d-%m-%Y')}}", > showsTime:false}); }); } catch(e) {}; > > try { $("input.datetime").focus( function() {Calendar.setup({ > inputField:this.id, ifFormat:"{{=T('%d-%m-%Y %H:%M:%S')}}", > showsTime: true,timeFormat: "24"}); }); } catch(e) {}; > > try { $("input.time").clockpick({ > starthour:0, endhour:23, showminutes:true, military:true}); } catch(e) > {}; > > On Apr 17, 8:09 am, jmverm...@xs4all.nl wrote: > > Function in the controller: > def byplace(): > response.functionname=T('Event list by place') > response.image=URL(r=request,c='static',f='media/core/banner.png') > form=form_factory(SQLField('plaats',requires=IS_NOT_EMPTY(),\ > widget=lambda self, value:INPUT > (_id='eventbyplace',_name='plaats',_class='ac_input',_type='text',requires=self.requires)), > SQLField('datum',type='date',requires=IS_DATE('%d-%m-%Y')),\ > SQLField('dagen',requires=IS_IN_SET([7,14,28,56],labels=['1 > week','2 weken','4 weken','8 weken']))) > events=[] > if form.accepts(request.vars,session): > response.flash=T('no results') > fromdate=request.vars.datum > todate=IS_DATE()(fromdate)[0]+datetime.timedelta(days=int > (request.vars.dagen)) > events=db((db.event.plaats==request.vars.plaats)& > (db.event.van_datum>=fromdate)&\ > (db.event.van_datum<=todate)&(db.event.doelgroep=='Consumer')& > (db.event.scope=='Extern'))\ > .select > (db.event.id,db.event.event,db.event.van_datum,db.event.locatie,\ > db.event.eventtype,orderby=db.event.van_datum) > elif form.errors: > response.flash=T('form has errors') > else: > response.flash=T('please fill the form') > return dict(form=form,events=events) > > Exposing the function results in the following error: > > File "/Library/Python/2.5/site-packages/web2pyfitwise/applications/ > core/controllers/eventlist.py", line 25, in byplace > todate=IS_DATE()(fromdate)[0]+datetime.timedelta(days=int > (request.vars.dagen)) > TypeError: cannot concatenate 'str' and 'datetime.timedelta' objects > > When I replace todate=... with: > > todate=form.vars.datum+datetime.timedelta(days=int(form.vars.dagen)) > > and expose the function I get this error: > > File "/Library/Python/2.5/site-packages/web2pyfitwise/applications/ > core/controllers/eventlist.py", line 29, in byplace > db.event.eventtype,orderby=db.event.van_datum) > File "/Library/Python/2.5/site-packages/web2pyfitwise/gluon/sql.py", > line 1902, in select > r = response(query) > File "/Library/Python/2.5/site-packages/web2pyfitwise/gluon/sql.py", > line 1897, in response > self._db._execute(query) > File "/Library/Python/2.5/site-packages/web2pyfitwise/gluon/sql.py", > line 664, in <lambda> > **b) > DataError: date/time field value out of range: "21-04-2009" > HINT: Perhaps you need a different "datestyle" setting. > > which, I guess, refers to the orderby clause in the query: > > events=db((db.event.plaats==request.vars.plaats)& > (db.event.van_datum>=fromdate)&\ > (db.event.van_datum<=todate)&(db.event.doelgroep=='Consumer')& > (db.event.scope=='Extern'))\ > .select > (db.event.id,db.event.event,db.event.van_datum,db.event.locatie,\ > db.event.eventtype,orderby=db.event.van_datum) > > Furthermore, inserting an event through appadmin results in a: must be > YYYY-MM-DD! validation error. > > I hope one of you can help me solve this problem, it's getting on my > nerves.... > > Kind regards, > > Annet. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---