def video_chapter_new(request, video): list_chapter = video.chapter_set.all() form_chapter = ChapterForm(initial={"video": video}) form_import = ChapterImportForm(user=request.user, video=video) if request.is_ajax(): return render( request, "chapter/form_chapter.html", { "form_chapter": form_chapter, "form_import": form_import, "video": video, }, ) else: return render( request, "video_chapter.html", { "video": video, "list_chapter": list_chapter, "form_chapter": form_chapter, "form_import": form_import, }, )
def video_chapter_modify(request, video): list_chapter = video.chapter_set.all() if request.POST.get("action") and request.POST["action"] == "modify": chapter = get_object_or_404(Chapter, id=request.POST["id"]) form_chapter = ChapterForm(instance=chapter) if request.is_ajax(): return render( request, "chapter/form_chapter.html", { "form_chapter": form_chapter, "video": video }, ) else: return render( request, "video_chapter.html", { "video": video, "list_chapter": list_chapter, "form_chapter": form_chapter, }, )
def video_chapter_import(request, video): list_chapter = video.chapter_set.all() form_chapter = ChapterForm(initial={'video': video}) form_import = ChapterImportForm(request.POST, user=request.user, video=video) if form_import.is_valid(): 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(): some_data_to_dump = { 'errors': '{0}'.format(_('Please correct errors.')), 'form': render_to_string( 'chapter/form_chapter.html', { 'video': video, 'form_import': form_import, 'form_chapter': form_chapter, 'csrf_token': request.COOKIES['csrftoken'] }) } 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, 'form_import': form_import })
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 })
def video_chapter_modify(request, video): list_chapter = video.chapter_set.all() if request.POST.get('action') and request.POST['action'] == 'modify': chapter = get_object_or_404(Chapter, id=request.POST['id']) form_chapter = ChapterForm(instance=chapter) if request.is_ajax(): return render(request, 'chapter/form_chapter.html', { 'form_chapter': form_chapter, 'video': video }) else: return render( request, 'video_chapter.html', { 'video': video, 'list_chapter': list_chapter, 'form_chapter': form_chapter })
def video_chapter_new(request, video): list_chapter = video.chapter_set.all() form_chapter = ChapterForm(initial={'video': video}) form_import = ChapterImportForm(user=request.user, video=video) if request.is_ajax(): return render( request, 'chapter/form_chapter.html', { 'form_chapter': form_chapter, 'form_import': form_import, 'video': video }) else: return render( request, 'video_chapter.html', { 'video': video, 'list_chapter': list_chapter, 'form_chapter': form_chapter, 'form_import': form_import })
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, }, )
def video_chapter_import(request, video): list_chapter = video.chapter_set.all() form_chapter = ChapterForm(initial={"video": video}) form_import = ChapterImportForm(request.POST, user=request.user, video=video) if form_import.is_valid(): 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(): some_data_to_dump = { "errors": "{0}".format(_("Please correct errors.")), "form": render_to_string( "chapter/form_chapter.html", { "video": video, "form_import": form_import, "form_chapter": form_chapter, "csrf_token": request.COOKIES["csrftoken"], }, ), } 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, "form_import": form_import, }, )