Beispiel #1
0
def new_text_blog():
	form = NewTextBlogForm()

	if request.method == 'POST' and form.validate():
		new_blog = blog_create(form.title.data, form.tags.data, form.body.data, form.post_submit.data)
		new_blog.blog_type = 'text'
		db.session.commit()
		return redirect('/blog/list')
	return render_template('simpleblog/text-edit-form.html', form=form)	
Beispiel #2
0
def edit_blog(blog_id):
	blog = BlogEntry.query.filter_by(id=blog_id).first()
	if blog.blog_type == 'text':
		form = NewTextBlogForm()
		form.title.data = blog.title
		tags = '' 
		for tag in blog.tags:
			 tags += tag.title + ','
		form.tags.data = tags
		form.body.data = blog.body
		
		if request.method == 'POST' and form.validate():
			blog.title = form.title.data
			tags = form.tags.data.split(',')
			tag_objects = []
			for tag in tags: 
				storedTag = BlogTag.query.filter_by(title=tag).first()
				tag_objects.append(storedTag)
			blog.tags = tag_objects
			db.session.commit()	
			return redirect('/blog/list')
		return render_template('simpleblog/text-new.html', form=form)	
	return redirect('/')