Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Set up a session when your classes are in a separate files

Received: by 10.182.160.42 with SMTP id xh10mr79607obb.19.1345146235339;
        Thu, 16 Aug 2012 12:43:55 -0700 (PDT)
X-BeenThere: webpy@googlegroups.com
Received: by 10.182.18.234 with SMTP id z10ls2306554obd.7.gmail; Thu, 16 Aug
 2012 12:43:53 -0700 (PDT)
Received: by 10.182.37.103 with SMTP id x7mr117506obj.5.1345146233313;
        Thu, 16 Aug 2012 12:43:53 -0700 (PDT)
Date: Thu, 16 Aug 2012 12:43:52 -0700 (PDT)
From: Adam Bengtsson <adam...@gmail.com>
To: webpy@googlegroups.com
Message-Id: <ceebba88-661c-4b7b-9683-ccbdd906659d@googlegroups.com>
In-Reply-To: <CAFWNNM7aH0W_WUp6no2YiuSyAM1rRPDh8ovEKT8Kh4tfm76JEw@mail.gmail.com>
References: <60692046-40bc-4f82-b632-096b20b72704@googlegroups.com>
 <CACOY-+KSjAR6=n=iEf8H=UiFveB8JQA5tmJNNvuCV6_MchqX1A@mail.gmail.com>
 <CAFWNNM7aH0W_WUp6no2YiuSyAM1rRPDh8ovEKT8Kh4tfm76JEw@mail.gmail.com>
Subject: Re: [webpy] Set up a session when your classes are in a separate
 files
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_913_23996088.1345146232896"

------=_Part_913_23996088.1345146232896
Content-Type: multipart/alternative; 
	boundary="----=_Part_914_11542187.1345146232896"

------=_Part_914_11542187.1345146232896
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hello,

Thank you both for your replies, having totally missed the cookbook 
example, I think I'll give that a try!

//Adam

Den onsdagen den 15:e augusti 2012 kl. 21:05:27 UTC+2 skrev Marios Zindilis:
>
> Perhaps this covers your question?
>
> http://webpy.org/cookbook/sessions_with_subapp
>
> On Wed, Aug 15, 2012 at 9:07 PM, Shannon Cruey <
> shanno...@cloudsidekick.com <javascript:>> wrote:
>
>> I had this issue when I started with web.py, and I was completely new to 
>> Python too.
>>
>> Right or wrong, here's what I did.  I moved on because it worked.
>>
>> 1) I created a file called sharedsession.py  It's one line - looks like 
>> this:
>>
>>    - session = None
>>    
>> 2) in my main web.py file I do this:
>>
>>    - import sharedsession
>>    - ...
>>    - sharedsession.session = web.session.Session(app, 
>>    web.session.ShelfStore(shelve.open('session.shelf'))) 
>>
>> (I'm using shelf because I was having problems with the other type and 
>> wsgi/apache, and I don't wanna use a db.)
>> Then, in all my other modules I "import sharedsession" and just reference 
>> 'session' there.
>>
>> Like I said, I'm no python expert, in fact I still don't fully understand 
>> "import" to this day.  (It's like a black box for me... it works, it's 
>> magical in some ways, and I don't understand why.)
>>
>> If this is horribly wrong I hope someone else will warn you not to use my 
>> terrible idea.  If it's right, you're welcome! ;-)
>>
>>
>>
>>
>> On Wed, Aug 15, 2012 at 10:36 AM, Adam Bengtsson <ada...@gmail.com<javascript:>
>> > wrote:
>>
>>> Hello agian,
>>>
>>> I was eager to try out the session functionality in web.py but am not 
>>> really sure how to go about doing this. Having consulted the cookbook I've 
>>> found the Working with Sessions-example.
>>>
>>> In this example, the app-object is passed as an argument to the session 
>>> initialization, and the session-object is then used globally by the other 
>>> classes _in this file_.
>>>
>>> How would I go about if I wanted to initialize or at least use a session 
>>> object in a different file where I no longer have the app-reference? Is 
>>> there some obscure reference to the current application somewhere within 
>>> the web-package?
>>>
>>> Thank you,
>>> Adam
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "web.py" group.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msg/webpy/-/GyuekdV6G9EJ.
>>> To post to this group, send email to we...@googlegroups.com<javascript:>
>>> .
>>> To unsubscribe from this group, send email to 
>>> webpy+un...@googlegroups.com <javascript:>.
>>> For more options, visit this group at 
>>> http://groups.google.com/group/webpy?hl=en.
>>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "web.py" group.
>> To post to this group, send email to we...@googlegroups.com <javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> webpy+un...@googlegroups.com <javascript:>.
>> For more options, visit this group at 
>> http://groups.google.com/group/webpy?hl=en.
>>
>
>
>
> -- 
> Marios Zindilis
>
>  
------=_Part_914_11542187.1345146232896
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

Hello,<div><br></div><div>Thank you both for your replies, having totally missed the cookbook example, I think I'll give that a try!</div><div><br></div><div>//Adam<br><br>Den onsdagen den 15:e augusti 2012 kl. 21:05:27 UTC+2 skrev Marios Zindilis:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Perhaps this covers your question?<div><br></div><div><a href="http://webpy.org/cookbook/sessions_with_subapp" target="_blank">http://webpy.org/cookbook/<wbr>sessions_with_subapp</a><br><br><div class="gmail_quote">On Wed, Aug 15, 2012 at 9:07 PM, Shannon Cruey <span dir="ltr">&lt;<a href="javascript:" target="_blank" gdf-obfuscated-mailto="e5DH868jVdgJ">shanno...@cloudsidekick.<wbr>com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I had this issue when I started with web.py, and I was completely new to Python too.<br><br>Right or wrong, here's what I did.&nbsp; I moved on because it worked.<br>
<br>1) I created a file called sharedsession.py&nbsp; It's one line - looks like this:<br>

<ul><li>session = None<br></li></ul>2) in my main web.py file I do this:<br><ul><li>import sharedsession</li><li>...<br></li><li>sharedsession.session = web.session.Session(app, web.session.ShelfStore(shelve.<wbr>open('session.shelf')))</li>


</ul><p>(I'm using shelf because I was having problems with the other type and wsgi/apache, and I don't wanna use a db.)<br></p>Then, in all my other modules I "import sharedsession" and just reference 'session' there.<br>


<br>Like I said, I'm no python expert, in fact I still don't fully understand "import" to this day.&nbsp; (It's like a black box for me... it works, it's magical in some ways, and I don't understand why.)<br>

<br>If this is horribly wrong I hope someone else will warn you not to use my terrible idea.&nbsp; If it's right, you're welcome! ;-)<br>
<br><br><br><br><div class="gmail_quote">On Wed, Aug 15, 2012 at 10:36 AM, Adam Bengtsson <span dir="ltr">&lt;<a href="javascript:" target="_blank" gdf-obfuscated-mailto="e5DH868jVdgJ">ada...@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Hello agian,<div><br></div><div>I was eager to try out the session functionality in web.py but am not really sure how to go about doing this. Having consulted the cookbook I've found the Working with Sessions-example.</div>


<div><br></div><div>In this example, the app-object is passed as an argument to the session initialization, and the session-object is then used globally by the other classes _in this file_.</div><div><br></div><div>How would I go about if I wanted to initialize or at least use a session object in a different file where I no longer have the app-reference? Is there some obscure reference to the current application somewhere within the web-package?</div>


<div><br></div><div>Thank you,</div><div>Adam</div><span><font color="#888888"><span><font color="#888888">

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "web.py" group.<br>
To view this discussion on the web visit <a href="https://groups.google.com/d/msg/webpy/-/GyuekdV6G9EJ" target="_blank">https://groups.google.com/d/<wbr>msg/webpy/-/GyuekdV6G9EJ</a>.<br> 
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="e5DH868jVdgJ">we...@googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="e5DH868jVdgJ">webpy+un...@<wbr>googlegroups.com</a>.<br>

For more options, visit this group at <a href="http://groups.google.com/group/webpy?hl=en" target="_blank">http://groups.google.com/<wbr>group/webpy?hl=en</a>.<br>


</font></span></font></span></blockquote></div><span><font color="#888888"><br>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "web.py" group.<br>
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="e5DH868jVdgJ">we...@googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="e5DH868jVdgJ">webpy+un...@<wbr>googlegroups.com</a>.<br>

For more options, visit this group at <a href="http://groups.google.com/group/webpy?hl=en" target="_blank">http://groups.google.com/<wbr>group/webpy?hl=en</a>.<br>


</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Marios Zindilis<br><br>
</div>
</blockquote></div>
------=_Part_914_11542187.1345146232896--

------=_Part_913_23996088.1345146232896--