On 2/19/2010 11:20 AM, georgehu wrote:
> On 2/18/2010 4:51 PM, Fernando Correa Neto wrote:
>> Hey there,
>> Using beaker is no biggie.
>> In your .ini you need something like:
>> [filter:beaker]
>> use = egg:Beaker#beaker_session
>> beaker.session.key = yourapp.session
>> beaker.session.secret = supersecret
>> [pipeline:main]
>> pipeline = egg:repoze.zodbconn#closer
>>             egg:repoze.tm2#tm
>>             beaker
>>             app
>> And then you'll have 'yourapp.session' in your environment. i.e.:
>> request.environ['yourapp.session'] or
>> request.environ['beaker.session'].
>> Cheers,
>> Fernando
>> On Thu, Feb 18, 2010 at 10:10 PM, georgehu<geo...@gmail.com>  wrote:
>>> I'm trying to implement a simple session management like the Amazon
>>> site, you can throw your order item into your shopping cart even 
>>> without
>>> a login, and Amazon can remember your ordered items for many days. I'm
>>> using mysql and sqlalchemy, according to the document, the Beaker is
>>> suggested in this case. But I would like to see an example code snippet
>>> or tutorial on how to do it.
>>> Thanks
>>> George Hu
>>> _______________________________________________
>>> Repoze-dev mailing list
>>> Repoze-dev@lists.repoze.org
>>> http://lists.repoze.org/listinfo/repoze-dev
> Hi there, first I would like to thank you all for the help. As I'm 
> fairly new to the web app development, I want to know more details 
> about session management in my case. What I'm trying to implement is 
> like anonymous session in Amazon, for example, a user comes to the 
> site without login, drop items in the cart, now I need to save 
> something in the client browser to identify the user, I guess in this 
> case I can use the session id:
> request.environ['beaker.session'].id
> but how can I tell the browser to 'save' it into the client cookie?
> at the same time, I will create a record in the database to save the 
> item with the session id. When user comes back to the site later on, 
> the system will identify the user by matching the cookie with the 
> session id saved in the database, so how can I 'retrieve' the cookie 
> in this case? And BTW, is the generated session id always unique?
> Thanks
> George Hu
Okay, here is my code to do it, it seems good right now, any 
advise/suggestion is appreciated,
1. Save session into cookie:
s = request.enviorn['beaker.session']

2. Save session id into database:

  assign s.id to the field value

3. Get the records with certain id:

use a expression like  table.session_id == 
request.environ['beaker.session'].id to filter the records


George Hu

Repoze-dev mailing list

Reply via email to