Пример #1
0
def video(id):
    video = Video.get_by_id(id)
    if video is None:
        return {}, 404

    if request.method == 'GET':
        video_dict = video.as_dict()
        response = jsonify(video_dict)
        response.status_code = 200
        return response

    if is_valid_admin(request):
        if request.method == 'PUT':
            result = request.get_json()
            video = Video.update_data(id, result)
            if video:
                video_dict = video.as_dict()
                response = jsonify(video_dict)
                response.status_code = 200
                return response
            else:
                return error_response('Video não atualizado', 500)

        elif request.method == 'DELETE':
            if Video.delete(id):
                # deletar no youtube
                return {}, 200
            else:
                return error_response('Video não deletado', 500)
    else:
        return error_response('Permissão negada', 401)
Пример #2
0
def update_share_times(cid, tid):
    """更新分享次数"""
    item = dict()
    if tid == 1:  # 海报
        pass
    elif tid == 2:  # 文章
        article = Article.get_by_id(cid)
        article.update_real_use_count()
        item = article.to_dict()
    elif tid == 4:  # 视频
        video = Video.get_by_id(cid)
        video.update_real_use_count()
        item = video.to_dict()
    return item
Пример #3
0
 def test_04_get_by_id(self):
     course = Course.add({'name': "Curso de Teste"})
     video = Video.add(1, {'youtube_code': 'test_code', 'course_order': 1})
     new_video = Video.get_by_id(1)
     video_fail = Video.get_by_id(2)
     assert new_video is not None and new_video.id == video.id and video_fail is None