def post_topic(board_id, board_name): board = Board.objects(board_id=board_id).first() if board is None: abort(404) forum = board.forum form = PostTopicForm(request.form) if request.method == 'GET': return render_template('forum_post_topic.html', board=board, forum=forum, form=form) elif request.method == 'POST': if not form.validate(): return render_template('forum_post_topic.html', board=board, forum=forum, form=form) topic = Topic(title=form.title.data, author=current_user.to_dbref(), forum=forum, board=board) topic_edit = TopicEdit(title=topic.title, date=topic.date, announcement=topic.announcement, author=topic.author) topic.edits.append(topic_edit) topic.save() post = Post(author=current_user.to_dbref(), content=form.content.data, topic=topic, forum=forum, date=topic.date, is_op=True) post_edit = PostEdit(author=post.author, content=post.content, date=post.date) post.edits.append(post_edit) post.save() topic.op = post topic.date = post.date topic.save() return redirect(topic.get_url())
def view_board_redirect(board_id): board = Board.objects(board_id=board_id).first() if board is None: abort(404) return redirect( url_for('forum.view_board', board_id=board_id, board_name=board.name.replace(' ', '_'), page=1))
def view_board(board_id, board_name, page): board = Board.objects(board_id=board_id).first() if board is None: abort(404) if not board_name == board.get_url_name(): return redirect(board.get_url()) forum = board.forum # Get our sorted topics and the number of topics. topics = Topic.objects(board=board).order_by('-last_post_date') topic_num = len(topics) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(topic_num / float(TOPICS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topics_display.html', board=board, forum=forum, topics=[], read_topics=[], forum_menu_current=board.id, **forum_template_data(forum)) abort(404) # Compile the list of topics we want displayed. display_topics = topics.skip( (page - 1) * TOPICS_PER_PAGE).limit(TOPICS_PER_PAGE) if current_user.is_authenticated(): read_topics = display_topics.filter( users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None # Find the links we want for the next/prev buttons if applicable. #next_page = url_for('forum.view_board', page=page + 1, **board.get_url_info()) if page < num_pages \ # else None #prev_page = url_for('forum.view_board', page=page - 1, **board.get_url_info()) if page > 1 and not num_pages == 1 \ # else None # Mash together a list of what pages we want linked to in the pagination bar. #links = [] #for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages-page) + 1): # num = page + page_mod # links.append({'num': num, 'url': url_for('forum.view_board', page=num, **board.get_url_info()), 'active': (num == page)}) # Render it all out :D return render_template('forum_topics_display.html', board=board, forum=forum, topics=display_topics, read_topics=read_topics, forum_menu_current=board.id, **forum_template_data(forum))
def view_board(board_id, board_name, page): board = Board.objects(board_id=board_id).first() if board is None: abort(404) if not board_name == board.get_url_name(): return redirect(board.get_url()) forum = board.forum # Get our sorted topics and the number of topics. topics = Topic.objects(board=board).order_by('-last_post_date') topic_num = len(topics) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(topic_num / float(TOPICS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topics_display.html', board=board, forum=forum, topics=[], read_topics=[], forum_menu_current=board.id, **forum_template_data(forum)) abort(404) # Compile the list of topics we want displayed. display_topics = topics.skip((page - 1) * TOPICS_PER_PAGE).limit(TOPICS_PER_PAGE) if current_user.is_authenticated(): read_topics = display_topics.filter(users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None # Find the links we want for the next/prev buttons if applicable. #next_page = url_for('forum.view_board', page=page + 1, **board.get_url_info()) if page < num_pages \ # else None #prev_page = url_for('forum.view_board', page=page - 1, **board.get_url_info()) if page > 1 and not num_pages == 1 \ # else None # Mash together a list of what pages we want linked to in the pagination bar. #links = [] #for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages-page) + 1): # num = page + page_mod # links.append({'num': num, 'url': url_for('forum.view_board', page=num, **board.get_url_info()), 'active': (num == page)}) # Render it all out :D return render_template('forum_topics_display.html', board=board, forum=forum, topics=display_topics, read_topics=read_topics, forum_menu_current=board.id, **forum_template_data(forum))
def view_board_redirect(board_id): board = Board.objects(board_id=board_id).first() if board is None: abort(404) return redirect(url_for('forum.view_board', board_id=board_id, board_name=board.name.replace(' ', '_'), page=1))