On Fri, Apr 9, 2010 at 4:17 AM, laser_cg <caum...@gmail.com> wrote:
> Hello everybody!
>
> I am working with sessions with the database backend in an e-commerce
> shop. I store the cart ID, the number of items in the cart and the
> total prize in the session. But actually have two problems.
>
> 1. I set the SESSION_EXPIRE_AT_BROWSER_CLOSE = True, but Django does
> not delete the session from the relation django_session when the
> browser is closed. Why is that? Is that normal?
>
> 2. How can I erase the shopping cart whose ID is in the session, when
> the session ends at browser close?
> I guess I should execute some code similar to the following, but I do
> not know where exactly:
>
> cart = Cart.objects.get(request.session[cart_id])  # This code is
> assuming that this is in a view
> cart.delete()
>
> Thank you so much. Replies will be wellcome.
>

1) Yes, the browser does not send a special signal to your website
saying the user has closed their browser. There is no way to detect
precisely when a user terminates their session.

2) If you want to erase carts from expired sessions, then you need to
periodically (every hour, 30 minutes) purge your sessions. This
(realistically) has to happen from outside of the webserver (google:
django celery), and should find session objects whose expiry time has
been reached, look inside the session for carts and remove the cart if
there, before finally deleting the session object.

Cheers

Tom

-- 
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.

Reply via email to