[Grok-dev] Store session data

Jeffrey D Peterson bgpete at gmail.com
Tue Aug 17 14:21:50 EDT 2010


There is a great deal more you can do but, the basics are similar to this:

from zope.session.interfaces import ISession
import grok

session_name = 'my.session'

class MyView(grok.View):

	def update(self):
		session = ISession(self.request)[session_name]

		session['mydata'] = 'Some data you want to store'

		return

def MyOtherView(grok.View):

	def update(self):
		session = ISession(self.request)[session_name]

		self.mydata = session.get('mydata', None)

		return


--
Jeffrey Peterson
bgpete3 at gmail.com

> -----Original Message-----
> From: grok-dev-bounces at zope.org [mailto:grok-dev-bounces at zope.org] On
> Behalf Of bribon
> Sent: Tuesday, August 17, 2010 11:10 AM
> To: grok-dev at zope.org
> Subject: [Grok-dev] Store session data
> 
> 
> Hello,
> 
> I'm migrating my application based on ZODB to MySQL. I see in some
> features
> MySQL is faster than ZODB. My concern is I need to call to the database
> twice when I page is rendering. One is for generating the view, and
> another
> one is for the client side. I use javascript in the client side and
> REST for
> the communication between server and client.
> 
> Thus, I'm thinking of storing all the data related to whoever user in a
> session object or something like that. I mean in my actual application
> every
> time a page is rendered it needs to call the database to grab the data.
> All
> the data in my application is related to whoever user. So when a user
> is log
> in, I can grab all the data in one time and store it in session object.
> Then, if a user switches the page or makes any change, I can play with
> the
> session object, where the data of whoever user is stored, and I don't
> need
> to call every time to the database.
> 
> I was trying to find out something like this for Grok, but I haven't
> found
> out anything. I just found out for Zope a session object, but It seems
> like
> the session object is going in every request. I need to store the data
> of
> whoever user in the server (I guess in ZODB) and I can grab the user id
> from
> the request. Because all the data from the client to the server is
> going in
> JSON format.
> 
> It would be great if someone could guide me in this issue.
> 
> Thanks in advance!
> --
> View this message in context: http://old.nabble.com/Store-session-data-
> tp29449277p29449277.html
> Sent from the Grok mailing list archive at Nabble.com.
> 
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list