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.
thank you very much for helping me
pavel
-- 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
Could you perhaps tell a few more details about what you want to
achieve and for what reason? :-)
-- Horst
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.
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
now it is working, but still have some question please.
for instance in my views.py i have:
index_globals={}
Class Test:
init and some more data ....
def homepage(request):
some code with variables ....
index_globals['info'] = user_system
index_globals['timestamp'] = today
request.session['index_globals'] = index_globals
so now when i need some data from index_globals in every method i have
to call with
user_start_time = request.session['index_globals']['timestamp']
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
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',{})
def create_view(klass):
def _func(request, *args, **kwargs):
return klass(request, *args, **kwargs)()
return _func
test = create_view(TestView)
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 ;-) )
-- Horst
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.
i believe there is some nicer way, isn't it?
thank you very much
pavel
please i am unable to find how to obtain sesssion key after i create the
session.
from
http://www.djangoproject.com/documentation/sessions/#using-sessions-out-of-views
i save some data
from django.contrib.sessions.backends.db import SessionStore
s = SessionStore(session_key='')
s['name'] = 'pavel'
s.save()
so it creates new row in django_session table, but how will i obtain now
the session key to retrive the session data?
thank you very much for advice
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.
thank you very much, pavel
http://www.djangoproject.com/download/
And if you only want to use 0.95.3
http://www.djangoproject.com/download/0.95.3/tarball/
get this tarball
hkm...@gmail.com schrieb:
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,
--
Brett Parker
anyway thanks again for answer and have a nice weekend
pavel
In the debian stable archive you should find python-django-0.95.1-1etch1
(see: http://packages.debian.org/etch/python-django), if you look at the
changelog for that
(http://packages.debian.org/changelogs/pool/main/p/python-django/python-django_0.95.1-1etch1/changelog)
you'll see that the xss bug is patched in that version.
Thanks,
--
Brett Parker