Exemplo n.º 1
0
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("Your post has been created", "success")
        return redirect(url_for('home'))
    return render_template("create_post.html",
                           title="New Post",
                           form=form,
                           legend="New post")
Exemplo n.º 2
0
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('Your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
Exemplo n.º 3
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.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('post', post_id=post.id))
    elif request.method == 'GET':
        form.title.data = post.title
        form.content.data = post.content
Exemplo n.º 4
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        flash(f'Post Saved', 'sucess')
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        return redirect(url_for('newsfeed'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
Exemplo n.º 5
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data, year=form.year.data, picture=form.picture.data,
                     description=form.description.data, author=current_user)
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.receipt_file = picture_file
        db.session.add(post)
        db.session.commit()
        flash('Portfolio work has been uploaded!', 'success')
        return redirect(url_for('portfolio'))
    return render_template('portfolio.html', title='New Portfolio Work',
                         form=form, legend='New portfolio work')
Exemplo n.º 6
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        user = User.objects(username=current_user.username).first()
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=user)
        post.save()
        flash('Your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title="New Post",
                           form=form,
                           legend="Create New Post")
Exemplo n.º 7
0
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('Votre publication à bien été créé !', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='Nouvelle Publication')
Exemplo n.º 8
0
def new_post():
    """"Create a post and add to database"""
    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('Your post has been created!', 'success')
        return redirect(url_for('homepage'))
    return render_template("create_form.html",
                           title="Create a Post",
                           form=form)
Exemplo n.º 9
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title = form.title.data, location = form.location.data, phone_no = form.phone_no.data,  content= form.content.data, author= current_user)
        print('Location', file=sys.stderr)
        print(form.location.data, file=sys.stderr)
        geolocator = Nominatim(user_agent="app")
        location = geolocator.geocode(form.location.data)
        print(location.latitude, location.longitude, file=sys.stderr)
        post.location2 = str(location.latitude)+','+str(location.longitude)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html', title= 'New Post', form=form)
Exemplo n.º 10
0
def update_post(id):
    post=Post.query.get_or_404(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('Post have been updated', 'success')
        return redirect(url_for('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",post=post,form=form, legend='Update Post')
Exemplo n.º 11
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        #Here we have used author as a back reference to author of the post (check out models.py for details)
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash("Post Created!", "success")
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='Update Post')
Exemplo n.º 12
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.title = form.title.data
        post.content = form.content.data
        db.session.commit()
    form.title.data = post.title
    form.content.data = post.content
    return render_template('new_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')
Exemplo n.º 13
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():           # Check if the user is logged in or not
        post.title = form.title.data      # To Update Post Title
        post.content = form.content.data  # To Update Post Content
        db.session.commit()
        flash ('Your post has been updated!', 'success')  # Flash a message
        return redirect(url_for('post', post_id=post.id))
    elif request.method == 'GET':
        form.title.data = post.title      # Populate the input field
        form.content.data = post.content  # Populate the input field
    return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
Exemplo n.º 14
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.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('El post se actualizo correctamente', 'success')
        return redirect(url_for('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='Actualizar', form=form, legend='Modificar Post')
Exemplo n.º 15
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    bg=form.bg.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('your post has successfully posted.', 'success')
        return redirect(url_for('posts.new_post'))
    return render_template('create_post.html',
                           title='new_post',
                           form=form,
                           legend='create post')
Exemplo n.º 16
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(client_name=form.client_name.data, client_or_saggezza=form.client_or_saggezza.data, client_project=form.client_project.data, date=form.date.data, billable_to=form.billable_to.data,
                     payment=form.payment.data, receipt=form.receipt.data, category=form.category.data, description=form.description.data, GBP=form.GBP.data, EUR=form.EUR.data, USD=form.USD.data, author=current_user)
        post.verify_or_decline = 'pending'
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.receipt_file = picture_file
        db.session.add(post)
        db.session.commit()
        flash('Expense has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html', title='New Post',
                         form=form, legend='New Post')
Exemplo n.º 17
0
def post_update(post_id):
    form = PostForm()
    post=Post.query.get_or_404(post_id)# if doesnt exist then 404
    if post.author.username!=current_user.username:
        abort(403)# forbidden operation
    if form.validate_on_submit():
        post.title=form.title.data
        post.content=form.content.data
        db.session.commit()
        flash('Your post has been updated','success')
        return redirect(url_for('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', form=form,legend="Update Post")
Exemplo n.º 18
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.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash("Your post has been updated !", "success")
        return redirect(url_for("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")
Exemplo n.º 19
0
def post_update(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('Your Post has been Updated', 'success')
        return redirect(url_for('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)
Exemplo n.º 20
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.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Post updated successfully', 'success')
        return redirect(url_for('home'))
    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')
Exemplo n.º 21
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.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Пост был обновлен!', 'success')
        return redirect(url_for('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', form=form, title='Изменить пост', legend='Изменить пост')
Exemplo n.º 22
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post3(title=form.title.data,
                     content=form.content.data,
                     author=current_user.username,
                     user_id=current_user.id,
                     image_file=current_user.image_file)
        db.session.add(post)
        db.session.commit()
        flash('Your Post has been created', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Notification')
Exemplo n.º 23
0
def new_post():
    form = PostForm()

    if not current_user:
        return redirect(url_for('main.login'))

    if form.validate_on_submit():
        new_post = Post(id=str(uuid4()), title=form.title.data)
        new_post.text = form.text.data
        new_post.publish_date = datetime.now()

        db.session.add(new_post)
        db.session.commit()
        return redirect(url_for('blog.home'))

    return render_template('new_post.html', form=form)
Exemplo n.º 24
0
def update_post(post_id):
  post = Post.query.get_or_404(post_id)
  if post.author != current_user:
    abort(403) # http response for a forbidden route
  form = PostForm()
  if form.validate_on_submit():
    post.title = form.title.data
    post.content = form.content.data
    db.session.commit()
    # don't need to use db.session since the data is already in the database
    flash('Your post has been updated!', 'success')
    return redirect(url_for('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, author=current_user, legend='Update Post')
Exemplo n.º 25
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():
        picture_file = save_post_picture(form.picture.data)
        post = Post(title=form.title.data, content=form.content.data, author=current_user, picture_post=picture_file)
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('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')
Exemplo n.º 26
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.food = form.food.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('home2', post_id=post.id))
    elif request.method == 'GET':
        form.food.data = post.food
    return render_template('create_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')
Exemplo n.º 27
0
def update_post(post_id):
    form = PostForm()
    post= Post.query.get(post_id)
    if current_user != post.author:
        abort(403)
    if form.validate_on_submit():
        post.title= form.title.data
        post.description = form.description.data
        #db.session.add(post)
        db.session.commit()  
        flash('Your Post has been updated','success')
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.title.data = post.title
        form.description.data = post.description
    return render_template('create_post.html',title=f'Update Post {post_id}', form = form, heading = 'Update Post')
Exemplo n.º 28
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id) #get post if exist, if not return 404
    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('Your post has been updated!', category='success')
        return redirect(url_for('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')
Exemplo n.º 29
0
def edit_post(post_id):
    form = PostForm()
    post = Post.query.get_or_404(post_id)  # 先从数据库拿到post对象
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        post.category = Category.query.get(form.category.data)
        db.session.commit()  # 注意!flask SQLAlchemy修改数据时不需要添加db.session.add()语句
        flash('更新文章成功!', 'success')
        # 编辑完后回到显示该文章内容页面
        return redirect(url_for('my_blog.show_post', post_id=post.id))

    form.title.data = post.title
    form.body.data = post.body
    form.category.data = post.category_id
    return render_template('admin/edit_post.html', form=form)
Exemplo n.º 30
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        #        post = Post(title=form.title.data, content=form.content.data, user_id=current_user.id)
        post = Post(title=form.title.data,
                    content=form.content.data,
                    date_posted=datetime.utcnow(),
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Post added Sucessfully!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='Create Post')