Пример #1
0
def delete_forum(forum_path):
    parent_path = forum_path.split('/')[:-1]
    parent = get_forum_by_path('/'.join(parent_path))
    for i, x in enumerate(parent.forums):
        if x['name'] == forum_path.split('/')[-1]:
            parent['forums'].pop(i)
            break

    root.save()
    return redirect(parent_path)
Пример #2
0
def delete_forum(forum_path):
    parent_path = forum_path.split('/')[:-1]
    parent = get_forum_by_path('/'.join(parent_path))
    for i, x in enumerate(parent.forums):
        if x['name'] == forum_path.split('/')[-1]:
            parent['forums'].pop(i)
            break

    root.save()
    return redirect(parent_path)
Пример #3
0
def new_root_forum():
    c = connection['my_forum']
    forum = root

    if request.method == 'GET':
        return render_template('new_forum.html', forum=forum)

    elif request.method == 'POST':
        new_forum = c.forums.Forum()
        new_forum.name = request.form['name']
        forum.forums.append(new_forum)
        root.save()

        return redirect(request.form['name'])
Пример #4
0
def new_forum(forum_path):
    c = connection['my_forum']
    forum = get_forum_by_path(forum_path)

    if request.method == 'GET':
        return render_template('new_forum.html', forum=forum)

    elif request.method == 'POST':
        new_forum = c.forums.Forum()
        new_forum.name = request.form['name']
        forum['forums'].append(new_forum)
        root.save()

        return redirect('/' + forum_path + '/' + request.form['name'])
Пример #5
0
def new_root_forum():
    c = connection['my_forum']
    forum = root

    if request.method == 'GET':
        return render_template('new_forum.html', forum=forum)

    elif request.method == 'POST':
        new_forum = c.forums.Forum()
        new_forum.name = request.form['name']
        forum.forums.append(new_forum)
        root.save()

        return redirect(request.form['name'])
Пример #6
0
def new_forum(forum_path):
    c = connection['my_forum']
    forum = get_forum_by_path(forum_path)

    if request.method == 'GET':
        return render_template('new_forum.html', forum=forum)

    elif request.method == 'POST':
        new_forum = c.forums.Forum()
        new_forum.name = request.form['name']
        forum['forums'].append(new_forum)
        root.save()

        return redirect('/' + forum_path + '/' + request.form['name'])
Пример #7
0
def respond(forum_path=None, id_thread=None):
    c = connection['my_forum']
    forum = get_forum_by_path(forum_path)
    t = [x for x in forum['threads'] if str(x['_id']) == id_thread][0]
    if request.method == 'GET':
        # XXX
        return redirect('/' + forum_path + '/thread/' + str(t['_id']))

    elif request.method == 'POST':
        if not t['locked']:
            user = connection['my_forum'].users.User.find_one(
                {'name': session['username']})

            comment = c.comments.Comment()
            comment.author = user._id
            comment.text = request.form['text']
            comment.creation_date = datetime.today()
            t['comments'].append(comment)
            root.save()

        return redirect('/' + forum_path + '/thread/' + str(t['_id']))
Пример #8
0
def respond(forum_path=None, id_thread=None):
    c = connection['my_forum']
    forum = get_forum_by_path(forum_path)
    t = [x for x in forum['threads'] if str(x['_id']) == id_thread][0]
    if request.method == 'GET':
        # XXX
        return redirect('/' + forum_path + '/thread/' + str(t['_id']))

    elif request.method == 'POST':
        if not t['locked']:
            user = connection['my_forum'].users.User.find_one(
                    {'name': session['username']})

            comment = c.comments.Comment()
            comment.author = user._id
            comment.text = request.form['text']
            comment.creation_date = datetime.today()
            t['comments'].append(comment)
            root.save()

        return redirect('/' + forum_path + '/thread/' + str(t['_id']))
Пример #9
0
def respond_arbitraty_thread(id_thread=None):
    c = connection['my_forum']
    t = search_thread(id_thread, root)

    if not t:
        abort(404)

    if request.method == 'GET':
        # XXX
        return redirect('/thread/' + str(t['_id']))

    elif request.method == 'POST':
        if not t['locked']:
            user = connection['my_forum'].users.User.find_one(
                {'name': session['username']})

            comment = c.comments.Comment()
            comment.author = user._id
            comment.text = request.form['text']
            comment.creation_date = datetime.today()
            t['comments'].append(comment)
            root.save()

        return redirect('/thread/' + str(id_thread))
Пример #10
0
def new_thread(forum_path):
    c = connection['my_forum']
    forum = get_forum_by_path(forum_path)

    if request.method == 'GET':
        return render_template('new_thread.html', forum=forum)

    elif request.method == 'POST':
        user = connection['my_forum'].users.User.find_one(
            {'name': session['username']})

        new_thread = c.threads.Thread()
        new_thread._id = ObjectId()
        new_thread.title = request.form['title']
        new_thread.pinned = False
        comment = c.comments.Comment()
        comment.author = user._id
        comment.text = request.form['text']
        comment.creation_date = datetime.today()
        new_thread.comments.append(comment)
        forum.threads.append(new_thread)
        root.save()

        return redirect('/' + forum_path + '/thread/' + str(new_thread._id))
Пример #11
0
def respond_arbitraty_thread(id_thread=None):
    c = connection['my_forum']
    t = search_thread(id_thread, root)

    if not t:
        abort(404)

    if request.method == 'GET':
        # XXX
        return redirect('/thread/' + str(t['_id']))

    elif request.method == 'POST':
        if not t['locked']:
            user = connection['my_forum'].users.User.find_one(
                    {'name': session['username']})

            comment = c.comments.Comment()
            comment.author = user._id
            comment.text = request.form['text']
            comment.creation_date = datetime.today()
            t['comments'].append(comment)
            root.save()

        return redirect('/thread/' + str(id_thread))
Пример #12
0
def new_thread(forum_path):
    c = connection['my_forum']
    forum = get_forum_by_path(forum_path)

    if request.method == 'GET':
        return render_template('new_thread.html', forum=forum)

    elif request.method == 'POST':
        user = connection['my_forum'].users.User.find_one(
                {'name': session['username']})

        new_thread = c.threads.Thread()
        new_thread._id = ObjectId()
        new_thread.title = request.form['title']
        new_thread.pinned = False
        comment = c.comments.Comment()
        comment.author = user._id
        comment.text = request.form['text']
        comment.creation_date = datetime.today()
        new_thread.comments.append(comment)
        forum.threads.append(new_thread)
        root.save()

        return redirect('/'+ forum_path + '/thread/' + str(new_thread._id))