Пример #1
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
Пример #2
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
Пример #3
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()
Пример #4
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()
Пример #5
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()
Пример #6
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
Пример #7
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