コード例 #1
0
def update_post(post_id):
    session["images"] = []
    post = Posts.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)

    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.text = form.text.data
        post.county = form.county.data
        post.quadrature = form.quadrature.data
        post.price = form.price.data
        post.property_type = form.property_type.data
        post.sale_rent = form.sale_rent.data

        if form.property_pics.data:
            if str(form.property_pics.data
                   ) == "[<FileStorage: '' ('application/octet-stream')>]":
                session["images"].append(post.property_pictures)

            else:
                piclist = form.property_pics.data
                for pic in piclist:
                    file_picture = save_picture(pic)
                    post.property_pictures = file_picture
                    session["images"].append(post.property_pictures)

        post.property_pictures = session["images"]
        post.property_pictures = ",".join(post.property_pictures)
        db.session.commit()
        flash("Your post has been updated!")
        return redirect(
            url_for("core.home", post_id=post.id,
                    images=session["images"]))  #, post_list2=post_list2

    elif request.method == "GET":
        form.title.data = post.title
        form.text.data = post.text
        form.county.data = post.county
        form.quadrature.data = post.quadrature
        form.price.data = post.price
        form.property_type.data = post.property_type
        form.property_pics.data = post.property_pictures
        form.sale_rent.data = post.sale_rent

    post_list = post.property_pictures.split(",")
    pic_prop = url_for("static",
                       filename="property_pictures/" + post.property_pictures)
    return render_template("create_post.html",
                           form=form,
                           post_list=post_list,
                           images=session["images"],
                           pic_prop=pic_prop)
コード例 #2
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(patient=form.patient.data,
                    condition=form.condition.data,
                    medication=form.medication.data,
                    description=form.description.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_post.html', title='New Post', form=form)
コード例 #3
0
ファイル: routes.py プロジェクト: thieu1995/prosolorg-pjf
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash(u"Your post has been created!", "success")
        return redirect(url_for("main.home"))
    return render_template("create_post.html",
                           title="New Post",
                           form=form,
                           legend="New Post")
コード例 #4
0
ファイル: views.py プロジェクト: adyouri/kalima
def add_post():
    form = PostForm()
    if request.method == "POST":
        if form.validate_on_submit():
            title = form.title.data
            description = form.description.data
            #category = Category.query.filter_by(name = form.category.data).first()
            category_name = form.category.data
            tags = form.tags.data.split(" ")
            user_id = current_user.id
            post = BlogPost(title=title,
                            description=description,
                            author_id=user_id)
            db.session.add(post)
            db.session.commit()
            add_category(category_name=category_name, post=post)
            add_tags(tags=tags, post=post)
            """
            if category:
                category_id = category.id
                post = BlogPost(title, description, user_id, category_id)
            else:
                db.session.add(Category(form.category.data))
                db.session.commit()
                flash("Added New category")
                category_id = Category.query.filter_by(name = form.category.data).first().id
                post = BlogPost(title, description, user_id, category_id)
            ### tag ----------------
            tags = form.tags.data.split(" ")
            # check if tag exists and if it is already added to the post (Ugly, refactor it): 
            for tag in tags:
                t = Tag(tag)
                tag_exists = Tag.query.filter_by(name = tag).first()
                if tag_exists:
                        if tag_exists not in post.tags:
                            post.tags.append(tag_exists)
                        else:
                            pass
                else:
                    db.session.add(t)
                    post.tags.append(t)
                    db.session.commit()
            db.session.add(post)

            ### endtag -------------
            """
            db.session.commit()
            flash("Added New Post")
            return redirect(url_for("posts.post_by_id", id=post.id))
    return render_template("add_post.html", form=form)
コード例 #5
0
def create_post():
    session["images"] = []
    form = PostForm()
    if form.validate_on_submit():

        post = Posts(title=form.title.data,
                     text=form.text.data,
                     county=form.county.data,
                     quadrature=form.quadrature.data,
                     price=form.price.data,
                     property_type=form.property_type.data,
                     property_pictures=form.property_pics.data,
                     sale_rent=form.sale_rent.data,
                     user_id=current_user.id)

        if str(form.property_pics.data
               ) == "[<FileStorage: '' ('application/octet-stream')>]":
            default = "default_prop.png"
            post.property_pictures = default
            session["images"].append(post.property_pictures)

        else:
            piclist = form.property_pics.data
            for pic in piclist:
                file_picture = save_picture(pic)
                post.property_pictures = file_picture
                session["images"].append(post.property_pictures)

        post.property_pictures = session["images"]
        post.property_pictures = ",".join(post.property_pictures)

        db.session.add(post)
        db.session.commit()
        flash("Your post is created!")

        return redirect(
            url_for("posts.read_post",
                    post=post,
                    post_id=post.id,
                    images=session["images"]))
    picture_file = url_for("static",
                           filename="profile_pictures/" +
                           current_user.profile_picture)
    return render_template("create_post.html",
                           form=form,
                           picture_file=picture_file)
コード例 #6
0
ファイル: routes.py プロジェクト: thieu1995/prosolorg-pjf
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash(u"Your post has been updated!", "success")
        return redirect(url_for("posts.post", post_id=post.id))
    elif request.method == 'GET':
        form.title.data = post.title
        form.content.data = post.content
    return render_template("create_post.html",
                           title="Update Post",
                           form=form,
                           legend="Update Post")
コード例 #7
0
ファイル: views.py プロジェクト: divyaoswal/HelpLocals
def new(user_id):
    post_form = PostForm(request.form)
    if request.method == 'POST':
        if post_form.validate_on_submit():
            post_obj = Post(contactName=request.form['contactName'],
                            phoneNo=request.form['phoneNo'],
                            address=request.form['address'],
                            title=request.form['title'],
                            description=request.form['description'],
                            user_id=user_id)
            db.session.add(post_obj)
            db.session.commit()
            return redirect(
                url_for('images.upload_files',
                        user_id=user_id,
                        post_id=post_obj.id))
    return render_template('posts/new.html',
                           user_id=user_id,
                           post_form=post_form)
コード例 #8
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.patient = form.patient.data
        post.condition = form.condition.data
        post.medication = form.medication.data
        post.description = form.description.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('posts.post', post_id=post.id))
    elif request.method == 'GET':
        form.patient.data = post.patient
        form.condition.data = post.condition
        form.medication.data = post.medication
        form.description.data = post.description
    return render_template('create_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')