Beispiel #1
0
def video_chapter_save(request, video):
    list_chapter = video.chapter_set.all()

    form_chapter = None
    if request.POST.get('chapter_id') != 'None':
        chapter = get_object_or_404(Chapter, id=request.POST['chapter_id'])
        form_chapter = ChapterForm(request.POST, instance=chapter)
    else:
        form_chapter = ChapterForm(request.POST)
    if form_chapter.is_valid():
        form_chapter.save()
        list_chapter = video.chapter_set.all()
        if request.is_ajax():
            csrf_token_value = get_token(request)
            some_data_to_dump = {
                'list_chapter':
                render_to_string('chapter/list_chapter.html', {
                    'list_chapter': list_chapter,
                    'video': video,
                    "csrf_token_value": csrf_token_value
                },
                                 request=request),
                'video-elem':
                render_to_string('videos/video-element.html', {'video': video},
                                 request=request)
            }
            data = json.dumps(some_data_to_dump)
            return HttpResponse(data, content_type='application/json')
        else:
            return render(request, 'video_chapter.html', {
                'video': video,
                'list_chapter': list_chapter
            })
    else:
        if request.is_ajax():
            csrf_token_value = get_token(request)
            some_data_to_dump = {
                'errors':
                '{0}'.format(_('Please correct errors.')),
                'form':
                render_to_string('chapter/form_chapter.html', {
                    'video': video,
                    'form_chapter': form_chapter,
                    "csrf_token_value": csrf_token_value
                },
                                 request=request)
            }
            data = json.dumps(some_data_to_dump)
            return HttpResponse(data, content_type='application/json')
        else:
            return render(
                request, 'video_chapter.html', {
                    'video': video,
                    'list_chapter': list_chapter,
                    'form_chapter': form_chapter
                })
Beispiel #2
0
def video_chapter_save(request, video):
    list_chapter = video.chapter_set.all()

    form_chapter = None
    if request.POST.get("chapter_id") != "None":
        chapter = get_object_or_404(Chapter, id=request.POST["chapter_id"])
        form_chapter = ChapterForm(request.POST, instance=chapter)
    else:
        form_chapter = ChapterForm(request.POST)
    if form_chapter.is_valid():
        form_chapter.save()
        list_chapter = video.chapter_set.all()
        if request.is_ajax():
            csrf_token_value = get_token(request)
            some_data_to_dump = {
                "list_chapter":
                render_to_string(
                    "chapter/list_chapter.html",
                    {
                        "list_chapter": list_chapter,
                        "video": video,
                        "csrf_token_value": csrf_token_value,
                    },
                    request=request,
                ),
                "video-elem":
                render_to_string(
                    "videos/video-element.html",
                    {"video": video},
                    request=request,
                ),
            }
            data = json.dumps(some_data_to_dump)
            return HttpResponse(data, content_type="application/json")
        else:
            return render(
                request,
                "video_chapter.html",
                {
                    "video": video,
                    "list_chapter": list_chapter
                },
            )
    else:
        if request.is_ajax():
            csrf_token_value = get_token(request)
            some_data_to_dump = {
                "errors":
                "{0}".format(_("Please correct errors.")),
                "form":
                render_to_string(
                    "chapter/form_chapter.html",
                    {
                        "video": video,
                        "form_chapter": form_chapter,
                        "csrf_token_value": csrf_token_value,
                    },
                    request=request,
                ),
            }
            data = json.dumps(some_data_to_dump)
            return HttpResponse(data, content_type="application/json")
        else:
            return render(
                request,
                "video_chapter.html",
                {
                    "video": video,
                    "list_chapter": list_chapter,
                    "form_chapter": form_chapter,
                },
            )