Exemple #1
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}')
Exemple #2
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))
Exemple #3
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>/"))
Exemple #4
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))
Exemple #5
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)
Exemple #6
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)
Exemple #7
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))
Exemple #8
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)
Exemple #9
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")))
Exemple #10
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))
Exemple #11
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))
Exemple #12
0
def admin_show(event_id):
    event = Event.query.get(event_id)
    comments = Comment.find_comments_for_event(event_id)
    participants = Event.find_participants_for_event(event_id)

    return render_template("events/details.html",
                           event=event,
                           comments=comments,
                           participants=participants)
Exemple #13
0
def message_new_comment(channel_id, message_id):

    messageform = MessageForm(request.form)

    if not messageform.validate() or messageform.body.data.isspace():
        return redirect(
            url_for("message_index",
                    channel_id=channel_id,
                    message_id=message_id))

    comment = Comment(messageform.body.data, current_user.username)
    comment.message_id = message_id
    comment.account_id = current_user.id

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

    return redirect(
        url_for("message_index", channel_id=channel_id, message_id=message_id))
Exemple #14
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))
Exemple #15
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))
Exemple #16
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"))
Exemple #17
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))
Exemple #18
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))
Exemple #19
0
def single_account_index(account_id):
    account = Account.query.get(account_id)

    return render_template("auth/index.html",
        account = account, 
        accountform = AccountForm(),
        channels = Account.find_accounts_channels(account_id),
        my_channels=Channel.get_my_channels(account_id),
        all_channels=Channel.get_channels_where_not_in(account_id),
        public_channels=Channel.get_all_publics(),
        messages=Message.query.filter_by(account_id=account_id),
        comments=Comment.get_comment_message_and_channel_id(account_id))
Exemple #20
0
def accounts_update(account_id):

    accountform = AccountForm(request.form)

    # check if username is whitespaces only
    char1 = False
    email = False
    not_same = False

    messages = []
    messages.append("THESE ARE THE CONDITIONS YOU MUST PAST")
    messages.append("*username must be 2 character length")
    messages.append("*password must be 8 character length")
    messages.append("*motto must be 2 character length")
    messages.append("*email must be 6 character length and must be real email")

    # email check
    for c in accountform.email.data:
        if c == '@':
            char1 = True

        if char1 == True:
            if c == '.':
                email = True

    if not accountform.password.data == accountform.password2.data:
        messages.append("*password was not same")
        not_same = True

    if not accountform.validate() or email == False or accountform.username.data.isspace() or not_same == True:
        return render_template("auth/index.html",
                                accountform = AccountForm(),
                                errors = messages,
                                account=current_user,
                                my_channels=Channel.get_my_channels(current_user.id),
                                all_channels=Channel.get_channels_where_not_in(current_user.id),
                                channels=Account.find_accounts_channels(current_user.id),
                                public_channels=Channel.get_all_publics(),
                                messages=Message.query.filter_by(account_id=current_user.id),
                                comments=Comment.get_comment_message_and_channel_id(current_user.id))

    account = Account.query.get(account_id)

    account.username = accountform.username.data
    account.password = accountform.password.data
    account.motto = accountform.motto.data
    account.email = accountform.email.data

    db.session().commit()

    return redirect(url_for("single_account_index"))
Exemple #21
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))
Exemple #22
0
def show_thread(thread_id):
    thread = Thread.query.get(thread_id)
    if thread.hidden and not current_user.is_authenticated:
        print("NOT ALLOWED")
        return redirect(request.referrer)
    form = CommentForm()
    form.thread_id.data = thread.id
    return render_template(
        "threads/thread.html",
        thread=Thread.query.get(thread_id),
        owner=User.query.get(thread.account_id),
        comments=Comment.find_comments_with_thread(thread_id),
        form=form,
        tags=Tag.find_tags(),
        users=User.query.all(),
        threadtags=Tag.find_tags_with_thread(thread_id),
        section=Section.query.get(thread.section_id))
Exemple #23
0
def comment_update(comment_id):
    if request.method == 'GET':
        return render_template("comments/update.html",
                               form=CommentForm(request.form),
                               comment_id=comment_id,
                               t=Comment.query.get(comment_id))
    form = CommentForm(request.form)
    if not form.validate():
        return render_template("comments/update.html",
                               form=form,
                               comment_id=comment_id,
                               t=Comment.query.get(comment_id))
    d = Comment(form.name.data)
    c = Comment.query.get(comment_id)
    if current_user.id != c.account_id:
        return render_template("comments/list.html",
                               comments=Comment.query.all())
    uusiNimi = d.name
    c.name = uusiNimi
    db.session().commit()
    return redirect(
        url_for("conversation_view", conversation_id=c.conversation_id))
Exemple #24
0
def event_show(event_id):
    event = Event.query.get(event_id)
    comments = Comment.find_comments_for_event(event_id)
    attendees = Event.participant_count(event_id)
    account = User.query.get(current_user.id)

    # format dateinfo for template
    event.day = datetime.strftime(event.date_time, '%d.')
    event.month = datetime.strftime(event.date_time, '%B')
    event.time = datetime.strftime(event.date_time, '%H:%M')
    event.date = datetime.strftime(event.date_time, '%d.%m.%Y')

    if event in account.attending:
        userHasjoined = True
    else:
        userHasjoined = False

    return render_template("events/event.html",
                           event=event,
                           attendees=attendees,
                           comments=comments,
                           form=CommentForm(),
                           userHasjoined=userHasjoined)