Пример #1
0
def posts_create(thread_id):
  thread = Thread.query.get_or_404(thread_id)

  form = PostForm(request.form)

  if not form.validate():
    return render_template("posts/new.html",
      form = form,
      thread_id = thread_id,
      title = thread.title
    )

  try:
    thread.modification_time = db.func.current_timestamp()

    posted = Post(form.content.data)
    posted.account_id = current_user.id
    posted.thread_id = thread_id

    db.session().add(posted)
    db.session().commit()
    flash("Your comment was posted", "alert alert-info")
  except:
    db.session.rollback()
    flash("Error occurred, comment was not posted", "alert alert-danger")

  return redirect(url_for("posts_thread", thread_id=thread_id))
Пример #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)
Пример #3
0
def posts_edit(thread_id, post_id):
  post = Post.query.get_or_404(post_id)

  if post.account_id == current_user.id:
    form = PostForm(request.form)

    if not form.validate():
      return render_template("posts/edit_post.html",
        form = form, post = post
      )

    try:
      newContent = form.content.data
      post.content = newContent

      db.session().commit()

      flash("Post was edited", "alert alert-info")
    except:
      db.session.rollback()
      flash("Error occurred, changes were not saved", "alert alert-danger")

  else:
    flash("You are not authorized", "alert alert-danger")
    
  return redirect(url_for("posts_thread", thread_id=thread_id))
Пример #4
0
def posts_create(theme_num):

    form = PostForm(request.form)

    if not form.validate():
        return render_template("posts/write.html",
                               form=form,
                               theme_id=theme_num)

    b = Topic(form.topic.data)
    old_topic = Topic.query.filter_by(name=form.topic.data).first()

    if not old_topic:
        b.theme_id = theme_num
        db.session().add(b)
        db.session().commit()
        Subject = Topic.query.filter_by(name=form.topic.data).first()

        a = Post(request.form.get("content"))
        a.topic = form.topic.data
        a.author = current_user.name
        a.account_id = current_user.id
        a.subject_id = Subject.id
        db.session().add(a)

        db.session().commit()

        return redirect(url_for("topic_id", theme_id=theme_num))

    else:
        flash("Topic already taken!")
        return render_template("posts/write.html",
                               form=form,
                               error="Topic already taken!",
                               theme_id=theme_num)
Пример #5
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)
Пример #6
0
def posts_create():
    form = PostForm(request.form)

    if (form.add_tag.data):
        form.tags.append(form.tag.data)
        form.tag.data = ''
        return render_template("posts/new.html", form=form)

    if not form.validate():
        return render_template("posts/new.html", form=form)

    p = Post(form.name.data, form.content.data)
    p.user_id = current_user.id

    db.session().add(p)
    db.session().commit()

    for tag in form.tags:
        tagd = Tag.query.filter_by(name=tag).first()
        if not tagd:
            t = Tag(tag)
            db.session().add(t)
            db.session().commit()
            pt = PostTag(t.id, p.id)
        else:
            pt = PostTag(tagd.id, p.id)

        db.session().add(pt)
        db.session().commit()

    PostForm.tags = []

    return redirect(url_for("posts_index"))
Пример #7
0
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")
Пример #8
0
def posts_update(threadId, postId):
    dbPost = Post.query.get(postId)

    # Allowed: MASTER, ADMIN and USER own post
    if (current_user.userrole == "USER"
            and dbPost.account_id != current_user.id):
        return login_manager.unauthorized()

    if request.method == "GET":
        form = PostForm()
        form.message.data = dbPost.message
        return render_template("posts/update.html",
                               form=form,
                               threadId=threadId,
                               postId=postId)

    form = PostForm(request.form)
    if not form.validate():
        return render_template("posts/update.html",
                               form=form,
                               threadId=threadId,
                               postId=postId)

    dbPost.message = form.message.data
    db.session().commit()
    return redirect(url_for("threads_open", threadId=threadId))
Пример #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 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')
Пример #10
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')
Пример #11
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")
Пример #12
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')
Пример #13
0
def user_wall(id):
    user = User.query.get(id)
    subscriber_count = Subscription.query.filter_by(wall_id=user.wall.id).count()
    subscription_count = Subscription.query.filter_by(owner_id=user.id).count()
    post_count = Post.query.filter_by(owner_id=user.id).count()
    comment_count = Comment.query.filter_by(owner_id=user.id).count()

    if not user:
        return redirect(url_for("oops",
                                error="Invalid user ID"))

    if request.method == "GET":
        limit = 5
        older_than = request.args.get("older_than")
        if older_than == None:
            older_than = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)

        return render_template("wall/user_wall.html",
                               posts=Post.get_posts_for_user_wall(id,
                                                                  older_than=older_than,
                                                                  limit=limit),
                               user=user,
                               form=PostForm(),
                               limit=limit,
                               subscriber_count=subscriber_count,
                               subscription_count=subscription_count,
                               post_count=post_count,
                               comment_count=comment_count)

    form = PostForm(request.form)

    if not form.validate():
        return render_template("wall/user_wall.html",
                               posts=Post.get_posts_for_user_wall(id),
                               user=user,
                               form=form,
                               subscriber_count=subscriber_count,
                               subscription_count=subscription_count,
                               post_count=post_count,
                               comment_count=comment_count)

    content = re.sub(r"^\s+",
                     "",
                     form.content.data,
                     flags=re.MULTILINE).strip()
    owner_id = current_user.id
    wall_id = user.wall.id

    post = Post(content, owner_id, wall_id)
    db.session().add(post)
    db.session().commit()

    return redirect(url_for("user_wall",
                            id=id))
Пример #14
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')
Пример #15
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)
Пример #16
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')
Пример #17
0
def posts_create():
    form = PostForm(request.form)

    if not form.validate():
        return render_template("posts/list.html", posts = Post.query.filter_by(parent_id=None).order_by(Post.create_time.desc()).all(), hashtags = Hashtag.get_trending_hashtags(1, 5), form = form, show = True)

    post = Post(current_user.id, form.content.data, None)
  
    db.session().add(post)
    db.session().commit()
  
    return redirect(url_for("posts_index"))
Пример #18
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)
Пример #19
0
def posts_reply_to(post_id):
    form = PostForm(request.form)

    if not form.validate():
        post = Post.query.get(post_id)
        return render_template("posts/reply_to.html", post = post, form = form)

    post = Post(current_user.id, form.content.data, post_id)

    db.session().add(post)
    db.session().commit()

    return redirect(url_for("posts_thread", post_id = post_id))
Пример #20
0
def posts_create():
    form = PostForm(request.form)

    if not form.validate():
        return render_template("posts/new.html", form=form)

    post = Post(form.name.data)
    post.accountId = current_user.id

    db.session().add(post)
    db.session().commit()

    return redirect(url_for("posts_index"))
Пример #21
0
def posts_edit(post_id):
    post = Post.query.get(post_id)
    form = PostForm(request.form)

    post.title = form.title.data
    post.content = form.content.data

    if not form.validate():
        return render_template('posts/edit.html', post=post, form=form)

    with session_scope() as session:
        session.commit()

    return redirect(url_for('posts_details', post_id=post_id))
Пример #22
0
def posts_submit():
    form = PostForm(request.form)

    if not form.validate():
        return render_template('posts/submit.html', form=form)

    with session_scope() as session:
        post = Post(form.title.data, form.content.data)
        post.account_id = current_user.id

        session.add(post)
        session.commit()

    return redirect(url_for('posts_index'))
Пример #23
0
def post_edit(post_id):
    form = PostForm(request.form)

    if not form.validate():
        return render_template("/posts/post.html",
                               form=form,
                               post=Post.query.get(post_id),
                               commentform=CommentForm())
    p = Post.query.get(post_id)
    if p.account_id == current_user.id:
        p.content = form.content.data
        db.session().commit()

    return redirect(url_for('post_specific', post_id=post_id))
Пример #24
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)
Пример #25
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")
Пример #26
0
def post_create(thread_id):
    form = PostForm(request.form)
    form.content.data = escape(form.content.data)

    if not form.validate():
        return render_template("post/new.html", form=form, thread_id=thread_id)
    if not current_user.is_authenticated:
        flash("Authentication error")
        return redirect(url_for("category_index"))
    p = Post(form.content.data)
    p.account_id = current_user.id
    p.thread_id = thread_id
    db.session().add(p)
    db.session().commit()
    return redirect(url_for("thread_view", thread_id=thread_id))
Пример #27
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')
Пример #28
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)
Пример #29
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('create_post.html', title='New Post', form=form, legend = 'Update Post')
Пример #30
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')