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_forum(forum): forum = Forum.objects(identifier=forum).first() if forum is None: abort(404) categories = Category.objects(forum=forum) recent_topics = Topic.objects(forum=forum).order_by('-last_post_date').limit(10) if current_user.is_authenticated(): read_topics = recent_topics.filter(users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None return render_template("forum_topics_display.html", categories=categories, forum=forum, topics=recent_topics, read_topics=read_topics, forum_menu_current='latest', **forum_template_data(forum)) #@blueprint.route('/f/a/s/') #def setup(): # category = Category.objects.first() # forum = Forum.objects(identifier="main").first() # board = Board() # board.name = "General Chat" # board.forum = forum # board.categories = [category] # board.description = "Put chatter here pls" # board.save() # return 'yes'
def post_reply(topic_id, topic_name): topic = Topic.objects(topic_url_id=topic_id).first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) board = topic.board forum = board.forum form = TopicReplyForm(request.form) if request.method == 'GET': return render_template('forum_post_reply.html', forum=forum, board=board, topic=topic, form=form) elif request.method == 'POST': if not form.validate(): return render_template('forum_post_reply.html', forum=forum, board=board, topic=topic, form=form) post = Post(author=current_user.to_dbref(), content=form.content.data, topic=topic, forum=forum) post_edit = PostEdit(author=post.author, content=post.content, date=post.date) post.edits.append(post_edit) post.save() topic.update(set__users_read_topic=[], set__last_post_date=post.date) return redirect(topic.get_url())
def view_forum(forum): forum = Forum.objects(identifier=forum).first() if forum is None: abort(404) categories = Category.objects(forum=forum) recent_topics = Topic.objects( forum=forum).order_by('-last_post_date').limit(10) if current_user.is_authenticated(): read_topics = recent_topics.filter( users_read_topic__in=[current_user.id]).scalar('id') else: read_topics = None return render_template("forum_topics_display.html", categories=categories, forum=forum, topics=recent_topics, read_topics=read_topics, forum_menu_current='latest', **forum_template_data(forum)) #@blueprint.route('/f/a/s/') #def setup(): # category = Category.objects.first() # forum = Forum.objects(identifier="main").first() # board = Board() # board.name = "General Chat" # board.forum = forum # board.categories = [category] # board.description = "Put chatter here pls" # board.save() # return 'yes'
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 __init__(self, user): posts_raw = Post.objects(author=user.to_dbref()).order_by('-date') self.post_num = len(posts_raw) self.forum_activity = posts_raw.limit(6) self.topic_num = len(Topic.objects(author=user))
def view_topic(topic_id, topic_name, page): if page == 0: abort(404) topic_reply_form = TopicReplyForm() topic = Topic.objects(topic_url_id=topic_id).exclude().first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) if current_user.is_authenticated(): topic.update(add_to_set__users_read_topic=current_user.to_dbref()) board = topic.board forum = board.forum # Get our sorted posts and the number of posts. posts = Post.objects(topic=topic).order_by('+date') num_posts = len(posts) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(num_posts / float(POSTS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topic_view.html', topic=topic, board=board, forum=forum, posts=posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=None, prev=None, links=[]) abort(404) # Compile the list of topics we want displayed. display_posts = posts.skip( (page - 1) * POSTS_PER_PAGE).limit(POSTS_PER_PAGE) # Find the links we want for the next/prev buttons if applicable. next_page = url_for( 'forum.view_topic', page=page + 1, **topic.get_url_info()) if page < num_pages else None prev_page = url_for( 'forum.view_topic', page=page - 1, **topic.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_topic', page=num, **topic.get_url_info()), 'active': (num == page) }) return render_template('forum_topic_view.html', topic=topic, board=board, forum=forum, posts=display_posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=next_page, prev=prev_page, links=links, markdown_escape=markdown_escape, post_edit=PostEditForm(), forum_menu_current=board.id, **forum_template_data(forum))
def view_topic(topic_id, topic_name, page): if page == 0: abort(404) topic_reply_form = TopicReplyForm() topic = Topic.objects(topic_url_id=topic_id).exclude().first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) if current_user.is_authenticated(): topic.update(add_to_set__users_read_topic=current_user.to_dbref()) board = topic.board forum = board.forum # Get our sorted posts and the number of posts. posts = Post.objects(topic=topic).order_by("+date") num_posts = len(posts) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(num_posts / float(POSTS_PER_PAGE))) if num_pages < page: if page == 1: return render_template( "forum_topic_view.html", topic=topic, board=board, forum=forum, posts=posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=None, prev=None, links=[], ) abort(404) # Compile the list of topics we want displayed. display_posts = posts.skip((page - 1) * POSTS_PER_PAGE).limit(POSTS_PER_PAGE) # Find the links we want for the next/prev buttons if applicable. next_page = url_for("forum.view_topic", page=page + 1, **topic.get_url_info()) if page < num_pages else None prev_page = ( url_for("forum.view_topic", page=page - 1, **topic.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_topic", page=num, **topic.get_url_info()), "active": (num == page)} ) return render_template( "forum_topic_view.html", topic=topic, board=board, forum=forum, posts=display_posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=next_page, prev=prev_page, links=links, markdown_escape=markdown_escape, post_edit=PostEditForm(), forum_menu_current=board.id, **forum_template_data(forum) )