def quizUpdateOperation(id, name, is_fast, date_start, date_end):
    quiz = quizRead(id)

    # quiz is not found
    if quiz is None:
        raise ErrorWithCode(404, "No quiz found")

    if name is not None:
        quiz.name = name

    if is_fast is not None:
        quiz.is_fast = is_fast

    if (date_start is not None) and (date_end is not None):
        validate_dates(date_start, date_end)
        quiz.date_start = date_start
        quiz.date_end = date_end
    else:
        if (date_start is not None):
            validate_dates(date_start, quiz.date_end)
            quiz.date_start = date_start
        elif (date_end is not None):
            validate_dates(quiz.date_start, date_end)
            quiz.date_end = date_end

    if quizUpdate() == False:
        raise ErrorWithCode(400, "Unsuccessful")

    # success case
    return quiz
def quizMngCreateOperation(topic_id, lesson_id, quiz_id):

    # dependency not found
    topic = Topic.query.filter_by(id=topic_id).first()
    if topic is None:
        raise ErrorWithCode(409, "topic not found")

    # dependency not found
    lesson = Lesson.query.filter_by(topic_id=topic_id).filter_by(
        id=lesson_id).first()
    if lesson is None:
        raise ErrorWithCode(409, "lesson not found")

    # existing rs found
    rs = Rs_lesson_quiz_contain.query.filter_by(topic_id=topic_id).filter_by(
        lesson_id=lesson_id).filter_by(quiz_id=quiz_id).first()
    if rs is not None:
        raise ErrorWithCode(409, "existing relationship found")

    rs = initializeRsLessonQuizContain(topic_id, lesson_id, quiz_id)
    if rsLessonQuizContainCreate(rs) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return rs
示例#3
0
def user_update_operation(username, name, age, height, weight):

    user = userRead(col='username', value=username)

    # user is not found
    if user is None:
        raise ErrorWithCode(409, "No user found")

    if name is not None:
        user.name = name

    if age is not None:
        user.age = age

    if height is not None:
        user.height = height

    if weight is not None:
        user.weight = weight

    if userUpdate() == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return user
示例#4
0
def questionDeleteOperation(id):
    question = questionRead(id)

    # question is not found
    if question is None:
        raise ErrorWithCode(404, "No question found")

    if questionDelete(id) == False:
        raise ErrorWithCode(400, "Unsuccessful")

    # success case
    return True
def quizMngDeleteOperation(id):

    rs = Rs_lesson_quiz_contain.query.filter_by(id=id).first()

    if rs is None:
        raise ErrorWithCode(409, "No rs found")

    if rsLessonQuizContainDelete(id) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return True
def lessonDeleteOperation(topic_id, lesson_id):
    lesson = lessonRead(topic_id=topic_id, col='id', value=lesson_id)

    # lesson is not found
    if lesson is None:
        raise ErrorWithCode(409, "No lesson found")

    if lessonDelete(topic_id, lesson_id) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return True
示例#7
0
def auth_operation(username, password):

    user = userRead(col='username', value=username)

    # user is not found
    if user is None:
        raise ErrorWithCode(409, "No user found")

    # if password is wrong
    if not authenticate(password, user.encrypted_password):
        raise ErrorWithCode(401, "Unauthorised - Incorrect password")

    return True
示例#8
0
def questionUpdateOperation(id, description):
    question = questionRead(id)

    # question is not found
    if question is None:
        raise ErrorWithCode(404, "No question found")

    question.description = description
    if questionUpdate() == False:
        raise ErrorWithCode(400, "Unsuccessful")

    # success case
    return question
示例#9
0
def questionCreateOperation(topic_id, lesson_id, description):
    lesson = lessonRead(topic_id=topic_id, col='id', value=lesson_id)

    # topic and lesson not found
    if lesson is None:
        raise ErrorWithCode(404, "No topic/lesson found")

    question = initializeQuestion(topic_id, lesson_id, description)
    if questionCreate(question) == False:
        raise ErrorWithCode(400, "Unsuccessful")

    # success case
    return question
def staffCreateOperation(email, password, name):
    staff = staffRead(col='email', value=email)

    # if staff exist found
    if staff:
        raise ErrorWithCode(409, "Existing staff")

    staff = initializeStaff(email, password, name)
    if staffCreate(staff) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return staff
示例#11
0
def userCreateOperation(email, password):
    user = userRead(col='email', value=email)

    # if user exist found
    if user:
        raise ErrorWithCode(409, "Existing user")

    user = initializeUser(email, password)
    if userCreate(user) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return user
def topicCreateOperation(name):
    topic = topicRead(col='name', value=name)

    # if topic exist found
    if topic:
        raise ErrorWithCode(409, "Existing topic")

    topic = initializeTopic(name)
    if topicCreate(topic) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return topic
示例#13
0
def courseCreateOperation(index):
    course = courseRead(index)

    # if course exist found
    if course:
        raise ErrorWithCode(409, "Existing course")

    course = initializeCourse(index)
    if courseCreate(course) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return course
def studentCreateOperation(email, password, matriculation_number, name):
    student = studentRead(col='email', value=email)

    # if student exist found
    if student:
        raise ErrorWithCode(409, "Existing student")

    student = initializeStudent(email, password, matriculation_number, name)
    if studentCreate(student) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return student
示例#15
0
def user_create_operation(username, plaintext_password, name):

    user = userRead(col='username', value=username)

    # user existing
    if user is not None:
        raise ErrorWithCode(409, "Existing user found")

    user = initialize_user(username, plaintext_password, name)
    if userCreate(user) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return user
示例#16
0
def authOperation(email, password):

    user = userRead(col='email', value=email)

    # user is not found
    if user is None:
        raise ErrorWithCode(409, "No user found")

    # if password is wrong
    if authenticate(password, user.encrypted_password) is False:
        raise ErrorWithCode(401, "Unauthorised - wrong password")

    # success case
    return user
def topicUpdateOperation(id, name):
    topic = topicRead(col='id', value=id)

    # if topic not found
    if topic is None:
        raise ErrorWithCode(409, "No topic found")

    topic.name = name

    if topicUpdate() is False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return topic
def quizCreateOperation(staff_id, name, is_fast, date_start, date_end):
    staff = staffRead(col='id', value=staff_id)

    # staff not found
    if staff is None:
        raise ErrorWithCode(404, "No staff found")

    validate_dates(date_start, date_end)

    quiz = initializeQuiz(staff_id, name, is_fast, date_start, date_end)
    if quizCreate(quiz) == False:
        raise ErrorWithCode(400, "Unsuccessful")

    # success case
    return quiz
def lessonCreateOperation(topic_id, name, content, url_link):
    lesson = lessonRead(topic_id=topic_id, col='name', value=name)

    # if lesson exist found
    if lesson:
        raise ErrorWithCode(409, "Existing lesson")

    lesson = initializeLesson(topic_id=topic_id,
                              name=name,
                              content=content,
                              url_link=url_link)
    if lessonCreate(lesson) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return lesson
示例#20
0
def userUpdateOperation(email, old_password, new_password):
    user = userRead(col='email', value=email)

    # user is not found
    if user is None:
        raise ErrorWithCode(409, "No user found")

    # password authentication fail
    if authenticate(old_password, user.encrypted_password) == False:
        raise ErrorWithCode(401, "Wrong password does not match")

    user.encrypted_password = encrypt(new_password)
    if userUpdate() == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return user
示例#21
0
def user_update_password_operation(username, current_password, new_password):

    user = userRead(col='username', value=username)

    # user is not found
    if user is None:
        raise ErrorWithCode(409, "No user found")

    # incorrect password provided
    if authenticate(current_password, user.encrypted_password) is False:
        raise ErrorWithCode(401, "Wrong password provided")

    user.encrypted_password = encrypt(new_password)
    if userUpdate() == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return user
def lessonReadOperation(topic_id, lesson_id):
    lesson = lessonRead(topic_id=topic_id, col='id', value=lesson_id)

    # lesson is not found
    if lesson is None:
        raise ErrorWithCode(409, "No lesson found")

    # success case
    return lesson
示例#23
0
def challengeUpdateCompletedOperation(from_student_id, to_student_id, quiz_id,
                                      winner_id):

    challenges = challengeRead(from_student_id, to_student_id, quiz_id, None)

    # challenge is not found
    if len(challenges) == 0:
        raise ErrorWithCode(409, "No challenge found")

    challenge = challenges[0]

    challenge.is_completed = True
    challenge.winner_id = winner_id
    if challengeUpdate() == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return challenge
示例#24
0
def userReadOperation(email):
    user = userRead(col='email', value=email)

    # user is not found
    if user is None:
        raise ErrorWithCode(409, "No user found")

    # success case
    return user
def courseMngReadOperation(user_email):
    student = studentRead(col='email', value=user_email)

    # student is not found
    if student is None:
        raise ErrorWithCode(409, "No student found")

    # success case
    return student
示例#26
0
def questionReadOperation(id):
    question = questionRead(id)

    # question is not found
    if question is None:
        raise ErrorWithCode(404, "No question found")

    # success case
    return question
示例#27
0
def courseReadOperation(index):
    course = courseRead(index)

    # course is not found
    if course is None:
        raise ErrorWithCode(409, "No course found")

    # success case
    return course
def topicDeleteOperation(id):

    topic = topicRead(col='id', value=id)

    # if topic not found
    if topic is None:
        raise ErrorWithCode(409, "No topic found")

    lessons = lessonListRead()
    for lesson in lessons:
        if lesson.topic_id == id:
            raise ErrorWithCode(409, "Topic has lessons assigned to it")

    if topicDelete(id) == False:
        raise ErrorWithCode(503, "Unsuccessful")

    # success case
    return True
def staffReadOperation(email):
    staff = staffRead(col='email', value=email)

    # staff is not found
    if staff is None:
        raise ErrorWithCode(409, "No staff found")

    # success case
    return staff
def topicReadOperation(id):
    topic = topicRead(col='id', value=id)

    # topic is not found
    if topic is None:
        raise ErrorWithCode(409, "No topic found")

    # success case
    return topic