Exemplo n.º 1
0
    def write_user(
        user_rep
    ):  # user_rep = [identifier, password, role] guest has an extra field for enrolment application

        session = DBSession()
        if user_rep[2] != 'guest':
            new_user = models.User(uid=user_rep[0],
                                   password=user_rep[1],
                                   role=user_rep[2])
        else:
            new_user = models.Guest(uid=user_rep[0],
                                    password=user_rep[1],
                                    role=user_rep[2],
                                    enrolled='False')
            enrolment = user_rep[3].split(' ')
            EnrolmentController.write_enrolment(
                [enrolment[0], enrolment[1], user_rep[0]])
        session.add(new_user)
        success = True
        try:
            session.commit()
        except:
            success = False
        session.close()
        return success
Exemplo n.º 2
0
    def write_survey(course_name, course_session, starttime, endtime,
                     questions):

        session = DBSession()
        state = 'created'
        if starttime < datetime.now():
            state = 'review'
        if endtime < datetime.now():
            state = 'deactivate'
        new_survey = models.Survey(course_name=course_name,
                                   course_session=course_session,
                                   starttime=starttime,
                                   endtime=endtime,
                                   state=state)
        session.add(new_survey)
        for qid in questions:
            new_question = models.SurveyQStore(course_name=course_name,
                                               course_session=course_session,
                                               qid=qid)
            session.add(new_question)
        try:
            session.commit()
        except:
            return False
        session.close()
        return True
Exemplo n.º 3
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()
Exemplo n.º 4
0
    def write_course(course_rep):  # course_rep = [name, session]

        session = DBSession()
        new_course = models.Course(name=course_rep[0], session=course_rep[1])
        session.add(new_course)
        try:
            session.commit()
        except:
            pass
        session.close()
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
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()
Exemplo n.º 8
0
    def survey_add_questions(course, questions):

        session = DBSession()

        course_list = course.split(" ")
        for qid in questions:
            new_question = models.SurveyQStore(course_name=course_list[0],
                                               course_session=course_list[1],
                                               qid=qid)
            session.add(new_question)

        session.commit()
        session.close()
Exemplo n.º 9
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
Exemplo n.º 10
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()
Exemplo n.º 11
0
    def write_enrolment(
        enrolment_rep
    ):  # enrolment_rep = [course_name, course_session, user_id]

        session = DBSession()

        new_enrolment = models.Enrolment(course_name=enrolment_rep[0],
                                         course_session=enrolment_rep[1],
                                         uid=enrolment_rep[2],
                                         completed='False')
        session.add(new_enrolment)
        try:
            session.commit()
        except:
            pass
        session.close()
Exemplo n.º 12
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()
Exemplo n.º 13
0
    def write_response(course_name, course_session, qid, response):

        session = DBSession()

        response = models.Responses(course_name=course_name,
                                    course_session=course_session,
                                    qid=qid,
                                    response=response)

        session.add(response)
        try:
            session.commit()
        except:
            session.close()
            return False
        session.close()
        return True
Exemplo n.º 14
0
    def write_question(
        question_rep
    ):  # question_rep = [question_text, [answers], is_optional]

        session = DBSession()
        new_question = models.Question(question=question_rep[0],
                                       ans="|".join(question_rep[1]),
                                       deleted='False',
                                       is_optional=question_rep[2])
        session.add(new_question)
        try:
            session.commit()
        except:
            print('error: Question alread exists!')
            return False
        session.close()
        return True