示例#1
0
文件: views.py 项目: asmcos/blog
def index():
	blog = blogs.all();
	form = BlogsForm();
	if request.method == 'POST':
		flag = form.validate(request.params)
		if flag:
			n = blogs(**form.data);
			n.username = request.user.username
			n.save();
	return {'blog':blog,'form':form}
示例#2
0
def create():
    if require_login():
        return redirect(url_for(login))

    if request.method == "POST":
        form = BlogsForm()
        flag = form.validate(request.params)
        if flag:
            info = blogs(**form.data)
            info.username = request.user.username
            info.save()
        return redirect('/view/%d' % info.id)

    form = BlogsForm()
    return {'form':form}
示例#3
0
文件: views.py 项目: asmcos/blog
def edit(id):
	if require_login():
		return redirect(url_for(login))
	if request.method == 'GET':
		p = blogs.get(blogs.c.id==id)
		form = BlogsForm(data={'title':p.title,'content':p.content})
		return {'form':form}
	elif request.method == 'POST':
		form = BlogsForm()
            	flag = form.validate(request.params)
		n = blogs.get(blogs.c.id == id)
		if n:
			n.username = request.user.username
			n.title    = form.data.title
			n.content  = form.data.content
			n.save()
		return redirect('/');
示例#4
0
def add():
    """ 新增文章 """
    form = BlogsForm()
    if form.validate_on_submit():
        blog = Blogs(
            title=form.title.data,
            content=form.content.data,
            types=form.types.data,
            images=form.images.data,
            is_valid=True,
            create_time=datetime.now(),
            update_time=datetime.now(),
        )
        db.session.add(blog)
        db.session.commit()
        flash('添加成功')
        return redirect(url_for('admin'))
    return render_template('/admin/add.html', form=form)
示例#5
0
def update(pk):
    """ 更新文章 """
    obj = Blogs.query.get(pk)
    if obj is None:
        abort(404)
    form = BlogsForm(obj=obj)
    if form.validate_on_submit():
        blog = Blogs(
            title=form.title.data,
            content=form.content.data,
            types=form.types.data,
            images=form.images.data,
            update_time=datetime.now(),
        )
        db.session.add(blog)
        db.session.commit()
        flash('修改成功')
        return redirect(url_for('admin'))
    return render_template('/admin/update.html', form=form)