tags:

views:

203

answers:

2

Quick question. In my syndication feed framework code,

http://docs.djangoproject.com/en/dev/ref/contrib/syndication/

what is the best way to get access to the session? I don't have access to the request, and I can't use

from django.contrib.sessions.backends.db import SessionStore

as I don't know the session ID, but I need to access some of the variables in the session.

i.e. I have:

from django.contrib.syndication.feeds import Feed
class LatestPhotos(Feed):
    ...

and in that LatestPhotos class, I need to access something in the session to help control the logic flow. I can't find any documentation on the best way to do it.

Thanks

Thanks!

+2  A: 

It seems like a design flaw to be trying to access session data in the LatestPhoto's class. I would assume that if your syndication feed depended on a session variable, then the items you're syndicating (LatestPhotos) should be constructed with that variable?

Can you make the logic flow decision before you construct the LatestPhotos object, or at the very least pass the session ID in to the LatestPhotos init routine?

John Weldon
+1: Syndication is session-less. It's an announcement of site changes handed out to anyone who does a GET on /feeds/. There is neither session nor user.
S.Lott
The problem is, you have to provide a dict of url => Feed class mappings in your urls.py URL patterns definition. So I have no access whatsoever to the session at any point (or at least the request) so I can tell which "site" the request is for. This is defined at boot time, not at all during the request. Thoughts on how to do it given those constraints? Thanks!
sleach
Looks like someone else wants similar functionality:http://code.djangoproject.com/ticket/2912
sleach
A: 

Figured it out - drrr, so simple. The syndication framework Feed class has a member called request...so simple I never thought of it :)

sleach