def new_post():
    form = PostForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            post = Post(title=form.title.data,
                        content=form.content.data,
                        content_md=form.content_md.data,
                        author=current_user,
                        image_file=picture_file)
        else:
            post = Post(title=form.title.data,
                        content=form.content.data,
                        content_md=form.content_md.data,
                        author=current_user)
        db.session.add(post)
        current_user.post_title_saved = ''
        current_user.post_html_saved = ''
        current_user.post_md_saved = ''
        db.session.commit()
        flash("Post created!", 'success')
        return redirect(url_for('main.home'))
    return render_template("create_post.html",
                           title="New Post",
                           form=form,
                           legend="New Post")
Exemple #2
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    user_info = User_info.query.filter_by(user_id=current_user.id).first()
    get_warnings = AttendingEvent.query.filter(
        AttendingEvent.warning == 'warning').filter(
            AttendingEvent.user_id == current_user.id).all()
    user_warning = []
    for warning in get_warnings:
        event = Post.query.filter(Post.event_id == warning.event_id).first()
        user_warning.append(event)
    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()
        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',
                           form=form,
                           user_info=user_info,
                           user_warning=user_warning)
Exemple #3
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        url = form.youtube.data.replace("watch?v=", "embed/")
        if form.youtube.data == "":
            url = None
        if form.picture.data:
            image_file = save_picture(form.picture.data)
        if not form.picture.data:
            image_file = ""

        post = Post(title=form.title.data,
                    content=form.content.data,
                    youtube=url,
                    author=current_user,
                    image_file=image_file)
        db.session.add(post)
        db.session.commit()

        return redirect(url_for('posts.home'))
    user_info = User_info.query.filter_by(id=current_user.id).first()
    get_warnings = AttendingEvent.query.filter(
        AttendingEvent.warning == 'warning').filter(
            AttendingEvent.user_id == current_user.id).all()
    user_warning = []
    for warning in get_warnings:
        event = Post.query.filter(Post.event_id == warning.event_id).first()
        user_warning.append(event)
    return render_template('create_post.html',
                           form=form,
                           user_info=user_info,
                           user_warning=user_warning)
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 form has been submitted', 'success')
        return redirect(url_for('users.user_posts', username=current_user.username))
    return render_template('create_post.html', title='New Post', form=form, legend='New Post')
Exemple #5
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 successfully added', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_post.html', title="News Post", form = form, legend='New Post')
Exemple #6
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data, url=form.url.data,
                    content=form.content.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Váša otázka bola vytvorená a zverejnená', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_post.html', title='Opýtať sa otázku', form=form, legend='Opýtajte sa otázku')
Exemple #7
0
def create_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('main.index'))

    return render_template("posts/create_post.html", title="Create Post", form=form, legend="Create Post")
Exemple #8
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('Conteúdo publicado com sucesso!', 'success')
        return redirect(url_for('main.index'))
    return render_template('posting.html', title='Novas Postagens',
                           form=form, legend='Nova Postagem')
Exemple #9
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("main.home"))
    return render_template("create_post.html", title="New Post", form=form)
Exemple #10
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.body.data, user_id=current_user.id)
        db.session.add(post)
        db.session.commit()
        flash('¡Has dejado el mensaje', 'success')
        return redirect(url_for('main.debate'))
    return render_template('posts/create_post.html',
                           title='Nuevo Mensaje',
                           form=form,
                           legend='Nuevo Mensaje')
Exemple #11
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    category=dict(form.category.choices).get(
                        form.category.data),
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('main.index'))
    return render_template('posts/post_form.html', title='New Post', form=form)
Exemple #12
0
def new_post():
	form = PostForm()
	if form.validate_on_submit():
		post = Posts(title=form.title.data, content=form.content.data, author=current_user)
		db.session.add(post)
		db.session.commit()


		send_new_post_email(post)
		flash('Post created!', 'success')
		return redirect(url_for('main.home'))

	return render_template('create_post.html', title='New Post', 
							legend='Update Post', form=form)
Exemple #13
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', 'is-success')
        return redirect(url_for('posts.blog'))
    return render_template('pages/blogs/create_post.html',
                           title='New Post',
                           form=form,
                           legend="Creer un nouveau Post")
Exemple #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('Váša otázka bola úspešne upravená', '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='Upraviť otázku', form=form, legend='Upravte svoju otázku')
Exemple #15
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("posts.post", post_id=post.id))
    elif request.method == "GET":
        form.title.data = post.title
        form.content.data = post.content
    return render_template("update_post.html", title="Update Post", form=form)
Exemple #16
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.body = form.body.data
        db.session.commit()
        flash('¡Has modificado el mensaje!', 'success')
        return redirect(url_for('posts.post', post_id=post.id))
    elif request.method == 'GET':
        form.body.data = post.body
    return render_template('posts/create_post.html',
                           title='Editar mensaje',
                           form=form,
                           legend='Editar mensaje')
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('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='New Post', form=form, legend = 'Update Post')
Exemple #18
0
def update_post(post_id):
	post = Posts.query.get_or_404(post_id)
	if post.author != current_user and current_user.email != '*****@*****.**':
		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('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', 
							legend='Update Post', form=form)
Exemple #19
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)  # criar página de erro.
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash("Postagem atualizada com sucesso!", '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('posting.html',
                           title='Alterando Informações da Postagem',
                           form=form, legend='Alterar Informações')
Exemple #20
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(' Your Post has been update!', 'is-success')
        return redirect(url_for('posts.blog_show', id=post.id))
    elif request.method == 'GET':
        form.title.data = post.title
        form.content.data = post.content
    return render_template('pages/blogs/create_post.html',
                           title='Update Post',
                           form=form,
                           legend="Mise à jour du Post")
Exemple #21
0
def update_post(post_id):
	post = Post.query.get_or_404(post_id)
	if post.author != current_user:
		abort(403)

	form = PostForm()
	form.tags.choices = [(tag.name, tag.name) for tag in Tag.query.all()]
	if form.validate_on_submit():
		post.title = form.title.data
		post.draft = int(form.draft.data)

		content = form.content.data
		attachments = request.files.getlist(form.attachments.name)

		if attachments and all(f for f in attachments):
			for attachment in attachments:
				_, file_extension = os.path.splitext(attachment.filename)
				if file_extension in [".jpg", ".jpeg", ".png", ".tiff"]:
					saved_image_path = save_image(attachment)
					content = content.replace(attachment.filename, saved_image_path)
				else:
					flash(f"{attachment.filename}: This file is not supported.", "warning")
		post.content = content
		# post.content = markdown2.markdown(content)

		if form.thumbnail.data:
			post.thumbnail = save_thumbnail(form.thumbnail.data)

		for tag_name in form.tags.data:
			tag = Tag.query.filter_by(name=tag_name).first()
			tag.posts.append(post)

			if tag_name == "Featured": #max 3 most recent Featured posts at any given time
				tag.posts = tag.posts[-3:]
		db.session.commit() #We're updating something that is already in the database, so no need for db.session.add()
		flash("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
		form.draft.data = post.draft
	return render_template("create_post.html", title="Update Post", form=form, legend="Update Post")
Exemple #22
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    form.submit.label.text = 'Update'
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        post.category = dict(form.category.choices).get(form.category.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.title.data = post.title
        form.content.data = post.content
        form.category.data = post.category[0]
    return render_template('posts/post_form.html',
                           title='Update Post',
                           form=form)
Exemple #23
0
def update_post(post_id):
    event = Post.query.get_or_404(post_id)
    if event.author != current_user and not current_user.admin:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        event.title = form.title.data
        event.content = form.content.data
        event.content_md = form.content_md.data
        db.session.commit()
        flash("Post updated!", 'success')
        return redirect(url_for('posts.post', post_id=event.id))
    elif request.method == 'GET':
        form.title.data = event.title
        form.content.data = event.content
        form.content_md.data = event.content_md
    return render_template('create_post_update.html',
                           title="Update Post",
                           form=form,
                           legend="Update Post")
Exemple #24
0
def new_post():
	if current_user.role != "Admin":
		abort(403)

	form = PostForm()
	form.tags.choices = [(tag.name, tag.name) for tag in Tag.query.all()]
	if form.validate_on_submit():
		content = form.content.data
		attachments = request.files.getlist(form.attachments.name)

		if attachments and all(f for f in attachments):
			for attachment in attachments:
				_, file_extension = os.path.splitext(attachment.filename)
				if file_extension in [".jpg", ".jpeg", ".png", ".tiff", ".gif", ".mp4", ".mov"]:
					saved_image_path = save_image(attachment)
					content = content.replace(attachment.filename, saved_image_path)
				else:
					flash(f"{attachment.filename}: This file is not supported.", "warning")
		# content = markdown2.markdown(content)

		thumbnail_filename = save_thumbnail(form.thumbnail.data) if form.thumbnail.data else "default.jpg"

		post = Post(title=form.title.data, content=content, author=current_user, draft=int(form.draft.data), thumbnail=thumbnail_filename)

		for tag_name in form.tags.data:
			tag = Tag.query.filter_by(name=tag_name).first()
			tag.posts.append(post)

			if tag_name == "Featured": #max 3 most recent Featured posts at any given time
				tag.posts = tag.posts[-3:]

		db.session.add(post)
		db.session.commit()
		flash(f"Your post has been created! {form.draft.data} {type(form.draft.data)}", "success")
		return redirect(url_for("posts.post", post_id=post.id))

	return render_template("create_post.html", title="New Post", form=form)