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 create(request): if request.method == 'POST': form = VideoForm(request.POST, request.FILES) if form.is_valid(): return render_to_response('video/successful_import.html', {}, context_instance=RequestContext(request)) else: form = VideoForm() importForm = VideoImportForm() return render_to_response('video/create.html', { 'form': form, 'importForm': importForm, }, context_instance=RequestContext(request))
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_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))
def upload_video(request, template_name='video/upload.html'): if request.method == 'POST': form = VideoForm(request.POST, request.FILES) if form.is_valid(): vimeoClient = VimeoClient(settings.VIMEO_API_KEY, settings.VIMEO_API_SECRET) tempVideo = open(tempfile.mktemp(".AVI"), 'wb+') for chunk in form.files['video'].chunks(): tempVideo.write(chunk) try: ticked_id = vimeoClient.upload(tempVideo.name) except Exception, inst: mail_admins("Error Uploading Video", "Vimeo Video konnte nicht hochgeladen werden: "\ +str(inst.args)) return render_to_response("video/upload_error.html", { }, context_instance=RequestContext(request)) tempVideo.close() if ticked_id: video_id = vimeoClient.check_upload_status(ticked_id) if video_id: #get thumbnail url rsp = vimeoClient.call("vimeo.videos.getThumbnailUrl", {"video_id": video_id, "size":"160x120"} ) thumbnail_url = rsp.getElementsByTagName("thumbnail")[0]\ .childNodes[0].nodeValue #set the values video = Video(creator=request.user, import_url="http://vimeo.com/"+video_id, was_uploaded=True, is_viewable=False, external_id=video_id, ticket_id=ticked_id, comment=form.cleaned_data['comment'], title=form.cleaned_data['title'], tags=form.cleaned_data['tags'], thumbnail_url=thumbnail_url ) video.save(); rsp = vimeoClient.call("vimeo.videos.setTitle", { "title": form.cleaned_data['title'], "video_id": video_id } ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Titel konnte nicht gesetzt werden:\ Video_id: "+str(video.pk)) rsp = vimeoClient.call("vimeo.videos.setCaption", { "caption": form.cleaned_data['comment'], "video_id": video_id } ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Caption konnte nicht gesetzt werden:\ Video_id: "+str(video.pk)) rsp = vimeoClient.call("vimeo.videos.setPrivacy", {"privacy": "anybody", "video_id": video_id} ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Privacy konnte nicht gesetzt werden:\ Video_id: "+str(video.id)) if form.cleaned_data['tags']: tags = parse_tag_input(video.tags) tags = ",".join(tags) rsp = vimeoClient.call("vimeo.videos.addTags", {"tags": tags, "video_id": video_id} ) if(rsp.attributes['stat'].value!="ok"): mail_admins("Error", "Vimeo Tags konnten nicht gesetzt \ werden: Video_id: "+str(video.id)) return render_to_response("video/upload_success.html", { "video": video, }, context_instance=RequestContext(request)) # an error has occurred return render_to_response("video/upload_error.html", { }, context_instance=RequestContext(request)) else: request.user.message_set.create(message=_("Video '%s' was \ successfully uploaded!") % video.title) return HttpResponseRedirect(reverse('show_video', args=(video.id,)))