示例#1
0
    def post(self, cid):
        if not g.current_user.is_teacher(g.current_course):
            return api_abort(403, "permission denied")

        old_media = Media.load_media_from_uuid(g.current_course.avatar, return_model=True)
        new_media = request.files.get("avatar")
        if new_media is None:
            return api_abort(400, "file missing")
        new_media_uuid = Media.save_media(new_media, "avatars/course", commit=False)
        old_media.delete() if old_media is not None else 1
        g.current_course.avatar = new_media_uuid
        db.session.commit()
        return "OK"
示例#2
0
    def post(self):
        data = course_create_reqparser.parse_args()
        new_course = Course(data['name'], data['public'], g.current_user.id,
                            data['start_at'], data['end_at'], data['introduce'])

        new_media = request.files.get("avatar")
        if new_media is None:
            return api_abort(400, "file missing")
        new_media_uuid = Media.save_media(new_media, "avatars/course", commit=False)
        new_course.avatar = new_media_uuid

        db.session.add(new_course)
        db.session.commit()
        return make_resp(new_course.to_json(detail=True))
示例#3
0
    def post(self, cid):
        # expected str chapter and file document, if chapter not exist, create it.
        data = upload_reqparser.parse_args()
        chapter_name = data['chapter']
        name = data['name']
        chapter = Chapter.query.filter_by(name=chapter_name, course_id=g.current_course.id).first()
        if chapter is None:
            chapter = Chapter(chapter_name)
            chapter.course = g.current_course
            db.session.add(chapter)

        course = g.current_course
        movie = request.files.get('movie')
        if movie is None:
            return api_abort(400, "movie is None")

        new_media_uuid = Media.save_media(movie, 'course/{}/movie'.format(course.id), name=name)
        media_uuid_list = pickle.loads(chapter.movies)
        media_uuid_list.append(new_media_uuid)
        chapter.movies = pickle.dumps(media_uuid_list)
        db.session.commit()
        return make_resp(chapter.to_json(with_movies=True))