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)
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'])
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']))
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))
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))
def forum(forum_path): try: return render_template('forum.html', forum=get_forum_by_path(forum_path)) except IndexError: raise
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)