def get_all_questions(mandatory_only): session = DBSession() if mandatory_only == 'True': questions = session.query(models.Question).filter( models.Question.is_optional == 'False').all() else: questions = session.query(models.Question).all() question_list = [] for question in questions: question_list.append([ question.id, question.question, QuestionController.reformat_ans(question.ans), question.deleted, question.is_optional ]) session.close() return question_list
def get_enrolment(user_id): session = DBSession() courses = session.query( models.Enrolment).filter(models.Enrolment.uid == user_id).all() session.close() return courses
def get_respondents(course_name, course_session): session = DBSession() respondents = session.query(models.Enrolment).filter( models.Enrolment.course_name == course_name).filter( models.Enrolment.course_session == course_session).all() # remove rows which are staff checked from the user table session.close() return len(respondents)
def delete_question(question_id): session = DBSession() question = session.query( models.Question).filter(models.Question.id == question_id).first() question.deleted = 'True' session.commit() session.close()
def get_responses(course_name, course_session): session = DBSession() responses = session.query(models.Responses).filter( models.Responses.course_name == course_name).filter( models.Responses.course_session == course_session).all() session.close() return responses
def get_unnaproved_guests(): session = DBSession() guests = session.query( models.Guest).filter(models.Guest.enrolled == 'False').all() session.close() return guests
def get_user(identifier): session = DBSession() user = session.query( models.User).filter(models.User.uid == identifier).first() session.close() return user
def get_all_surveys(): session = DBSession() surveys = session.query(models.Survey).all() session.close() for survey in surveys: SurveyController.set_deactivate_after_end(survey) SurveyController.set_review_after_start(survey) return surveys
def approve_enrolment(user_id): session = DBSession() user = session.query( models.Guest).filter(models.Guest.uid == user_id).first() user.enrolled = "True" session.commit() session.close()
def set_survey_active(course_name, course_session): session = DBSession() survey = session.query(models.Survey).filter( models.Survey.course_name == course_name).filter( models.Survey.course_session == course_session).first() survey.state = 'active' session.commit() session.close()
def get_question(id): # [id, question, answers, deleted] session = DBSession() question = session.query( models.Question).filter(models.Question.id == id).first() session.close() return [ question.id, question.question, QuestionController.reformat_ans(question.ans), question.deleted ]
def set_survey_completed(course_name, course_session, user_id): session = DBSession() enrolment = session.query( models.Enrolment).filter(models.Enrolment.uid == user_id).filter( models.Enrolment.course_name == course_name).filter( models.Enrolment.course_session == course_session).first() enrolment.completed = 'True' session.commit() session.close()
def num_answers(course_name: str, course_session: str, qid: int, answer: int): print(course_name, course_session, qid, answer) session = DBSession() responses = session.query(models.Responses.id).filter( models.Responses.course_name == course_name).filter( models.Responses.course_session == course_session).filter( models.Responses.qid == qid).filter( models.Responses.response == str(answer)).all() n = len(responses) session.close() return n
def close_survey(course_name, course_session): session = DBSession() survey = session.query(models.Survey).filter( models.Survey.course_name == course_name).filter( models.Survey.course_session == course_session).first() if survey.endtime < datetime.now(): survey.state = 'closed' session.commit() session.close
def check_guest_approved(identifier): session = DBSession() guest = session.query( models.Guest).filter(models.Guest.uid == identifier).first() if guest == None: return True if guest.enrolled == 'False': session.close() return False else: session.close() return True
def set_review_after_start(survey): if survey.starttime < datetime.now(): session = DBSession() sur = session.query(models.Survey).filter( models.Survey.course_name == survey.course_name).filter( models.Survey.course_session == survey.course_session).first() if sur.state == 'created': sur.state = 'review' session.commit() session.close()
def get_survey_questions(course_name, course_session): session = DBSession() q_stores = session.query(models.SurveyQStore).filter( models.SurveyQStore.course_name == course_name).filter( models.SurveyQStore.course_session == course_session).all() questions = [] for q in q_stores: questions.append(QuestionController.get_question(q.qid)) session.close() return questions
def check_password(user_name, password): session = DBSession() user = session.query( models.User).filter(models.User.uid == user_name).first() session.close() try: if user.password == password: return True else: return False except AttributeError: return False
def get_survey(course_name, course_session): session = DBSession() survey = session.query(models.Survey).filter( models.Survey.course_name == course_name).filter( models.Survey.course_session == course_session).first() session.close() try: SurveyController.set_deactivate_after_end(survey) SurveyController.set_review_after_start(survey) except AttributeError: print("no survey for {} {}".format(course_name, course_session)) return survey
def set_deactivate_after_end(survey): if survey.endtime < datetime.now(): session = DBSession() sur = session.query(models.Survey).filter( models.Survey.course_name == survey.course_name).filter( models.Survey.course_session == survey.course_session).first() if sur.state == 'created' or sur.state == 'review': sur.state = 'deactivate' elif sur.state == 'active': sur.state = 'adeactivate' session.commit() session.close()
def get_optional_questions(): session = DBSession() questions = session.query(models.Question).filter( models.Question.is_optional == 'True').all() question_list = [] for question in questions: question_list.append([ question.id, question.question, QuestionController.reformat_ans(question.ans), question.deleted ]) session.close() return question_list
def get_courses(): session = DBSession() session.close() return session.query(models.Course).all()