Ejemplo n.º 1
0
class SessionPublisher(Publisher):

    def __init__(self, root_namespace, config=None, session_mgr=None):
        from quixote.session import SessionManager
        Publisher.__init__(self, root_namespace, config)
        if session_mgr is None:
            self.session_mgr = SessionManager()
        else:
            self.session_mgr = session_mgr

    def set_session_manager(self, session_mgr):
        self.session_mgr = session_mgr

    def start_request(self, request):
        # Get the session object and stick it onto the request
        request.session = self.session_mgr.get_session(request)
        request.session.start_request(request)

    def finish_successful_request(self, request):
        if request.session is not None:
            request.session.finish_request(request)
            self.session_mgr.maintain_session(request, request.session)
        self.session_mgr.commit_changes(request.session)

    def finish_interrupted_request(self, request, exc):
        output = Publisher.finish_interrupted_request(self, request, exc)

        # commit the current transaction so that any changes to the
        # session objects are saved and are visible on the next HTTP
        # hit.  Remember, AccessError is a subclass of PublishError,
        # so this code will be run for both typos in the URL and for
        # the user not being logged in.
        #
        # The assumption here is that the UI code won't make changes
        # to the core database before checking permissions and raising
        # a PublishError; if you must do this (though it's hard to see
        # why this would be necessary), you'll have to abort the
        # current transaction, make your session changes, and then
        # raise the PublishError.
        #
        # XXX We should really be able to commit session changes and
        # database changes separately, but that requires ZODB
        # incantations that we currently don't know.
        self.session_mgr.commit_changes(request.session)

        return output

    def finish_failed_request(self, request):
        if self.session_mgr:
            self.session_mgr.abort_changes(request.session)
        return Publisher.finish_failed_request(self, request)
Ejemplo n.º 2
0
class SessionPublisher(Publisher):
    def __init__(self, root_namespace, config=None, session_mgr=None):
        from quixote.session import SessionManager
        Publisher.__init__(self, root_namespace, config)
        if session_mgr is None:
            self.session_mgr = SessionManager()
        else:
            self.session_mgr = session_mgr

    def set_session_manager(self, session_mgr):
        self.session_mgr = session_mgr

    def start_request(self, request):
        # Get the session object and stick it onto the request
        request.session = self.session_mgr.get_session(request)
        request.session.start_request(request)

    def finish_successful_request(self, request):
        if request.session is not None:
            request.session.finish_request(request)
            self.session_mgr.maintain_session(request, request.session)
        self.session_mgr.commit_changes(request.session)

    def finish_interrupted_request(self, request, exc):
        output = Publisher.finish_interrupted_request(self, request, exc)

        # commit the current transaction so that any changes to the
        # session objects are saved and are visible on the next HTTP
        # hit.  Remember, AccessError is a subclass of PublishError,
        # so this code will be run for both typos in the URL and for
        # the user not being logged in.
        #
        # The assumption here is that the UI code won't make changes
        # to the core database before checking permissions and raising
        # a PublishError; if you must do this (though it's hard to see
        # why this would be necessary), you'll have to abort the
        # current transaction, make your session changes, and then
        # raise the PublishError.
        #
        # XXX We should really be able to commit session changes and
        # database changes separately, but that requires ZODB
        # incantations that we currently don't know.
        self.session_mgr.commit_changes(request.session)

        return output

    def finish_failed_request(self, request):
        if self.session_mgr:
            self.session_mgr.abort_changes(request.session)
        return Publisher.finish_failed_request(self, request)