Hi all

Once again a question related to CRUD: Why is onaccept executed before 
pressing the "Submit" button?
I've written a function "update()" which calls crud.update. After 
submitting new values I would like to look up the location's latitude and 
longitude.
At the moment I'm facing the problem that the function 
"locate(request.args(0))" is called before displaying the location details.
What do I have to change to lookup latitude and longitude after update? Is 
there a way to lookup the coordinates asynchronously?

-Luca.


@auth.requires_signature()
def update():
    form = 
crud.update(db.location,request.args(0),next=URL('location','select', 
user_signature=True),onaccept=locate(request.args(0)))
    return dict(form=form)

@auth.requires_signature()
def locate(locationId):
    from gluon.tools import geocode
    location = db.location(db.location.id==locationId)
    (lat, long) = geocode("%s %s %s" % (location.country, location.city, 
location.street))
    location.update_record(latitude = lat,longitude = long)

@auth.requires_signature()
def select():
    db.location.name.represent = lambda name, row: \
       A(name,_href=URL('location','update', args=(row.id), 
user_signature=True))
    form = crud.select(table=db.location)
    return dict(form=form)

Reply via email to