Beispiel #1
0
def create():
    date = datetime.datetime.now()
    form = BlogPostForm()
    if form.validate_on_submit():
        filename = secure_filename(form.image.data.filename)
        form.image.data.save('project/static/images/' + filename)
        image_link = 'static/images/' + filename
        new_post = BlogPost(
            form.title_header.data,
            form.title_long.data,
            form.content.data,
            form.tag.data,
            date,
            image_link,
            current_user.id,
            form.author_name_manual.data
        )
        db.session.add(new_post)
        db.session.commit()
        flash('New entry was successfully posted. Thanks.')
        return redirect(url_for('home.create'))
    else:
        filename = None
        posts = db.session.query(BlogPost).all()
        return render_template(
            'create.html', posts=posts, form=form, error=error, filename=filename)
Beispiel #2
0
def editposts():
    error = None
    form = BlogPostForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            new_post = Post(
            	form.subject.data,
                form.header.data,
                form.digest.data,
                form.body.data,
            )
            db.session.add(new_post)
            db.session.commit()
            flash(u'پست ثبت شد!!')
    return render_template('postedit.html', form=form, error=error)
Beispiel #3
0
def editposts():
    error = None
    form = BlogPostForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            new_post = Post(
                form.subject.data,
                form.header.data,
                form.digest.data,
                form.body.data,
            )
            db.session.add(new_post)
            db.session.commit()
            flash(u'پست ثبت شد!!')
    return render_template('postedit.html', form=form, error=error)
Beispiel #4
0
def save():
    form = BlogPostForm()
    if form.validate_on_submit():
        if request.form['action'] == 'draft':
            print('Saving to redis')
            redis_client.set(form.title.data, form.body.data)
        else:
            print('Saving to postgres')
            model = Post()
            model.title = form.title.data
            model.body = form.body.data
            model.date = form.date.data
            model.author = form.author.data
            db.session.add(model)
            db.session.commit()
    return render_template('new.html', form=form)
Beispiel #5
0
def create():
    date = datetime.datetime.now()
    form = BlogPostForm()
    if form.validate_on_submit():
        filename = secure_filename(form.image.data.filename)
        form.image.data.save('project/static/images/' + filename)
        image_link = 'static/images/' + filename
        new_post = BlogPost(form.title_header.data, form.title_long.data,
                            form.content.data, form.tag.data, date, image_link,
                            current_user.id, form.author_name_manual.data)
        db.session.add(new_post)
        db.session.commit()
        flash('New entry was successfully posted. Thanks.')
        return redirect(url_for('home.create'))
    else:
        filename = None
        posts = db.session.query(BlogPost).all()
        return render_template('create.html',
                               posts=posts,
                               form=form,
                               error=error,
                               filename=filename)