コード例 #1
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def video_subtitles(request, course_key_string, video_id):
    """GET all video subtitles or POST a new subtitle"""
    api_client = get_client(course_key_string)
    if method_is(request, 'GET'):
        try:
            return JsonResponse(api_client.get_subtitles(video_id))
        except ClientError as e:
            return json_error_response(_("Could not fetch video subtitles:"),
                                       e.message)
    elif method_is(request, 'POST'):
        form = SubtitleForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                api_client.upload_subtitle(
                    form.cleaned_data["video_id"],
                    form.cleaned_data["uploaded_file"],
                    form.cleaned_data["language"],
                )
                return JsonResponse({})
            except ClientError as e:
                return json_error_response(_("Could not add subtitles:"),
                                           e.message)
        else:
            return json_error_response(_("Could not upload subtitles"),
                                       form.formatted_errors())
    else:
        raise Http404()
コード例 #2
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def file_upload_url(request, course_key_string):
    api_client = get_client(course_key_string)
    origin = '%s://%s' % (request.is_secure() and 'https'
                          or 'http', request.get_host())
    try:
        return JsonResponse(api_client.get_upload_url(origin=origin))
    except ClientError as e:
        return json_error_response(_("Could not fetch upload url:"), e.message)
コード例 #3
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def get_videos(request, course_key_string):
    api_client = get_client(course_key_string)

    # Get list of uploaded videos
    try:
        videos = api_client.get_videos()
        return JsonResponse({"videos": videos})
    except ClientError as e:
        return json_error_response(_("Could not fetch video list:"), e.message)
コード例 #4
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def get_videos(request, course_key_string):
    api_client = get_client(course_key_string)

    # Get list of uploaded videos
    try:
        videos = api_client.get_videos()
        return JsonResponse({"videos": videos})
    except ClientError as e:
        return json_error_response(_("Could not fetch video list:"), e.message)
コード例 #5
0
ファイル: videoupload.py プロジェクト: openfun/fun-apps
def file_upload_url(request, course_key_string):
    api_client = get_client(course_key_string)
    origin = '%s://%s' % (
        request.is_secure() and 'https' or 'http',
        request.get_host()
    )
    try:
        return JsonResponse(api_client.get_upload_url(origin=origin))
    except ClientError as e:
        return json_error_response(_("Could not fetch upload url:"), e.message)
コード例 #6
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def video(request, course_key_string, video_id):
    api_client = get_client(course_key_string)
    if method_is(request, "GET"):
        return get_video(request, api_client, video_id)
    elif method_is(request, "DELETE"):
        return delete_video(request, api_client, video_id)
    elif method_is(request, "POST"):
        return update_video(request, api_client, video_id)
    else:
        raise Http404()
コード例 #7
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def unpublish_video(request, course_key_string):
    video_id = request.POST.get("video_id")
    if not video_id:
        raise Http404()

    api_client = get_client(course_key_string)
    try:
        return JsonResponse(api_client.unpublish_video(video_id))
    except ClientError as e:
        return json_error_response(_("Could not unpublish video:"), e.message)
コード例 #8
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def video(request, course_key_string, video_id):
    api_client = get_client(course_key_string)
    if method_is(request, 'GET'):
        return get_video(request, api_client, video_id)
    elif method_is(request, 'DELETE'):
        return delete_video(request, api_client, video_id)
    elif method_is(request, 'POST'):
        return update_video(request, api_client, video_id)
    else:
        raise Http404()
コード例 #9
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def video_subtitle(request, course_key_string, video_id, subtitle_id):
    """GET or DELETE a specific video subtitle"""
    api_client = get_client(course_key_string)
    if method_is(request, "DELETE"):
        try:
            api_client.delete_video_subtitle(video_id, subtitle_id)
            return JsonResponse({})
        except ClientError as e:
            return json_error_response(_("Could not delete subtitle:"), e.message)
    else:
        raise Http404()
コード例 #10
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def video_update_thumbnail(request, course_key_string, video_id):
    form = ThumbnailForm(request.POST, request.FILES)
    if form.is_valid():
        api_client = get_client(course_key_string)
        try:
            return JsonResponse(
                api_client.upload_thumbnail(form.cleaned_data["video_id"], form.cleaned_data["uploaded_file"])
            )
        except ClientError as e:
            return json_error_response(_("Could not add thumbnail:"), e.message)
    else:
        return json_error_response(_("Could not upload thumbnail"), form.formatted_errors())
コード例 #11
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def video_subtitle(request, course_key_string, video_id, subtitle_id):
    """GET or DELETE a specific video subtitle"""
    api_client = get_client(course_key_string)
    if method_is(request, 'DELETE'):
        try:
            api_client.delete_video_subtitle(video_id, subtitle_id)
            return JsonResponse({})
        except ClientError as e:
            return json_error_response(_("Could not delete subtitle:"),
                                       e.message)
    else:
        raise Http404()
コード例 #12
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def create_video(request, course_key_string):
    payload = request.POST.get("payload")
    title = request.POST.get("title")
    if not payload:
        raise Http404()
    try:
        payload = json.loads(payload)
    except ValueError:
        raise Http404()

    api_client = get_client(course_key_string)
    try:
        return JsonResponse(api_client.create_video(payload, title=title))
    except ClientError as e:
        return json_error_response(_("Could not create video:"), e.message)
コード例 #13
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def create_video(request, course_key_string):
    payload = request.POST.get("payload")
    title = request.POST.get("title")
    if not payload:
        raise Http404()
    try:
        payload = json.loads(payload)
    except ValueError:
        raise Http404()

    api_client = get_client(course_key_string)
    try:
        return JsonResponse(api_client.create_video(payload, title=title))
    except ClientError as e:
        return json_error_response(_("Could not create video:"), e.message)
コード例 #14
0
ファイル: videoupload.py プロジェクト: oplarshad/fun-apps
def video_update_thumbnail(request, course_key_string, video_id):
    form = ThumbnailForm(request.POST, request.FILES)
    if form.is_valid():
        api_client = get_client(course_key_string)
        try:
            return JsonResponse(
                api_client.upload_thumbnail(
                    form.cleaned_data["video_id"],
                    form.cleaned_data["uploaded_file"],
                ))
        except ClientError as e:
            return json_error_response(_("Could not add thumbnail:"),
                                       e.message)
    else:
        return json_error_response(_("Could not upload thumbnail"),
                                   form.formatted_errors())
コード例 #15
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def video_subtitles(request, course_key_string, video_id):
    """GET all video subtitles or POST a new subtitle"""
    api_client = get_client(course_key_string)
    if method_is(request, "GET"):
        try:
            return JsonResponse(api_client.get_video_subtitles(video_id))
        except ClientError as e:
            return json_error_response(_("Could not fetch video subtitles:"), e.message)
    elif method_is(request, "POST"):
        form = SubtitleForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                api_client.upload_subtitle(
                    form.cleaned_data["video_id"], form.cleaned_data["uploaded_file"], form.cleaned_data["language"]
                )
                return JsonResponse({})
            except ClientError as e:
                return json_error_response(_("Could not add subtitles:"), e.message)
        else:
            return json_error_response(_("Could not upload subtitles"), form.formatted_errors())
    else:
        raise Http404()
コード例 #16
0
ファイル: videoupload.py プロジェクト: julAtWork/fun-apps
def file_upload_url(request, course_key_string):
    api_client = get_client(course_key_string)
    try:
        return JsonResponse(api_client.get_upload_url())
    except ClientError as e:
        return json_error_response(_("Could not fetch upload url:"), e.message)
コード例 #17
0
ファイル: videoupload.py プロジェクト: regisb/fun-apps
def file_upload(request, course_key_string):
    api_client = get_client(course_key_string)
    try:
        return JsonResponse(api_client.get_upload_url())
    except ClientError as e:
        return json_error_response(_("Could not fetch upload url:"), e.message)