def add_video(): """ Add a video to the database """ check_admin() add_video = True form = VideoForm() if form.validate_on_submit(): video = mongo.db.video try: # add department to the database video.insert({ 'video_name': form.video_name.data, 'video_address': form.video_address.data, 'video_picture': form.video_picture.data, 'release_name': form.release_name.data, 'praise_num': form.praise_num.data, 'collection_name': form.collection_name.data, 'upload_name': form.upload_name.data, 'download_name': form.download_name.data }) flash(u'您已经成功添加一个视频信息') except: # in case department name already exists flash(u'错误: 该视频信息已存在') # redirect to departments page return redirect(url_for('admin.list_videos')) # load department template return render_template('admin/videos/video.html', action="Add", add_video=add_video, form=form, title=u"添加视频信息")
def new_video(): form = VideoForm() if form.validate_on_submit(): now = moment.now().format('dddd, MMMM D YYYY') today = Day.query.filter_by(date=now).first() if today is not None: video = Video(title=form.title.data,description=form.description.data,video_link=form.video_link.data,day_id=today.id) db.session.add(video) db.session.flush() video.generate_hash() video.generate_thumbnail(app.config["UPLOAD_FOLDER"], form.thumbnail.data, app.config["ALLOWED_EXTENSIONS"]) db.session.add(video) db.session.commit() flash("Video Successfully Added") return redirect(url_for("index")) else: day = Day(date=now) db.session.add(day) db.session.flush() video = Video(title=form.title.data,description=form.description.data,video_link=form.video_link.data,day_id=day.id) db.session.add(video) db.session.flush() video.generate_hash() video.generate_thumbnail(app.config["UPLOAD_FOLDER"], form.thumbnail.data, app.config["ALLOWED_EXTENSIONS"]) db.session.add(video) db.session.commit() flash("Video Successfully Added") return redirect(url_for("index")) return render_template("videos/new.html",form=form)
def edit_video(id): data = Videos.query.get(id) form = VideoForm(request.form) form.title.data = data.title form.link.data = data.link if request.method == 'POST' and form.validate(): data.title = request.form["title"] data.link = request.form["link"] db.session.commit() flash("Video updated!", "success") return redirect(url_for('dashboard')) return render_template('edit_video.html', form=form)
def upload_video(request): if request.POST: form = VideoForm(request.POST, request.FILES) if form.is_valid(): video = form.save(commit=False) video.save() convert_video.delay(video.id) return HttpResponseRedirect('/') else: form = VideoForm() return render(request, 'upload_video.html', { 'form':form })
def post(self, request): tags = do_the_tags_magic(request.POST.get("tags", "")) request.POST["tags"] = tags form = VideoForm(request.POST, request.FILES) if form.is_valid(): obj = form.save(commit=False) obj.owner = request.user obj.save() form.save_m2m() return HttpResponseRedirect(reverse("accounts:index")) else: self.context["form"] = form return render(request, "app/upload.html", self.context)
def post(self, request): tags = do_the_tags_magic(request.POST.get('tags', '')) request.POST['tags'] = tags form = VideoForm(request.POST, request.FILES) if form.is_valid(): obj = form.save(commit=False) obj.owner = request.user obj.save() form.save_m2m() return HttpResponseRedirect(reverse('accounts:index')) else: context = {'video_upload_form': form} return render(request, 'app/upload.html', context)
def add_video(): form = VideoForm(request.form) if request.method == "POST" and form.validate(): title = form.title.data link = form.link.data author = session['username'] video = Videos(title, link, author) db.session.add(video) db.session.commit() flash("Video created", "success") return redirect(url_for('dashboard')) else: error = form.errors return render_template('add_video.html', form=form, error=error) return render_template('add_video.html', form=form)
def newvideo(): form = VideoForm() if request.method == 'POST': new_video = Video(form.name.data, form.video_type.data, form.digest.data, form.address.data, form.thumbnail.data) db.session.add(new_video) db.session.commit() return render_template('newvideo.html', form=form)
def add(request): context = { 'title': 'Add Video', 'form_action': reverse('videos:add'), 'submit_label': 'Upload', } if request.method == 'POST': form = VideoForm(request.POST, request.FILES) if form.is_valid(): obj = form.save(commit=False) obj.owner = request.user obj.save() return HttpResponseRedirect(reverse('accounts:index')) else: context['form'] = form else: context['form'] = VideoForm() return render(request, 'app/video.html', context)
def upload_video(request): if request.POST: form = VideoForm(request.POST, request.FILES) if form.is_valid(): video = form.save(commit=False) video.save() convert_video.delay(video.id) return HttpResponseRedirect('/') else: form = VideoForm() return render(request, 'upload_video.html', {'form': form})
def get(self, request): context = {'video_upload_form': VideoForm()} return render(request, 'app/upload.html', context)
def edit_video(name): """ Edit a video """ check_admin() add_video = False video = mongo.db.video.find({"video_name": name}) videos = mongo.db.video edit_video = { 'video_name': u"待赋值", 'video_address': u"待赋值", 'video_picture': u"待赋值", 'release_name': u"待赋值", 'praise_num': u"待赋值", 'collection_name': u"待赋值", 'upload_name': u"待赋值", 'download_name': u"待赋值" } videoarray = VideoArray(video_name=u"待赋值", video_address=u"待赋值", video_picture=u"待赋值", release_name=u"待赋值", praise_num=u"待赋值", collection_name=u"待赋值", upload_name=u"待赋值", download_name=u"待赋值") for s in video: videoarray.video_name = s['video_name'] videoarray.video_address = s['video_address'] videoarray.video_picture = s['video_picture'] videoarray.release_name = s['release_name'] videoarray.praise_num = s['praise_num'] videoarray.collection_name = s['collection_name'] videoarray.upload_name = s['upload_name'] videoarray.download_name = s['download_name'] form = VideoForm(obj=videoarray) videos.remove({'video_name': name}) if form.validate_on_submit(): edit_video['video_name'] = form.video_name.data edit_video['video_address'] = form.video_address.data edit_video['video_picture'] = form.video_picture.data edit_video['release_name'] = form.release_name.data edit_video['praise_num'] = form.praise_num.data edit_video['collection_name'] = form.collection_name.data edit_video['upload_name'] = form.upload_name.data edit_video['download_name'] = form.download_name.data videos.insert(edit_video) flash(u'您已经成功修改视频信息') # redirect to the dancegroups page return redirect(url_for('admin.list_videos')) for s in video: form.video_name.data = s['video_name'] form.video_address.data = s['video_address'] return render_template('admin/videos/video.html', action="Edit", add_video=add_video, form=form, video=video, title=u"修改舞群信息")