Re: What causes request.session to be erased?...When you go to different view?

2010-07-10 Thread Chris Seberino
Wow beautiful.  Thanks.  I needed that.

cs

On Jul 10, 12:14 am, Javier Guerra Giraldez 
wrote:
> On Fri, Jul 9, 2010 at 11:36 PM, Chris Seberino  wrote:
> > elif form.is_valid():
> >        ...
> >        request.session["posts"].append(form.cleaned_data)
> >        
>
> > I noticed that everytime I revisit this form and rerun this view, the
> > request.session["posts"] lists gets blown away and is empty again!?!?
>
> > Am I misunderstanding something about requests and sessions?
>
> from the docs 
> (http://docs.djangoproject.com/en/1.2/topics/http/sessions/#when-sessi...
>
>   # Gotcha: Session is NOT modified, because this alters
>   # request.session['foo'] instead of request.session.
>   request.session['foo']['bar'] = 'baz'
>   In the last case of the above example, we can tell the session
> object explicitly that it has been modified by setting the modified
> attribute on the session object:
>
>   request.session.modified = True
>
> that's exactly your case.  the session object is saved automatically
> only when it's marked as modified.  but when you modify an object
> inside the session and not the session itself; it doesn't gets
> notified of the change, so you have to tell it explicitly.
>
> --
> Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: What causes request.session to be erased?...When you go to different view?

2010-07-09 Thread Javier Guerra Giraldez
On Fri, Jul 9, 2010 at 11:36 PM, Chris Seberino  wrote:
> elif form.is_valid():
>        ...
>        request.session["posts"].append(form.cleaned_data)
>        
>
> I noticed that everytime I revisit this form and rerun this view, the
> request.session["posts"] lists gets blown away and is empty again!?!?
>
>
> Am I misunderstanding something about requests and sessions?


from the docs 
(http://docs.djangoproject.com/en/1.2/topics/http/sessions/#when-sessions-are-saved):

  # Gotcha: Session is NOT modified, because this alters
  # request.session['foo'] instead of request.session.
  request.session['foo']['bar'] = 'baz'
  In the last case of the above example, we can tell the session
object explicitly that it has been modified by setting the modified
attribute on the session object:

  request.session.modified = True


that's exactly your case.  the session object is saved automatically
only when it's marked as modified.  but when you modify an object
inside the session and not the session itself; it doesn't gets
notified of the change, so you have to tell it explicitly.



-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



What causes request.session to be erased?...When you go to different view?

2010-07-09 Thread Chris Seberino
Ever time a web page is visited, a view is called and a NEW request
object is passed in right?

Then if I'm not mistaken, it appears you can't maintain
request.session when you visit a new web page and a new view because a
NEW request object is passed in to the new view right?



My personal code visits a certain form multiple times to create new
"posts".  I was trying to collect them in a list I store in the
session as follows

...
elif form.is_valid():
...
request.session["posts"].append(form.cleaned_data)


I noticed that everytime I revisit this form and rerun this view, the
request.session["posts"] lists gets blown away and is empty again!?!?


Am I misunderstanding something about requests and sessions?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.