def store_user_id(self, user_id): """ Store a user's id for retrieval later :param user_id: the user id """ if EQ_SESSION_ID not in session: eq_session_id = str(uuid4()) logger.debug("creating new eq session id", session_id=eq_session_id) session[EQ_SESSION_ID] = eq_session_id eq_session = EQSession(eq_session_id, user_id) else: eq_session_id = session[EQ_SESSION_ID] logger.debug("got session id from session", session_id=eq_session_id) eq_session = self._get_user_session(eq_session_id) if eq_session is not None: logger.debug("got session from database", eq_session_id=eq_session.eq_session_id, user_id=eq_session.user_id, timestamp=eq_session.timestamp.isoformat()) with commit_or_rollback(db_session): # pylint: disable=maybe-no-member # session has a add function but it is wrapped in a session_scope which confuses pylint db_session.add(eq_session)
def add_or_update(self, data): if self.exists(): logger.debug("updating questionnaire data", user_id=self.user_id) questionnaire_state = self._get() questionnaire_state.set_data(data) else: logger.debug("creating questionnaire data", user_id=self.user_id) questionnaire_state = QuestionnaireState(self.user_id, data) with commit_or_rollback(db_session): # pylint: disable=maybe-no-member # session has a add function but it is wrapped in a session_scope which confuses pylint db_session.add(questionnaire_state)
def store(self, data, user_id, user_ik=None): logger.debug("About to store data %s for user %s", data, user_id) if self.has_data(user_id): logger.debug("Loading previous data for user %s", user_id) questionnaire_state = self._get_object(user_id) logger.debug("Loaded %s", questionnaire_state) questionnaire_state.set_data(data) else: logger.debug("Creating questionnaire state for user %s with data %s", user_id, data) questionnaire_state = QuestionnaireState(user_id, data) logger.debug("Committing questionnaire state") db_session.add(questionnaire_state) db_session.commit() logger.debug("Committed")
def store_user_id(self, user_id): logger.debug("DatabaseSessionManager store_user_id() - session %s", session) if EQ_SESSION_ID not in session: eq_session_id = self.create_session_id() logger.debug("Created new eq session id %s", eq_session_id) session[EQ_SESSION_ID] = eq_session_id eq_session = EQSession(eq_session_id, user_id) logger.debug("Constructed EQ Session object %s", eq_session) else: eq_session_id = session[EQ_SESSION_ID] logger.debug("Found eq_session_id %s in session", eq_session_id) eq_session = self._get_object(eq_session_id) logger.debug("Loaded object eq session %s", eq_session) logger.debug("About to commit to database") db_session.add(eq_session) db_session.commit() logger.debug("Committed")
def store_user_id(self, user_id): """ Store a user's id for retrieval later :param user_id: the user id """ logger.debug("SessionManager store_user_id() - session %s", session) if EQ_SESSION_ID not in session: eq_session_id = str(uuid4()) logger.debug("Created new eq session id %s", eq_session_id) session[EQ_SESSION_ID] = eq_session_id eq_session = EQSession(eq_session_id, user_id) logger.debug("Constructed EQ Session object %s", eq_session) else: eq_session_id = session[EQ_SESSION_ID] logger.debug("Found eq_session_id %s in session", eq_session_id) eq_session = self._get_user_session(eq_session_id) logger.debug("Loaded object eq session %s", eq_session) logger.debug("About to commit to database") with commit_or_rollback(db_session): # pylint: disable=maybe-no-member # session has a add function but it is wrapped in a session_scope which confuses pylint db_session.add(eq_session)