def get(self): action = self.get_argument("action", None) nid = self.get_argument("id", None) if nid is not None: node = BoardNode.objects.with_id(nid) if node is None: return self.write("node is NULL") if action == "edit": node_help = "" for help in node.help: node_help = node_help + help + "\n" self.render("admin/board_node_edit.html", node=node, node_help=node_help) elif action == "count": count = BoardTopic.objects(__raw__={"node.$id": node.id}).count() return self.write(u'Node "%s" 总共有 %d 条topic!' % (node.name, count)) elif action == "delete": if node: count = BoardTopic.objects(__raw__={"node.$id": node.id}).count() if count > 0: return self.write(u'Node "%s" 有 %d 条topic, 不能删除!' % (node.name, count)) node.delete() fetch_cached_board_nodelist(reflush=True) return self.redirect("/admin/board/node") nodes = BoardNode.objects().order_by("-update_time") return self.render("admin/board_node_list.html", nodes=nodes)
def get(self, node_name=None): if not node_name: self.about(404) node = BoardNode.get_by_name(node_name) if not node: self.about(404) self.render("board/submit.html", node=node)
def get(self, node_name=None): if not node_name: self.about(404) node = BoardNode.get_by_name(node_name) if not node: self.about(404) node_list = fetch_cached_board_nodelist() self.render("board/submit.html", node=node, node_list=node_list)
def post(self, node_name=None): if not node_name: self.about(404) node = BoardNode.get_by_name(node_name) if not node: self.about(404) people = self.get_current_user() schema = BoardTopicForm(self) if schema.validate(): topic_content = schema.params.get("topic_content", None) topic_more_content = schema.params.get("topic_more_content", None) topic_videos = schema.params.get("topic_videos", None) topic_tags = schema.params.get("topic_tags", None) topic = BoardTopic() topic.content = topic_content topic.more_content = topic_more_content topic.node = node topic.people = people #People.objects().first() if topic_videos: topic.videos = [topic_videos] topic.save() #try: # topic.save() #except Exception, e: # raise e return self.redirect('/board/node/%s' % node_name) else: topic_content = self.get_argument('topic_content', '') topic_more_content = self.get_argument('topic_more_content', '') topic_content_error = schema.form_errors.get('topic_content', '') topic_more_content_error = schema.form_errors.get('topic_more_content', '') topic_videos_error = schema.form_errors.get('topic_images', '') self.render("board/submit.html", node=node, topic_content=topic_content, topic_more_content=topic_more_content, topic_content_error=topic_content_error, topic_more_content_error=topic_more_content_error, topic_videos_error=topic_videos_error)
def get(self): offset = self.get_argument("offset", 0) limit = PageMaxLimit action = self.get_argument("action", None) node_list = fetch_cached_board_nodelist() if action == "delete": topic_id = self.get_argument("topic_id", None) if not topic_id: return about(404) topic = fetch_cached_board_topic(topic_id) deltopic = BoardTopicDeleted() deltopic.id = topic.id deltopic.people = topic.people deltopic.content = topic.content deltopic.more_content = topic.more_content deltopic.images = topic.images deltopic.video_urls = topic.video_urls deltopic.attach_urls = topic.attach_urls deltopic.logo = topic.logo deltopic.up_vote = topic.up_vote deltopic.down_vote = topic.down_vote deltopic.comment_count = topic.comment_count deltopic.create_time = topic.create_time deltopic.update_time = topic.update_time deltopic.node = topic.node deltopic.tags = topic.tags deltopic.save() tid = topic.id topic.delete() fetch_cached_board_topic(tid, reflush=True) return self.redirect("/admin/board/topic") elif action == "list": node_name = self.get_argument("node", None) node = BoardNode.get_by_name(node_name) if not node: return about(404) topic_list = BoardTopic.get_last_node_topics(node, limit=limit, offset=offset) return self.render("/admin/board_topic_list.html", topic_list=topic_list, node_list=node_list) topic_list = BoardTopic.get_last_topics(limit=limit, offset=offset) return self.render("/admin/board_topic_list.html", topic_list=topic_list, node_list=node_list)
def post(self): node_name = self.get_argument("node_name") node_desc = self.get_argument("node_desc") node_title = self.get_argument("node_title", "") node_help = self.get_argument("node_help", "") action = self.get_argument("action") if action == "edit": nid = self.get_argument("id") node = BoardNode.objects.with_id(nid) if node is None: return about(404) node.name = node_name node.title = node_title node.desc = node_desc helps = node_help.split("\n") help_list = [] for help in helps: help = help.strip() if help: help_list.append(help) node.help = help_list node.save() fetch_cached_board_nodelist(reflush=True) return self.redirect("/admin/board/node") elif action == "create": node = BoardNode() node.name = node_name node.desc = node_desc node.title = node_title helps = node_help.split("\n") help_list = [] for help in helps: help = help.strip() if help: help_list.append(help) node.help = help_list fetch_cached_board_nodelist(reflush=True) node.save() return self.redirect("/admin/board/node")
def get(self, node_name=None): if not node_name: self.about(404) node = BoardNode.get_by_name(node_name) if not node: self.about(404) page = self.get_argument('page', '1') page_no = string2int(page, -1) if page_no == -1: self.about(404) if page_no < 1: page_no = 1 offset = (page_no-1) * PageMaxLimit node_list = fetch_cached_board_nodelist() topics = BoardTopic.get_last_node_topics(node, limit=PageMaxLimit, offset=offset) topic_list = [] for t in topics: topic = fetch_cached_board_topic(t.id) topic_list.append(topic) now = time.time() total_count = BoardTopic.get_node_topics_count(node) total_pages = total_count / PageMaxLimit last_page = total_count % PageMaxLimit if last_page > 0: total_pages += 1 pagination = Pagination(page_no, total_pages) self.render("board/node.html", timeover=timeover, topic_list=topic_list, topic_count=len(topic_list), node_list=node_list, node = node, now_time=now, pagination=pagination, offset=offset)
def get_cached_board_nodelist(cache='board_nodelist'): try: nodelist = BoardNode.get_top_nodes() return list(nodelist) except InvalidId, error: pass