I see you are not using Auth, this means a lot of extra work for you.

Assuming user.id was stored in session.user_id upon login you can do

db.guestbook.author.default=session.user_id
db.guestbook.author.writable=False # readonly
db.guestbook.author.readable=False # invisible

Anyway, I suggest you use auth.

Massimo

On Jun 2, 5:59 pm, Bill <isp...@gmail.com> wrote:
> Hi,
>
> Guest Book users as they create a Guest Book entry will have an id
> assigned to that entry. This id goes into my users table so that I can
> retrieve it.  I thought the lambda function set up would enable me to
> do this.  Bottom line:  I don't know how to do accomplish this end.
>
> Also, I don't know how to reference the user of that id.  Thus, I was
> trying to use cookie sessions provided with web2py to store the user's
> id.
>
> If I replace the current "session.flash" value of "Guest Book
> Completed.Now YOU are on the map!" with "forms.vars.id", the variable
> "id" is unavailable.  Would like to get the id of the most recent
> entry in the guestbook table and place it in my users table in a field
> called gbentry.
>
> My idea for using lambda came from this post:
>
> form=crud.create(db.table,onaccept=lambda form: do_something_with
> (for.vars.id))http://groups.google.com/group/web2py/browse_thread/thread/373ba9cee9...
>
> Here are the models and the controller.  I thank you for your help.
>
> //models
> db.define_table('user',
>     SQLField('alias'),
>     SQLField('email'),
>     SQLField('password','password'),
>     SQLField('post_time','double',default=now),
>     SQLField('gbentry'))
>
> db.define_table('guestbook',
>    SQLField('post_time','double',default=now),
>    SQLField('comments','integer',default=0),
>    SQLField('filecabinet'),
>    SQLField('author',db.person),
>    SQLField('author_alias'),
>    SQLField('url',length=128),
>    SQLField('title',length=128),
>    SQLField('flagged','boolean',default=False),
>    SQLField('lat','double',default=1.0),
>    SQLField('lon','double',default=1.0),
>    SQLField('location','text'),
>    SQLField('client_ip'))
>
> //controllers
> def post():
>     if not session.authorized:
>         redirect(URL(r=request,f='login'))
> form=SQLFORM(db.guestbook,fields=['url','title','location'])
>     form.vars.client_ip=request.env.remote_addr
>     (latitude, longitude) = geocode(form.vars.location)
>     form.vars.lat=latitude
>     form.vars.lon=longitude
>     if form.accepts(request.vars,session):
>         session.flash=' Guest Book Completed.Now YOU are on the map! '
>         redirect(URL(r=request,f='index',args=
> [form.vars.filecabinet]))
>     return dict(form=form)
>
> On Jun 2, 3:27 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Not sure I understand the question. After
>
> > if form.accepts(...)
> >     # here you can use form.vars.id
>
> > On Jun 2, 3:31 pm, Bill <isp...@gmail.com> wrote:
>
> > > How do I use lambda to retrieve the most recent id in conjunction with
> > > the guestbook code below?
>
> > > Would like to update my users table with a reference id to their
> > > guestbook entry.
>
> > > In order store the guestbook entry id, I need to have a reference
> > > id.   I am not sure how to obtain this.
>
> > > One idea would be to grab it at login and save as a session variable.
> > > Please give me some insight.  The reference below has given me ideas,
> > > but I seem to be unable to use it.
>
> > > form=SQLFORM(db.guestbook,fields=['url','title','location'])
> > >     form.vars.client_ip=request.env.remote_addr
> > >     (latitude, longitude) = geocode(form.vars.location)
> > >     form.vars.lat=latitude
> > >     form.vars.lon=longitude
> > >     if form.accepts(request.vars,session):
> > >         session.flash=' Guest Book Completed.Now YOU are on the map! '
> > >         redirect(URL(r=request,f='index',args=
> > > [form.vars.filecabinet]))
> > >     return dict(form=form)
>
> > > Reference:
>
> > >http://groups.google.com/group/web2py/browse_thread/thread/5e1f13df58...
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to