Example #1
0
File: dev.py Project: rclanan/radar
def create_posts(n):
    for x in range(n):
        d = random_date(date(2008, 1, 1), date.today())

        post = Post()
        post.title = '%s Newsletter' % d.strftime('%b %Y')
        post.body = generate_lorem_ipsum(n=3, html=False)
        post.published = d
        db.session.add(post)
Example #2
0
def add_post():
    if not current_user.has_edit_news_permission:
        abort(403)

    form = PostForm()

    if form.validate_on_submit():
        post = Post()
        post.published = datetime.now()
        form.populate_obj(post)
        db.session.add(post)
        db.session.commit()

        return redirect(url_for('news.view_post', post_id=post.id))

    context = dict(
        form=form,
    )

    return render_template('edit_post.html', **context)