In gluon/contrib/gql.py web2py does this:
if field.type == 'datetime' and value != None and not
isinstance(value, datetime.datetime):
(y, m, d) = [int(x) for x in
str(value)[:10].strip().split('-')]
time_items = [int(x) for x in
str(value)[11:].strip().split(':')[:3]]
if len(time_items) == 3:
(h, mi, s) = time_items
else:
(h, mi, s) = time_items + [0]
row[tablename][fieldname] = datetime.datetime
(y,m,d,h,mi,s)
....
else:
row[tablename][fieldname] = value
perhaps you can put some print statements and see what "value" vs what
it should be.
Massimo
On Jun 29, 8:36 pm, Dan <[email protected]> wrote:
> Here is some sample code to produce the behavior I'm trying to
> describe. Note that in the controller, there are 2 lines commented out
> because they return an error ("TypeError: unsupported operand type(s)
> for -: 'str' and 'str'")
>
> db.define_table('timetest',
> db.Field('starttime','datetime',default=request.now),
> db.Field('endtime','datetime',default=request.now),
> )
>
> def timetest():
> form=FORM(TABLE(
> TR("Start time (Epoch Seconds UTC):",INPUT
> (_type="text",_name="start_time_es")),
> TR("End time (Epoch Seconds UTC):",INPUT
> (_type="text",_name="end_time_es")),
> TR("",INPUT(_type="submit",_value="Submit"))
> ))
>
> rowtoinsert = {}
> if form.accepts(request.vars):
> response.flash="form accepted input"
> startdatetime = datetime.datetime.utcfromtimestamp(float
> (form.vars.start_time_es))
> enddatetime = datetime.datetime.utcfromtimestamp(float
> (form.vars.end_time_es))
> # make the database insertion
> rowtoinsert={
> 'starttime':startdatetime,
> 'endtime':enddatetime,
> }
> idinserted = db.timetest.insert(**rowtoinsert)
> elif form.errors:
> response.flash="form is invalid"
>
> existing_rows = db(db.timetest.id>0).select().as_list()
> # for r in existing_rows:
> # r['time_difference'] = r['endtime'] - r['starttime']
>
> return dict(form=form,
> rowtoinsert=rowtoinsert,
> existing_rows=existing_rows)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---