示例#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
文件: main.py 项目: Khady/snakenest
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_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'])
示例#4
0
文件: main.py 项目: Khady/snakenest
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 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']))
示例#6
0
文件: main.py 项目: Khady/snakenest
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']))
示例#7
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))
示例#8
0
文件: main.py 项目: Khady/snakenest
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))
示例#9
0
def forum(forum_path):
    try:
        return render_template('forum.html',
                               forum=get_forum_by_path(forum_path))
    except IndexError:
        raise
示例#10
0
def thread(forum_path=None, id_thread=None):
    forum = get_forum_by_path(forum_path)
    t = [x for x in forum['threads'] if str(x['_id']) == id_thread][0]
    return render_template('thread.html', forum=forum, thread=t)
示例#11
0
文件: main.py 项目: Khady/snakenest
def forum(forum_path):
    try:
        return render_template('forum.html', forum=get_forum_by_path(forum_path))
    except IndexError:
        raise
示例#12
0
文件: main.py 项目: Khady/snakenest
def thread(forum_path=None, id_thread=None):
    forum = get_forum_by_path(forum_path)
    t = [x for x in forum['threads'] if str(x['_id']) == id_thread][0]
    return render_template('thread.html',
            forum=forum,
            thread=t)