Exemple #1
0
    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
Exemple #2
0
    def get_enrolment(user_id):

        session = DBSession()

        courses = session.query(
            models.Enrolment).filter(models.Enrolment.uid == user_id).all()
        session.close()
        return courses
Exemple #3
0
    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)
Exemple #4
0
    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()
Exemple #5
0
    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
Exemple #6
0
    def get_unnaproved_guests():

        session = DBSession()

        guests = session.query(
            models.Guest).filter(models.Guest.enrolled == 'False').all()

        session.close()

        return guests
Exemple #7
0
    def get_user(identifier):

        session = DBSession()

        user = session.query(
            models.User).filter(models.User.uid == identifier).first()

        session.close()

        return user
Exemple #8
0
    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
Exemple #9
0
    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()
Exemple #10
0
    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()
Exemple #11
0
    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
        ]
Exemple #12
0
    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()
Exemple #13
0
    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
Exemple #14
0
    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
Exemple #15
0
    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
Exemple #16
0
    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()
Exemple #17
0
    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
Exemple #18
0
    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
Exemple #19
0
    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
Exemple #20
0
    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()
Exemple #21
0
    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
Exemple #22
0
    def get_courses():

        session = DBSession()

        session.close()
        return session.query(models.Course).all()