예제 #1
0
def adddog():
    '''
    Post page
    '''
    form = PostForm()
    if request.method == 'POST' and form.validate_on_submit():

        new = Post(title=form.title.data,
                   text=form.post.data,
                   user=current_user,
                   gender=form.gender.data,
                   age=form.age.data)
        for split in form.tags.data.split(' '):
            tag = Tag.query.filter_by(tag_name=split).first()
            if tag is not None:
                new.tags.append(tag)

        images = request.files.getlist("upload")
        for img in images:
            ext = img.filename.split(".")[1]
            filename = str(int(time.time() * 1e6) +
                           randint(300, 43242)) + '.' + ext
            image_file = os.path.join(APP.config['UPLOAD_FOLDER'], filename)
            img.save(image_file)
            new.images.append(Image(name=filename))

        DB.session.add(new)
        DB.session.commit()
        return redirect(url_for('index'))
    return render_template('post.html', form=form, tags=TAGS)
예제 #2
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        form.post.author_id = current_user.id
        db.session.add(form.post)
        db.session.commit()
        fragment.reset(posts_list)
        fragment.reset(user_info, current_user.id)
        flash('Your post has saved successfully.', 'info')
        return redirect(url_for('index'))
    return render_template('newpost.html', form=form)
예제 #3
0
파일: admin.py 프로젝트: ddkaty/flasklog
def create_post():
    form = PostForm(request.form)
    if form.validate_on_submit():
        post = Post(form.title.data, form.author.data,
                form.published.data, form.permalink.data)
        db.session.add(post)
        try:
            db.session.commit()
            flash("Post added successfully!")
        except Exception, e:
            flash("%s", e)

        return redirect(url_for("backend.backend_list"))
예제 #4
0
def create_post():
    form = PostForm(request.form)
    if form.validate_on_submit():
        post = Post(form.title.data, form.author.data, form.published.data,
                    form.permalink.data)
        db.session.add(post)
        try:
            db.session.commit()
            flash("Post added successfully!")
        except Exception, e:
            flash("%s", e)

        return redirect(url_for("backend.backend_list"))