def new_post(): form = PostForm() if form.validate_on_submit(): form.save(set_author=True) flash('Added post.', 'success') return form.redirect(url_for('admin.index')) return render_template('admin/post_form.html', title='New post', form=form)
def edit_post(id, slug=None): post = Post.query.get_or_404(id) if slug is None: return redirect(url_for('admin.edit_post', id=id, slug=post.slug)) form = PostForm(obj=post) if form.validate_on_submit(): form.save() flash('Edited post.', 'success') return form.redirect(url_for('admin.index')) return render_template('admin/post_form.html', title='Edit post', form=form)
def post_new(): form = PostForm() if form.validate_on_submit(): #make a new post p= Post(form.title.data , form.body.data ,current_user.id ) #save the post p.save() #print post id print(p.id) flash("post has been added", 'success') return redirect( url_for('post.posts')) return render_template("admin/post/new.html" , form = form)
def post(): if current_user.is_adminenticated: return redirect(url_for('admin.admin')) if not current_user.real_name: flash(_('完善资料后再试')) return redirect(url_for('admin.index')) if not current_user.is_authed: flash(_('用户信息审核中, 稍后再试')) return redirect(url_for('admin.index')) form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, body=form.body.data, author=current_user) form.photo.data.filename = post.set_photo(form.photo.data.filename) filename = sphotos.save(form.photo.data) file_url = sphotos.url(filename) post.set_photo(file_url.split('/')[-1], token=True) db.session.add(post) db.session.commit() flash(_('课程申请已提交')) return redirect(url_for('admin.index')) return render_template('admin/post.html', title=_('申请课程'), form=form)
def edit_course(title): if current_user.is_adminenticated: flash(_('这里不能审核课程!')) return redirect(url_for('admin.index')) post = Post.query.filter_by(title=title).first_or_404() if not post.author == current_user: # print(2333) flash(_('你没有权限这么做!')) form = PostForm(post.title, post.body) if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data form.photo.data.filename = post.set_photo(form.photo.data.filename) filename = sphotos.save(form.photo.data) file_url = sphotos.url(filename) post.set_photo(file_url.split('/')[-1], token=True) db.session.add(post) db.session.commit() flash(_('此课程信息已更新')) return redirect(url_for('admin.index')) elif request.method == 'GET': form.title.data = post.title form.body.data = post.body return render_template('admin/user/edit_course.html', form=form)