def chooser_upload(request): VideoForm = get_video_form(Video) searchform = SearchForm() if request.POST: video = Video(uploaded_by_user=request.user) form = VideoForm(request.POST, request.FILES, instance=video) if form.is_valid(): video.uploaded_by_user = request.user video.save() # Reindex the video to make sure all tags are indexed search_index.insert_or_update_object(video) return render_modal_workflow( request, None, 'wagtailvideos/chooser/video_chosen.js', {'video_json': get_video_json(video)} ) else: form = VideoForm() videos = Video.objects.order_by('title') paginator, videos = paginate(request, videos, per_page=12) return render_modal_workflow( request, 'wagtailvideos/chooser/chooser.html', 'wagtailvideos/chooser/chooser.js', {'videos': videos, 'uploadform': form, 'searchform': searchform} )
def chooser_upload(request): VideoForm = get_video_form(Video) searchform = SearchForm() if request.POST: video = Video(uploaded_by_user=request.user) form = VideoForm(request.POST, request.FILES, instance=video) if form.is_valid(): video.uploaded_by_user = request.user video.save() # Reindex the video to make sure all tags are indexed search_index.insert_or_update_object(video) return render_modal_workflow( request, None, json_data={ 'step': 'video_chosen', 'result': get_video_json(video) } ) else: form = VideoForm() videos = Video.objects.order_by('title') paginator = Paginator(videos, per_page=12) page = paginator.get_page(request.GET.get('p')) return render_modal_workflow( request, 'wagtailvideos/chooser/chooser.html', None, template_vars={'videos': page, 'uploadform': form, 'searchform': searchform}, json_data=get_chooser_js_data() )
def add(request): VideoForm = get_video_form(Video) if request.POST: video = Video(uploaded_by_user=request.user) form = VideoForm(request.POST, request.FILES, instance=video, user=request.user) if form.is_valid(): # Save video = form.save(commit=False) video.file_size = video.file.size video.save() # Success! Send back an edit form for backend in get_search_backends(): backend.add(video) messages.success(request, _("Video '{0}' added.").format(video.title), buttons=[ messages.button(reverse('wagtailvideos:edit', args=(video.id,)), _('Edit')) ]) return redirect('wagtailvideos:index') else: messages.error(request, _("The video could not be created due to errors.")) else: form = VideoForm(user=request.user) return render(request, "wagtailvideos/videos/add.html", { 'form': form, })