durusmail: quixote-users: returning fresh instance of the main published class on every request
returning fresh instance of the main published class on every request
returning fresh instance of the main published class on every request
Ksenia Marasanova
2005-09-27
Hi,

I am sorry to say that this is Qx1 question, but maybe somebody can advise....

Would it be possible, in SCGI environment, somehow to return fresh
instance of the main published class, every time the base url / is
requested? The problem is that I have this class:

class Tree:
    _q_exports = []
    def __init__(self, page_id=None):
        if page_id is None:
            page_id = getHomepage()
        self.page_id = page_id

    def _q_index(self, request):
        return "I am page %d" % self.page_id

    def _q_lookup(self, request, name):
        return Tree(name)

that SCGI application uses as a main class mounted to "/".

My understanding is that when "/mypage/" is requested, _q_lookup is
called, the Tree instance is created that is unique for that
particular request. But the main Tree instance is initialized only
once, when application is started, so requesting "/" returns the same
tree instance for *all* requests (inside one SCGI process).
The problem here is that one application will serve multiple sites,
and homepage is different for all of them, depending on hostname and
such. I'd prefer not to redirect people to "/homepage/", which will
solve it, I guess. Another workaround is to reset all variables of the
main tree in every published method, but I was hoping maybe there is a
better solution.

Thanks,
--
Ksenia
reply