Beispiel #1
0
def index_course_questions(course):
    course = model.Course.getBy(db.session, code=course.upper())
    indexed_questions = course.index_questions()
    db.session.add_all(indexed_questions)
    db.session.commit()
    invalidate_view("course.get_popular", course=course.code)
    return success()
Beispiel #2
0
def index_course_questions(course):
    course = model.Course.getBy(db.session, code=course.upper())
    indexed_questions = course.index_questions()
    db.session.add_all(indexed_questions)
    db.session.commit()
    invalidate_view("course.get_popular", course=course.code)
    return success()
Beispiel #3
0
def get_and_update_courses():
    if request.method == "GET":
        # Return the user's courses
        return respond({ 
            "courses": g.user.courses
        })
    else:
        args = parser.parse(patchParams, request)
        id = args["course"]

        try:
            course = model.Course.getBy(db.session, id=id)
        except NotFound:
            return UnacceptableParameter("Course with id '%d' does not exist." % id)

        # Find the course
        userCourse = find(g.user.courses, lambda c: c.id == course.id)

        if request.method == "PATCH":
            # Patch request i.e. append to the collection
            # Ensure it's not already in the users courses
            if userCourse:
                return success() # Ignorance is bliss

            # Add the course
            g.user.courses.append(course)
        else:
            # Delete the course from the collection
            # Ensure we have the course
            if not userCourse:
                return success()
            
            # Remove the course
            g.user.courses.remove(userCourse)

        db.session.add(g.user)
        db.session.commit()
        return success()