def upload_video(request): if not request.user.is_authenticated: messages.warning( request, "To see this video you must login or register firstly!") return redirect("login") get = UserExt.objects.get(user_id=request.user.id) if get.activated == False: return redirect("login") form = VideoForm(request.POST or None, request.FILES or None) if form.is_valid(): form.save() messages.success(request, "Your video is successfuly added!") return redirect("home") return render(request, "video_upload.html", {"form": form})
def video_edit(request, video_id): if not request.is_ajax(): raise Http404() video = get_object_or_404(Video, pk=video_id) if request.method == 'POST': form = VideoForm(request.POST, request.FILES, instance=video) if form.is_valid(): convert = 'video_original' in form.changed_data video = form.save() if video.is_local(): if convert: video_path = video.video_original.path img_file_path = generate_image_path(video_path, VIDEO_THUMB_NAME) get_video_thumb(video_path, img_file_path) video.poster = generate_media_path(img_file_path) video.active = False video.save() return HttpResponseRedirect('/video/convert/{0}'.format(video.id)) else: return HttpResponse('') video.active = True video.save() video.get_yt_poster() return HttpResponse('') else: form = VideoForm(instance=video) return render_to_response('video/video_edit.html', {'form': form, 'video': video }, context_instance=RequestContext(request))
def video_edit(request, video_id): if not request.is_ajax(): raise Http404() video = get_object_or_404(Video, pk=video_id) if request.method == 'POST': form = VideoForm(request.POST, request.FILES, instance=video) if form.is_valid(): convert = 'video_original' in form.changed_data video = form.save() if video.is_local(): if convert: video_path = video.video_original.path img_file_path = generate_image_path( video_path, VIDEO_THUMB_NAME) get_video_thumb(video_path, img_file_path) video.poster = generate_media_path(img_file_path) video.active = False video.save() return HttpResponseRedirect('/video/convert/{0}'.format( video.id)) else: return HttpResponse('') video.active = True video.save() video.get_yt_poster() return HttpResponse('') else: form = VideoForm(instance=video) return render_to_response('video/video_edit.html', { 'form': form, 'video': video }, context_instance=RequestContext(request))
def post(self, request, *args, **kwargs): from video.forms import VideoForm video = Video.objects.get(pk=request.POST.get("pk")) form_post = VideoForm(request.POST, request.FILES, instance=video) if request.is_ajax() and form_post.is_valid( ) and video.list.is_user_can_create_el(request.user.pk): _video = form_post.save(commit=False) if video.type == Video.UPLOAD: if video.community: video.community.plus_videos(1) else: video.creator.plus_videos(1) video.title = _video.title video.description = _video.description video.image = _video.image video.votes_on = _video.votes_on video.comments_enabled = _video.comments_enabled video.type = Video.PUBLISHED video.save() return render_for_platform(request, 'users/video/main_list/video.html', {'object': video}) else: return HttpResponseBadRequest()
class CommunityVideoEdit(TemplateView): template_name = None def get(self, request, *args, **kwargs): self.template_name = get_detect_platform_template( "video/community_create/edit.html", request.user, request.META['HTTP_USER_AGENT']) return super(CommunityVideoEdit, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(CommunityVideoEdit, self).get_context_data(**kwargs) context["form"] = VideoForm() context["sub_categories"] = VideoSubCategory.objects.only("id") context["categories"] = VideoCategory.objects.only("id") context["video"] = Video.objects.get(pk=self.kwargs["pk"]) return context def post(self, request, *args, **kwargs): self.video = Video.objects.get(pk=self.kwargs["pk"]) self.form = VideoForm(request.POST, request.FILES, instance=self.video) if request.is_ajax() and self.form.is_valid( ) and request.user.pk.is_administrator_of_community(self.kwargs["pk"]): video = self.form.save(commit=False) new_video = self.video.edit_video( title=new_video.title, file=new_video.file, uri=new_video.uri, description=new_video.description, list=new_video.list, comments_enabled=new_video.comments_enabled, votes_on=new_video.votes_on) return render_for_platform(request, 'video/video_new/video.html', {'object': new_video}) else: return HttpResponseBadRequest()
def post(self,request,*args,**kwargs): form_post = VideoForm(request.POST, request.FILES) if request.is_ajax() and form_post.is_valid(): video = form_post.save(commit=False) new_video = Video.create_video(creator=request.user, title=video.title, file=video.file, image=video.image, uri=video.uri, lists=request.POST.getlist("list"), is_public=request.POST.get("is_public"), community=None) return render_for_platform(request, 'user_video/new_video.html',{'object': new_video}) else: return HttpResponseBadRequest()
def post(self,request,*args,**kwargs): self.video = Video.objects.get(pk=self.kwargs["pk"]) form_post = VideoForm(request.POST, request.FILES, instance=self.video) if request.is_ajax() and form_post.is_valid(): _video = form_post.save(commit=False) new_video = self.video.edit_video(title=_video.title, image=_video.image, uri=_video.uri, file=_video.file, lists=request.POST.getlist("list"), is_public=request.POST.get("is_public")) return render_for_platform(request, 'user_video/new_video.html',{'object': self.video}) else: return HttpResponseBadRequest()
def video_add(request): if request.method == 'POST': form = VideoForm(request.POST, request.FILES) if form.is_valid(): video = form.save() if video.is_local(): video_path = video.video_original.path img_file_path = generate_image_path(video_path, VIDEO_THUMB_NAME) get_video_thumb(video_path, img_file_path) video.poster = generate_media_path(img_file_path) video.save() return HttpResponseRedirect('/video/convert/{0}'.format(video.id)) video.active = True video.save() video.get_yt_poster() return HttpResponse('') else: form = VideoForm() return render_to_response('video/video_add.html', {'form': form }, context_instance=RequestContext(request))
class UserVideoCreate(TemplateView): template_name, form_post = None, None def get(self, request, *args, **kwargs): self.template_name = get_settings_template( "video/user_create/create_video.html", request.user, request.META['HTTP_USER_AGENT']) return super(UserVideoCreate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): from video.models import VideoList from video.forms import VideoForm context = super(UserVideoCreate, self).get_context_data(**kwargs) context["form_post"] = VideoForm() context['video_lists'] = VideoList.get_user_staff_lists( self.request.user.pk) return context def post(self, request, *args, **kwargs): from video.forms import VideoForm self.form_post = VideoForm(request.POST, request.FILES) self.user = User.objects.get(pk=self.kwargs["pk"]) if request.is_ajax() and self.form_post.is_valid(): video = self.form_post.save(commit=False) new_video = video.create_video( creator=request.user, image=video.image, title=video.title, file=video.file, uri=video.uri, description=video.description, list=video.list, comments_enabled=video.comments_enabled, votes_on=video.votes_on, community=None) return render_for_platform(request, 'video/video_new/video.html', {'object': new_video}) else: return HttpResponseBadRequest()
def video_add(request): if request.method == 'POST': form = VideoForm(request.POST, request.FILES) if form.is_valid(): video = form.save() if video.is_local(): video_path = video.video_original.path img_file_path = generate_image_path(video_path, VIDEO_THUMB_NAME) get_video_thumb(video_path, img_file_path) video.poster = generate_media_path(img_file_path) video.save() return HttpResponseRedirect('/video/convert/{0}'.format( video.id)) video.active = True video.save() video.get_yt_poster() return HttpResponse('') else: form = VideoForm() return render_to_response('video/video_add.html', {'form': form}, context_instance=RequestContext(request))