please , i would like to ask for a little help. I have few functions stored in my views.py under class Test. When i visit my homepage the urls.py is calling method homepage from views.py as i mentioned before. Here it dig some data as current server time and user agent from webbrowser. Now i need to pass these two details to any other function when the function is called. I read all docs about session, cache and others, but still did not found an answer. I also tried to store these details to session with
s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead') s['last_login'] = datetime.datetime.now() s.save()
and later call it. It saved it but with different session_key. So back to the first problem. Please how can i pass some data from one method to all methods.
Sorry if I misunderstood your problem, why don't you simply store the last_login somewhere in a userprofile? Since -- judging from the name -- it should only be altered when the user really logs in, I don't see the relation with a session there :-/
On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote: > hi all
> please , i would like to ask for a little help. I have few functions > stored in my views.py under class Test. When i visit my homepage the > urls.py is calling method homepage from views.py as i mentioned before. > Here it dig some data as current server time and user agent from > webbrowser. Now i need to pass these two details to any other function > when the function is called. I read all docs about session, cache and > others, but still did not found an answer. > I also tried to store these details to session with
> s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead') > s['last_login'] = datetime.datetime.now() > s.save()
> and later call it. It saved it but with different session_key. > So back to the first problem. Please how can i pass some data from one > method to all methods.
the last_login is an example from documentation. My problems are, that when i save something to the session(as current date, or user agent) with some key, and then look to database from terminal, the key is different.
The second problem is, that i cannot find a way how to pass some data from one function to all other functions.
Horst Gutmann wrote: > Sorry if I misunderstood your problem, why don't you simply store the > last_login somewhere in a userprofile? Since -- judging from the name > -- it should only be altered when the user really logs in, I don't see > the relation with a session there :-/
> -- Horst
> On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
>> hi all
>> please , i would like to ask for a little help. I have few functions >> stored in my views.py under class Test. When i visit my homepage the >> urls.py is calling method homepage from views.py as i mentioned before. >> Here it dig some data as current server time and user agent from >> webbrowser. Now i need to pass these two details to any other function >> when the function is called. I read all docs about session, cache and >> others, but still did not found an answer. >> I also tried to store these details to session with
>> s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead') >> s['last_login'] = datetime.datetime.now() >> s.save()
>> and later call it. It saved it but with different session_key. >> So back to the first problem. Please how can i pass some data from one >> method to all methods.
I think the current documentation and implementation of the
SessionStore is not correct. I had some problems with it yesterday as
well. I eventually solved it differently and without a session.
However if you just want to access a session from across different
views you can just use the 'request.session' dictionary. No need for
using the SessionStore.
But like Horst said try to figure out if you really need to use a
session in the first place.
Wim
On Apr 15, 2:05 pm, "hkm...@gmail.com" <hkm...@gmail.com> wrote:
> please , i would like to ask for a little help. I have few functions
> stored in my views.py under class Test. When i visit my homepage the
> urls.py is calling method homepage from views.py as i mentioned before.
> Here it dig some data as current server time and user agent from
> webbrowser. Now i need to pass these two details to any other function
> when the function is called. I read all docs about session, cache and
> others, but still did not found an answer.
> I also tried to store these details to session with
> s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
> s['last_login'] = datetime.datetime.now()
> s.save()
> and later call it. It saved it but with different session_key.
> So back to the first problem. Please how can i pass some data from one
> method to all methods.
Why do you want to manipulate just a specific session that might not even be an existing sesion anymore? And for what reason do you want to give other views the same data as the last view that's been used? To me this sounds just like using a normal session (as provided by request.session) ...
Could you perhaps tell a few more details about what you want to achieve and for what reason? :-)
On Tue, Apr 15, 2008 at 2:19 PM, hkm...@gmail.com <hkm...@gmail.com> wrote: > hi Horst
> the last_login is an example from documentation. My problems are, that > when i save something to the session(as current date, or user agent) > with some key, and then look to database from terminal, the key is > different.
> The second problem is, that i cannot find a way how to pass some data > from one function to all other functions.
> thank you > pavel
> Horst Gutmann wrote: > > Sorry if I misunderstood your problem, why don't you simply store the > > last_login somewhere in a userprofile? Since -- judging from the name > > -- it should only be altered when the user really logs in, I don't see > > the relation with a session there :-/
> > -- Horst
> > On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
> >> hi all
> >> please , i would like to ask for a little help. I have few functions > >> stored in my views.py under class Test. When i visit my homepage the > >> urls.py is calling method homepage from views.py as i mentioned before. > >> Here it dig some data as current server time and user agent from > >> webbrowser. Now i need to pass these two details to any other function > >> when the function is called. I read all docs about session, cache and > >> others, but still did not found an answer. > >> I also tried to store these details to session with
> >> and later call it. It saved it but with different session_key. > >> So back to the first problem. Please how can i pass some data from one > >> method to all methods.
> >> thank you very much for helping me > >> pavel
when i or whoever visit homepage, the method from views.py generates some data, for example info about operating system or whatever, just some value stored in variable or dict, let's call it info = {'system': 'unix'}
later when user is browsing the site, he/she visits some other part of site when some other method is called. And i need to access this variable. So does it mean that in every method where i need to work with this variable i have to save it to sessions in first method and use request.session in method where i need to work with this variable, or is there some better way how to pass this variable? Please feel free to show me some code examples. thank you pavel
Horst Gutmann wrote: > Why do you want to manipulate just a specific session that might not > even be an existing sesion anymore? And for what reason do you want to > give other views the same data as the last view that's been used? To > me this sounds just like using a normal session (as provided by > request.session) ...
> Could you perhaps tell a few more details about what you want to > achieve and for what reason? :-)
> -- Horst
> On Tue, Apr 15, 2008 at 2:19 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
>> hi Horst
>> the last_login is an example from documentation. My problems are, that >> when i save something to the session(as current date, or user agent) >> with some key, and then look to database from terminal, the key is >> different.
>> The second problem is, that i cannot find a way how to pass some data >> from one function to all other functions.
>> thank you >> pavel
>> Horst Gutmann wrote: >> > Sorry if I misunderstood your problem, why don't you simply store the >> > last_login somewhere in a userprofile? Since -- judging from the name >> > -- it should only be altered when the user really logs in, I don't see >> > the relation with a session there :-/
>> > -- Horst
>> > On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
>> >> hi all
>> >> please , i would like to ask for a little help. I have few functions >> >> stored in my views.py under class Test. When i visit my homepage the >> >> urls.py is calling method homepage from views.py as i mentioned before. >> >> Here it dig some data as current server time and user agent from >> >> webbrowser. Now i need to pass these two details to any other function >> >> when the function is called. I read all docs about session, cache and >> >> others, but still did not found an answer. >> >> I also tried to store these details to session with
>> >> and later call it. It saved it but with different session_key. >> >> So back to the first problem. Please how can i pass some data from one >> >> method to all methods.
>> >> thank you very much for helping me >> >> pavel
Well, depending on how you handle this "variable" you have multiple options:
1. Store it into the session using request.session['info'] = info and retrieve it later from the session when you want to use this data. 2. If you also want to keep this "choice" permanently associated with the user, I'd store it in the user's profile
IMO these are the only options you have and they are not really bad ones. Naturally you could also simply pass that choice using GET parameters, but again: This depends on how you want to use this value.
On Tue, Apr 15, 2008 at 3:09 PM, hkm...@gmail.com <hkm...@gmail.com> wrote: > ok i will try to explain.
> when i or whoever visit homepage, the method from views.py generates > some data, for example > info about operating system or whatever, just some value stored in > variable or dict, let's call it > info = {'system': 'unix'}
> later when user is browsing the site, he/she visits some other part of > site when some other method is called. And i need to access this variable. > So does it mean that in every method where i need to work with this > variable i have to save it to sessions in first method and use > request.session in method where i need to work with this variable, or is > there some better way how to pass this variable? > Please feel free to show me some code examples.
> thank you > pavel
> Horst Gutmann wrote: > > Why do you want to manipulate just a specific session that might not > > even be an existing sesion anymore? And for what reason do you want to > > give other views the same data as the last view that's been used? To > > me this sounds just like using a normal session (as provided by > > request.session) ...
> > Could you perhaps tell a few more details about what you want to > > achieve and for what reason? :-)
> > -- Horst
> > On Tue, Apr 15, 2008 at 2:19 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
> >> hi Horst
> >> the last_login is an example from documentation. My problems are, that > >> when i save something to the session(as current date, or user agent) > >> with some key, and then look to database from terminal, the key is > >> different.
> >> The second problem is, that i cannot find a way how to pass some data > >> from one function to all other functions.
> >> thank you > >> pavel
> >> Horst Gutmann wrote: > >> > Sorry if I misunderstood your problem, why don't you simply store the > >> > last_login somewhere in a userprofile? Since -- judging from the name > >> > -- it should only be altered when the user really logs in, I don't see > >> > the relation with a session there :-/
> >> > -- Horst
> >> > On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
> >> >> hi all
> >> >> please , i would like to ask for a little help. I have few functions > >> >> stored in my views.py under class Test. When i visit my homepage the > >> >> urls.py is calling method homepage from views.py as i mentioned before. > >> >> Here it dig some data as current server time and user agent from > >> >> webbrowser. Now i need to pass these two details to any other function > >> >> when the function is called. I read all docs about session, cache and > >> >> others, but still did not found an answer. > >> >> I also tried to store these details to session with
> >> >> and later call it. It saved it but with different session_key. > >> >> So back to the first problem. Please how can i pass some data from one > >> >> method to all methods.
> >> >> thank you very much for helping me > >> >> pavel
but what about if i need in my every method the current url path current_path = request.path
or this index_globals
is there a way i can make this variable global(the current_path will change every time when some method in views.py will be called), and it will be automaticaly assign to locals() in every method. just like
current_path = request.path Class Test:
i hope i describe it well, so you will undestand thank you very much again pavel
Horst Gutmann wrote: > Well, depending on how you handle this "variable" you have multiple options:
> 1. Store it into the session using request.session['info'] = info and > retrieve it later from the session when you want to use this data. > 2. If you also want to keep this "choice" permanently associated with > the user, I'd store it in the user's profile
> IMO these are the only options you have and they are not really bad > ones. Naturally you could also simply pass that choice using GET > parameters, but again: This depends on how you want to use this value.
> -- Horst
> On Tue, Apr 15, 2008 at 3:09 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
>> ok i will try to explain.
>> when i or whoever visit homepage, the method from views.py generates >> some data, for example >> info about operating system or whatever, just some value stored in >> variable or dict, let's call it >> info = {'system': 'unix'}
>> later when user is browsing the site, he/she visits some other part of >> site when some other method is called. And i need to access this variable. >> So does it mean that in every method where i need to work with this >> variable i have to save it to sessions in first method and use >> request.session in method where i need to work with this variable, or is >> there some better way how to pass this variable? >> Please feel free to show me some code examples.
>> thank you >> pavel
>> Horst Gutmann wrote: >> > Why do you want to manipulate just a specific session that might not >> > even be an existing sesion anymore? And for what reason do you want to >> > give other views the same data as the last view that's been used? To >> > me this sounds just like using a normal session (as provided by >> > request.session) ...
>> > Could you perhaps tell a few more details about what you want to >> > achieve and for what reason? :-)
>> > -- Horst
>> > On Tue, Apr 15, 2008 at 2:19 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
>> >> hi Horst
>> >> the last_login is an example from documentation. My problems are, that >> >> when i save something to the session(as current date, or user agent) >> >> with some key, and then look to database from terminal, the key is >> >> different.
>> >> The second problem is, that i cannot find a way how to pass some data >> >> from one function to all other functions.
>> >> thank you >> >> pavel
>> >> Horst Gutmann wrote: >> >> > Sorry if I misunderstood your problem, why don't you simply store the >> >> > last_login somewhere in a userprofile? Since -- judging from the name >> >> > -- it should only be altered when the user really logs in, I don't see >> >> > the relation with a session there :-/
>> >> > -- Horst
>> >> > On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
>> >> >> hi all
>> >> >> please , i would like to ask for a little help. I have few functions >> >> >> stored in my views.py under class Test. When i visit my homepage the >> >> >> urls.py is calling method homepage from views.py as i mentioned before. >> >> >> Here it dig some data as current server time and user agent from >> >> >> webbrowser. Now i need to pass these two details to any other function >> >> >> when the function is called. I read all docs about session, cache and >> >> >> others, but still did not found an answer. >> >> >> I also tried to store these details to session with
>> >> >> and later call it. It saved it but with different session_key. >> >> >> So back to the first problem. Please how can i pass some data from one >> >> >> method to all methods.
>> >> >> thank you very much for helping me >> >> >> pavel
Well, you could minimize the amount of code you will have to repeat for each and every view function by doing some OOP. For instance you could probably do something like this in your views.py:
class AbstractView(object): def __init__(self, request, *args, **kwargs): # Do some generic stuff here pass def __call__(self, *args, **kwargs): raise RuntimeError, "Not implemented"
class TestView(AbstractView): def __call__(self, *args, **kwargs): return render_to_response('some_template.html',{})
This module provides the view "test". In this case, you'd put the whole generic stuff you want _all_ your views to perform into the __init__ method of the AbstractView class. This is just a quick solution, but it should give you an idea of how to share processing between views if the short processing requires request-specific data.
I hope this helps (and isn't a really stupid solution for your problem ;-) )
> but what about if i need in my every method the current url path > current_path = request.path
> or this index_globals
> is there a way i can make this variable global(the current_path will > change every time when some method in views.py will be called), and it > will be automaticaly assign to locals() in every method. > just like
> current_path = request.path > Class Test:
> i hope i describe it well, so you will undestand > thank you very much again > pavel
> Horst Gutmann wrote: > > Well, depending on how you handle this "variable" you have multiple options:
> > 1. Store it into the session using request.session['info'] = info and > > retrieve it later from the session when you want to use this data. > > 2. If you also want to keep this "choice" permanently associated with > > the user, I'd store it in the user's profile
> > IMO these are the only options you have and they are not really bad > > ones. Naturally you could also simply pass that choice using GET > > parameters, but again: This depends on how you want to use this value.
> > -- Horst
> > On Tue, Apr 15, 2008 at 3:09 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
> >> ok i will try to explain.
> >> when i or whoever visit homepage, the method from views.py generates > >> some data, for example > >> info about operating system or whatever, just some value stored in > >> variable or dict, let's call it > >> info = {'system': 'unix'}
> >> later when user is browsing the site, he/she visits some other part of > >> site when some other method is called. And i need to access this variable. > >> So does it mean that in every method where i need to work with this > >> variable i have to save it to sessions in first method and use > >> request.session in method where i need to work with this variable, or is > >> there some better way how to pass this variable? > >> Please feel free to show me some code examples.
> >> thank you > >> pavel
> >> Horst Gutmann wrote: > >> > Why do you want to manipulate just a specific session that might not > >> > even be an existing sesion anymore? And for what reason do you want to > >> > give other views the same data as the last view that's been used? To > >> > me this sounds just like using a normal session (as provided by > >> > request.session) ...
> >> > Could you perhaps tell a few more details about what you want to > >> > achieve and for what reason? :-)
> >> > -- Horst
> >> > On Tue, Apr 15, 2008 at 2:19 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
> >> >> hi Horst
> >> >> the last_login is an example from documentation. My problems are, that > >> >> when i save something to the session(as current date, or user agent) > >> >> with some key, and then look to database from terminal, the key is > >> >> different.
> >> >> The second problem is, that i cannot find a way how to pass some data > >> >> from one function to all other functions.
> >> >> thank you > >> >> pavel
> >> >> Horst Gutmann wrote: > >> >> > Sorry if I misunderstood your problem, why don't you simply store the > >> >> > last_login somewhere in a userprofile? Since -- judging from the name > >> >> > -- it should only be altered when the user really logs in, I don't see > >> >> > the relation with a session there :-/
> >> >> > -- Horst
> >> >> > On Tue, Apr 15, 2008 at 2:05 PM, hkm...@gmail.com <hkm...@gmail.com> wrote:
> >> >> >> hi all
> >> >> >> please , i would like to ask for a little help. I have few functions > >> >> >> stored in my views.py under class Test. When i visit my homepage the > >> >> >> urls.py is calling method homepage from views.py as i mentioned before. > >> >> >> Here it dig some data as current server time and user agent from > >> >> >> webbrowser. Now i need to pass these two details to any other function > >> >> >> when the function is called. I read all docs about session, cache and > >> >> >> others, but still did not found an answer. > >> >> >> I also tried to store these details to session with
> >> >> >> and later call it. It saved it but with different session_key. > >> >> >> So back to the first problem. Please how can i pass some data from one > >> >> >> method to all methods.
> >> >> >> thank you very much for helping me > >> >> >> pavel
please i have another question about some data. I have created a model for user profile in my app. Edited the settings, and it is working ok.
So when user logged in through this method i save this to variable and i am able to call it from this method. But what if i needed to call this from all methods in my class. Do i have to save this to session with a secret key(as for every visitor it should be unique), and pass the key in cookies all the time, and from every method parse the cookie, catch the secret key, and dig data with it from session.
please i would like know if there is a way how to get latest 0.95.3 to my debian etch system. as i have official stable src(i am only able to use stable) and only 0.95.1-1 version is available for me.
> please i would like know if there is a way how to get latest 0.95.3 to > my debian etch system. as i have official stable src(i am only able to > use stable) and only 0.95.1-1 version is available for me.
> please i would like know if there is a way how to get latest 0.95.3 to > my debian etch system. as i have official stable src(i am only able to > use stable) and only 0.95.1-1 version is available for me.
> thank you very much, pavel
There'll be a new package for the 1.0 beta in the next few days, that'll most likely go to the experimental distribution - unstable currently has 0.96.2, which could easily be backported to etch. Lenny, currently, also has the 0.96.2 package, and as lenny is now in freeze is likely to release with that.
Also, the version that is in debian etch has the patches from 0.95.2 and 0.95.3 merged in to the 0.95.1 package for etch (it being just security updates, debian policy dictates that we patch and keep the version number the same).
I'll be creating the 1.0 beta packages this evening, but can (if you want) create some etch 0.96.2 packages.
thanks for replay Nick. i know about tar source, but what i need is to have latest stable version installed via apt-get(without creating own deb file from tar) as the system on all machines is done this way to keep everything in order. I know the django developers are mostly updating svn version, but i expected that maintainer for this package will create update version in which the XSS bug is fixed.
anyway thanks again for answer and have a nice weekend pavel
>> please i would like know if there is a way how to get latest 0.95.3 to >> my debian etch system. as i have official stable src(i am only able to >> use stable) and only 0.95.1-1 version is available for me.
> thanks for replay Nick. i know about tar source, but what i need is to > have latest stable version installed via apt-get(without creating own > deb file from tar) as the system on all machines is done this way to > keep everything in order. I know the django developers are mostly > updating svn version, but i expected that maintainer for this package > will create update version in which the XSS bug is fixed.
great, thank you very much. now it is all clear for me. I had my debian package from past time. So now i know i should always check for Debian change log. Reinstalling the package will solve my problem.
thanks again, enjoy weekend pavel
On Fri, Aug 15, 2008 at 1:27 PM, Brett Parker <iDu...@sommitrealweird.co.uk>wrote:
> > thanks for replay Nick. i know about tar source, but what i need is to > > have latest stable version installed via apt-get(without creating own > > deb file from tar) as the system on all machines is done this way to > > keep everything in order. I know the django developers are mostly > > updating svn version, but i expected that maintainer for this package > > will create update version in which the XSS bug is fixed.