We are a team of newbies in web2py trying out something new. If we insert 
into a database an item, and let modules access the new values it does not 
work properly as expected.
The code below:
code = ''
    
form = FORM(INPUT(_name='message'), INPUT(_type='submit'))
    if request.vars:
        r = [request.vars.message]
        db.post.insert(replies=r[0])# successful insert
    row = db(db.post.author== auth.user.id).select(db.post.id, db.post.
replies, orderby=~db.post.id, limitby=(0,1)).first()#should get the last row
    code  = row.replies if row else None
    return dict(value=code)

This code in the modules folder is part of other functions to access the 
latest row value for processing:
def Search_reply():
  db = current.db
  auth = Auth(db, hmac_key=Auth.get_or_create_key())
  auth.define_tables()
  name  = [r.replies.translate(None, '~!@#$%^&*()_+}{|":?><>-=][\';/.,') for 
r in db(db.post.author == auth.user.id).select(db.post.ALL)][-1]
  return name
  ##name will be used by other functions and a reply returned to view 

Problem

   1. Search_reply does not always gets me the last inserted item.
   2. I have to refresh the page for the function Search_reply to retrieve 
   the latest item

Tried options

   1. We tried using a different controller that had Search_replies and 
   called the function in view, also tried using the function from models with 
   the same result.
   2. We tried using db.commit() after db.post.insert() but with the same 
   results. One thing of note is that after the insert to db.post from web2py, 
   if running a python function that accesses the database on the python idle 
   interpreter, the new inserted message from db.post.replies is easily read 
   without having refreshed the web2py view page. Again, '
   code.replies if row else None
   gets the last inserted item BEFORE page refresh.

Is there a way to have modules access the new inserted message within 
web2py without page refresh?
Is there a way of dal refresh (not page refresh) after inserting a new item?
why doesn't db.commit(), on controller work to interrupt the workflow, have 
a message inserted then read the latest item?
We are thinking of something like this in the same workflow:
..workflow starts with user input
..controller functions insert the input to db
..controller imported functions read new inserted message for processing
..modules process message
..module through controller returns reply to view
..workflow ends

cc

Dream team

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