def testOtherTree(self): parent = self._createObject('root') child1 = self._createObject('child1').__of__(parent) grandchild = self._createObject('grandchild').__of__(child1) child2 = self._createObject('child2').__of__(parent) self.assertEqual(utils.RelativePath(child2, grandchild), '../child1/grandchild')
def update(self): utils.setLanguage(self.request, self.context) if self.request.environ["REQUEST_METHOD"] == "POST": reply = self.request.form if reply["action"] == "new": self._NewSurvey(reply) elif reply["action"] == "continue": self._ContinueSurvey(reply) else: survey = aq_inner(self.context) dbsession = SessionManager.session if dbsession is not None and \ dbsession.zodb_path == utils.RelativePath( self.request.client, survey): self.request.response.redirect("%s/resume?initial_view=1" % survey.absolute_url())
def sessions(self): """Return a list of all sessions for the current user. For each session a dictionary is returned with the following keys: * `id`: unique identifier for the session * `title`: session title * `modified`: timestamp of last session modification """ survey = aq_inner(self.context) my_path = utils.RelativePath(self.request.client, survey) account = getSecurityManager().getUser() result = [{ 'id': session.id, 'title': session.title, 'modified': session.modified } for session in account.sessions if session.zodb_path == my_path] result.sort(key=lambda s: s['modified'], reverse=True) return result
def hasValidSession(self, request): """Check if the user has an active session for the survey. """ dbsession = SessionManager.session client_path = utils.RelativePath(request.client, self.context) if dbsession is None or \ dbsession.zodb_path != client_path: # Allow for alternative session ids to be hardcoded in the # euphorie.ini file for automatic browser testing with Browsera conf = getUtility(IAppConfig).get("euphorie", {}) debug_ids = conf.get('debug_sessions', '').strip().splitlines() for sid in debug_ids: session = Session.query(model.SurveySession).get(sid) if hasattr(session, 'zodb_path') and \ session.zodb_path == client_path: SessionManager.resume(session) return True return False return True
def testDirectParent(self): parent = self._createObject('parent') child = self._createObject('child').__of__(parent) self.assertEqual(utils.RelativePath(parent, child), 'child')
def testSameItem(self): obj = self._createObject('dummy') self.assertEqual(utils.RelativePath(obj, obj), '')