Exemplo n.º 1
0
def comment_edit(comment_id):
    comment = Comment.query.get(comment_id)

    if current_user.id != comment.author_id:
        return redirect("/")

    if not comment:
        return redirect("/")

    # If the script this comment belongs to doesn't exist, delete it.
    s = Script.query.get(comment.script_id)
    if not s:
        db.session().delete(comment)
        db.session().commit()

    form = CommentForm(request.form)

    if not form.validate():
        return render_template("comments/edit.html",
                               comment=comment,
                               current_user=current_user,
                               commentForm=form)

    comment.title = request.form.get("title")
    comment.content = request.form.get("content")

    db.session().commit()

    return redirect(url_for("comment_show", comment_id=comment.id))
Exemplo n.º 2
0
def comments_edit(comment_id):
    comment = Comment.query.get(comment_id)
    if not comment.owner_id == current_user.id:
        return redirect(url_for("oops", error="Not authorized"))

    if request.method == "GET":
        return render_template("comments/edit.html",
                               comment_id=comment_id,
                               form=CommentForm(
                                   MultiDict({"content": comment.content})),
                               redir=request.args.get("redir"),
                               redir_id=request.args.get("redir_id"))

    form = CommentForm(request.form)
    if not form.validate():
        return render_template("comments/edit.html",
                               comment_id=comment_id,
                               form=form,
                               redir=request.args.get("redir"),
                               redir_id=request.args.get("redir_id"))

    comment.content = form.content.data
    db.session().commit()

    return try_redirect("comments_conversation", id=comment.post_id)
Exemplo n.º 3
0
def comments_conversation(id):
    post = Post.query.get(id)
    if not post:
        return redirect(url_for("oops", error="Post not found"))

    if request.method == "GET":
        return render_template("comments/conversation.html",
                               post=post,
                               form=CommentForm(),
                               **request.args)

    form = CommentForm(request.form)
    if not form.validate():
        return render_template("comments/conversation.html",
                               post=post,
                               form=form,
                               **request.args)

    content = re.sub(r"^\s+", "", form.content.data,
                     flags=re.MULTILINE).strip()
    comment = Comment(content, owner_id=current_user.id, post_id=id)
    db.session().add(comment)
    db.session().commit()

    return redirect(
        url_for("comments_conversation",
                id=id,
                back=request.args.get("back"),
                back_id=request.args.get("back_id")))
Exemplo n.º 4
0
def comments_edit(post_id, comment_id):
    if request.method == 'GET':
        return redirect(
            f'{url_for("posts_details", post_id=post_id)}#{comment_id or ""}')

    comment = Comment.query.get(comment_id)

    if (comment.account_id != current_user.id or comment.deleted):
        return redirect(url_for('posts_details', post_id=post_id))

    form = CommentForm(request.form)

    if not form.validate():
        return redirect(url_for('posts_details', post_id=post_id))

    parent = Comment.query.get(comment_id) if comment_id else None

    if parent and not str(parent.post_id) == post_id:
        return redirect(url_for('posts_details', post_id=post_id))

    with session_scope() as session:
        comment.content = form.content.data
        session.commit()

        return redirect(
            f'{url_for("posts_details", post_id=post_id)}#{comment.id}')
Exemplo n.º 5
0
def comments_create(post_id, comment_id):
    if request.method == 'GET':
        return redirect(
            f'{url_for("posts_details", post_id=post_id)}#{comment_id or ""}')

    form = CommentForm(request.form)

    if not form.validate():
        return redirect(url_for('posts_details', post_id=post_id))

    parent = Comment.query.get(comment_id) if comment_id else None

    if parent and (str(parent.post_id) != post_id or parent.deleted):
        return redirect(url_for('posts_details', post_id=post_id))

    comment = Comment(form.content.data)
    comment.account_id = current_user.id
    comment.post_id = post_id
    comment.parent_id = comment_id

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

        return redirect(
            f'{url_for("posts_details", post_id=post_id)}#{comment.id}')
Exemplo n.º 6
0
def update_comment(PostId):
    comment = Comment.query.get(request.form.get("comment_to_update"))

    if not current_user.id == comment.account.id:
        p = Post.query.get(PostId)

        return render_template(
            "comments/comments.html",
            PostName=p.postName,
            Comments=p.comments,
            PostID=p.id,
            form=CommentForm(),
            error="You are trying to edit a comment you did not make!")

    form = CommentForm(request.form)

    if not form.validate():
        return render_template("comments/updateCommentForm.html",
                               PostId=PostId,
                               CommentId=request.form.get("comment_to_update"),
                               form=form)

    comment.commentContent = form.comment.data
    db.session().commit()

    return redirect(url_for("show_comments", PostId=PostId))
Exemplo n.º 7
0
def comments_create(submission_id):
    form = CommentForm(request.form)
    if form.validate():
        comment = Comment(form.text.data)
        comment.account_id = current_user.id
        comment.submission_id = submission_id
        db.session().add(comment)
        db.session().commit()
    return redirect(url_for('submissions_view', submission_id=submission_id))
Exemplo n.º 8
0
def send_comment(event_id):
    form = CommentForm(request.form)
    event = Event.query.get(event_id)

    if form.validate():
        comment = Comment(form.content.data, event.id, current_user.id)

        db.session().add(comment)
        db.session().commit()

    return redirect(url_for('event_show', event_id=event.id))
Exemplo n.º 9
0
def memes_comment(meme_id):
    form = CommentForm()
    meme = Meme.query.get(meme_id)

    if form.validate_on_submit():
        comment = Comment(form.text.data, current_user.id, meme.id)

        db.session().add(comment)
        db.session().commit()

    return redirect(url_for("memes_index"))
Exemplo n.º 10
0
def comment_edit_post(comment_id):
    comment = Comment.query.get(comment_id)
    if(current_user.id != comment.user_id):
        return threadviews.threads_index()
    form = CommentForm(request.form)
    
    if not form.validate():
        return render_template("comments/editcomment.html", comment = comment, form = form)
    
    comment.comment_text = form.comment.data
    db.session().commit()
    return threadviews.threads_open(comment.thread_id)
Exemplo n.º 11
0
def comment_edit(post_id, comment_id):
    form = CommentForm(request.form)
    if not form.validate():
        return render_template("/posts/post.html",
                               form=PostForm(),
                               post=Post.query.get(post_id),
                               commentform=form)
    c = Comment.query.get(comment_id)
    if c.account_id == current_user.id:
        c.content = form.comment.data
        db.session().commit()

    return redirect(url_for('post_specific', post_id=post_id))
Exemplo n.º 12
0
def comment_create(recipe_id):
    form = CommentForm(request.form)
    if not form.validate():
        return render_template("recipes/<recipe_id>/", form=form)

    c = Comment(form.text.data)
    c.account_id = current_user.id
    c.recipe_id = recipe_id

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("recipes/<recipe_id>/"))
Exemplo n.º 13
0
def comment_create(recipe_id):
    form = CommentForm(request.form)
    if not form.validate():
        return redirect(url_for('recipe_get', recipe_id=recipe_id))

    c = Comment(form.text.data)
    c.account_id = current_user.id
    c.recipe_id = recipe_id

    db.session().add(c)
    db.session().commit()

    return redirect(url_for('recipe_get', recipe_id=recipe_id))
Exemplo n.º 14
0
def comment_create(script_id):
    if not validate_script_id(script_id):
        return redirect(url_for("script_list"))

    form = CommentForm(request.form)

    if not form.validate():
        return redirect(url_for("script_show", script_id=script_id))

    c = Comment(form.title.data, form.content.data, current_user.id, script_id)

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("script_show", script_id=script_id))
Exemplo n.º 15
0
def conversation_view(conversation_id):
    form = CommentForm(request.form)
    if not form.validate():
        return render_template(
            "conversations/viewOne.html",
            t=Conversation.query.get(conversation_id),
            form=form,
            conversation_comments=Conversation.find_comments_for_conversation(
                conversation_id))
    return render_template(
        "conversations/viewOne.html",
        t=Conversation.query.get(conversation_id),
        form=form,
        conversation_comments=Conversation.find_comments_for_conversation(
            conversation_id))
Exemplo n.º 16
0
def comment_post(thread_id):
    form = CommentForm(request.form)
    
    if not form.validate():
        thread = Thread.query.get(thread_id)
        comments = thread.comments
        
        return render_template("threads/showthread.html", form = form, comments = comments, thread = thread, user = thread.user)

    comment = Comment(form.comment.data)
    comment.thread_id = thread_id
    comment.user_id = current_user.id
    db.session().add(comment)
    db.session().commit()

    return threadviews.threads_open(thread_id)
Exemplo n.º 17
0
def thread_show(thread_id):
    t = Thread.query.get(thread_id)

    if t:
        user_thread = UserThread(thread_id)

        if current_user.is_authenticated:
            user_thread.account_id = current_user.id

        db.session().add(user_thread)
        db.session().commit()

    comments = Comment.query.filter_by(thread_id=thread_id).all()
    comment_amount = Comment.threads_comments(thread_id)

    views = UserThread.how_many_viewers_a_thread_has(thread_id)
    unique_views = UserThread.how_many_unique_viewers_a_thread_has(thread_id)

    return render_template("threads/one.html",
                           thread=t,
                           views=views,
                           unique_views=unique_views,
                           commentForm=CommentForm(),
                           comment_amount=comment_amount,
                           comments=comments)
Exemplo n.º 18
0
def submissions_view(submission_id):
    s = Submission.query.get(submission_id)
    u = User.query.get(s.account_id)
    form = CommentForm(request.form)

    canDelete = False
    if current_user.is_authenticated:
        if s.account_id == current_user.id or current_user.admin == True:
            canDelete = True

    hasComments = True
    if Comment.query.filter_by(submission_id=submission_id).first() is None:
        hasComments = False

    canFeature = False
    if current_user.is_authenticated:
        if current_user.admin == True:
            canFeature = True

    featureText = 'Feature '
    featured = False
    if s.featured == True:
        featureText = 'Unfeature '
        featured = True

    return render_template("submissions/level.html",
                           submission=s,
                           account=u,
                           form=form,
                           comments2=Comment.get_comments(subid=submission_id),
                           canDelete=canDelete,
                           hasComments=hasComments,
                           canFeature=canFeature,
                           featureText=featureText,
                           featured=featured)
Exemplo n.º 19
0
def recipe_get(recipe_id):
    recipe = Recipe.query.get(recipe_id)
    comments = Comment.query.filter_by(recipe_id=recipe_id).all()
    username = User.query.get(recipe.account_id).username
    users = User.query.all()
    voted = False
    votes = Vote.query.filter_by(recipe_id=recipe_id).count()
    recipeCategories = RecipeCategory.query.filter_by(
        recipe_id=recipe_id).all()
    categories = []
    form = CommentForm(request.form)

    for recipeCategory in recipeCategories:
        category = Category.query.filter_by(
            id=recipeCategory.category_id).all()
        for item in category:
            categories.append(item.name)

    if current_user.is_authenticated:
        votedOnQuery = Vote.query.filter(
            Vote.account_id == current_user.id).all()
        for vote in votedOnQuery:
            if vote.recipe_id == recipe.id:
                voted = True

    return render_template("recipes/recipe.html",
                           recipe=recipe,
                           username=username,
                           comments=comments,
                           form=form,
                           users=users,
                           voted=voted,
                           votes=votes,
                           categories=categories)
Exemplo n.º 20
0
def script_show(script_id):
    if not validate_script_id(script_id):
        return render_template("errors/error404.html")

    s = Script.query.get(script_id)
    a = User.query.get(s.author_id)
    comments = find_comments_with_author_name(script_id)

    userrole = "guest"
    if current_user.is_authenticated and current_user.is_admin():
        userrole = "ADMIN"

    if current_user.is_authenticated:
        f = Favourite.query.filter_by(user_id=current_user.id,
                                      script_id=script_id).first()
        if f:
            favourited = True
        else:
            favourited = False
    else:
        favourited = False

    return render_template("scripts/single.html",
                           script=s,
                           current_user=current_user,
                           author=a.username,
                           commentForm=CommentForm(),
                           comments=comments,
                           role=userrole,
                           favourited=favourited)
Exemplo n.º 21
0
def comments_create():

    form = CommentForm(request.form)
    threadi = Thread.query.get(form.thread_id.data)

    if not form.validate():
        return redirect(url_for("show_thread", thread_id=threadi.id))

    comm = Comment(form.message.data)
    comm.account_id = current_user.id
    comm.thread_id = form.thread_id.data

    db.session().add(comm)
    db.session().commit()

    return redirect(url_for("show_thread", thread_id=threadi.id))
Exemplo n.º 22
0
def new_comment(post_id):

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

    c = Comment(form.comment.data)
    c.account_id = current_user.id
    c.post_id = post_id

    db.session.add(c)
    db.session.commit()

    return redirect(url_for('post_specific', post_id=post_id))
Exemplo n.º 23
0
def comment_create(recipe_id):
    form = CommentForm(request.form)
    recipe = Recipe.query.get(recipe_id)

    if not form.validate():
        return render_template("comments/new_comment.html",
                               form=form,
                               recipe_id=recipe.id)

    comment = Comment(form.comment_text.data)
    comment.account_id = current_user.id
    comment.recipe_id = recipe.id

    db.session().add(comment)
    db.session().commit()

    return redirect(url_for("recipes_show_single", recipe_id=recipe.id))
Exemplo n.º 24
0
def show_comments(PostId):
    p = Post.query.get(PostId)

    return render_template("comments/comments.html",
                           PostName=p.postName,
                           Comments=p.comments,
                           PostID=p.id,
                           form=CommentForm())
Exemplo n.º 25
0
def comments_create(matchID):
    form = CommentForm(request.form)

    if not form.validate():
        return render_template(
            "comments/list.html",
            form=form,
            matches=Match.query.filter_by(id=matchID),
            comments=Comment.query.filter_by(matchid=matchID))

    c = Comment(form.content.data, matchID)
    c.account_id = current_user.id
    c.name = current_user.username
    db.session().add(c)
    db.session().commit()
    return render_template("comments/list.html",
                           form=form,
                           matches=Match.query.filter_by(id=matchID),
                           comments=Comment.query.filter_by(matchid=matchID))
Exemplo n.º 26
0
def comments_delete(ID, matchId):
    form = CommentForm(request.form)

    c = Comment.query.get(ID)
    db.session.delete(c)
    db.session.commit()
    return render_template("comments/list.html",
                           form=form,
                           matches=Match.query.filter_by(id=matchId),
                           comments=Comment.query.filter_by(matchid=matchId))
Exemplo n.º 27
0
def comment_update(comment_id):
    commentToUpdate = Comment.query.filter_by(id=comment_id).first()
    recipe_id = commentToUpdate.recipe_id

    if commentToUpdate.account_id != current_user.id:
        return login_manager.unauthorized()

    form = CommentForm(request.form)

    if not form.validate():
        return render_template("recipes/commentedit.html", form=form)

    form = CommentForm(request.form)
    commentToUpdate.text = form.text.data

    db.session().add(commentToUpdate)
    db.session().commit()

    return redirect(url_for('recipe_get', recipe_id=recipe_id))
Exemplo n.º 28
0
def comment_show(comment_id):
    comment = Comment.query.get(comment_id)

    if current_user.id != comment.author_id:
        return render_template("errors/error404.html")

    return render_template("comments/edit.html",
                           comment=comment,
                           current_user=current_user,
                           commentForm=CommentForm())
Exemplo n.º 29
0
def comments_create(conversation_id):
    form = CommentForm(request.form)
    if not form.validate():
        return render_template(
            "conversations/viewOne.html",
            t=Conversation.query.get(conversation_id),
            form=form,
            conversation_comments=Conversation.find_comments_for_conversation(
                conversation_id),
            error=
            "Kommentin pituus tulee olla vähintään 1 merkki ja korkeintaan 512 merkkiä."
        )
    t = Comment(form.name.data)
    t.account_id = current_user.id
    t.conversation_id = conversation_id
    db.session().add(t)
    db.session().commit()

    return redirect(
        url_for("conversation_view", conversation_id=conversation_id))
Exemplo n.º 30
0
def create_comment(PostId):
    form = CommentForm(request.form)

    if not form.validate():
        p = Post.query.get(PostId)

        return render_template("comments/comments.html",
                               PostName=p.postName,
                               Comments=p.comments,
                               PostID=p.id,
                               form=form)

    newComment = Comment(form.comment.data)
    newComment.postId = PostId
    newComment.accountId = current_user.id

    db.session().add(newComment)
    db.session().commit()

    return redirect(url_for("show_comments", PostId=PostId))