def edit_post(slug): post = Post.gql("WHERE slug = :1", slug)[0] images = Image.all() form = PostForm(title=post.title, category=post.category.key(), tags=','.join(post.tags),content=post.content, excerpt=post.excerpt,status=post.status) form.category.choices = controllers.categories_select() if form.validate_on_submit(): excerpt = form.excerpt.data if '<div>' in excerpt: if '<div><br></div>' not in excerpt[-100:]: excerpt = excerpt+'<div><br></div>' else: excerpt = '<div>'+excerpt+'</div>'+'<div><br></div>' post.title = form.title.data post.category = db.get(form.category.data) post.tags = [x.strip() for x in form.tags.data.split(',')] post.author = db.get(current_user.id) post.slug = controllers.slugify(form.title.data) post.content = form.content.data post.excerpt = excerpt post.status = form.status.data post.date_modified = datetime.now() post.put() flash('The post has been updated.','event') return redirect(url_for('view_posts')) return render_template('cms_edit_post.html', form=form, post=post, images=images)
def new_post(): form = PostForm() images = Image.all() form.category.choices = controllers.categories_select() if form.validate_on_submit(): excerpt = form.excerpt.data if '<div>' in excerpt: if '<div><br></div>' not in excerpt[-100:]: excerpt = excerpt+'<div><br></div>' else: excerpt = '<div>'+excerpt+'</div>'+'<div><br></div>' post = Post(title = form.title.data, category = db.get(form.category.data), tags = [x.strip() for x in form.tags.data.split(',')], slug = controllers.slugify(form.title.data), content = form.content.data, excerpt = excerpt, status = form.status.data, author = db.get(current_user.id), date_created = datetime.now()) post.put() flash('The new post has been saved.','event') return redirect(url_for('view_posts')) return render_template('cms_new_post.html', form=form, images=images)