def GET(self, node_name): limit = 10 node = node_model().get_one({'name': node_name}) if node is None: self.crumb.append('节点未找到') return render.node_nf('节点未找到', self.crumb.output()) else: self.crumb.append(node.display_name) node_fav = False if session.user_id: if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id}): node_fav = True total_rows = post_model().count_table({'node_id':node.id}) pagination = Pagination('/node/'+node_name, total_rows, limit = limit) page = pagination.true_page(web.input(p=1)['p']) posts_result = post_model().get_all({'node_id' : node.id}, limit = limit, offset = (page-1)*limit , order = 'time DESC') posts = [] for post_result in posts_result: post = {'post':post_result} user = user_model().get_one({'id':post_result.user_id}) post['user'] = user comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC') if comment: comment_user = user_model().get_one({'id':comment.user_id}) post['comment_user'] = comment_user else: post['comment_user'] = None posts.append(post) return render.node_posts(posts, node, total_rows, node_fav, self.crumb.output(), pagination.output())
def GET(self): crumb = Crumb() condition = {"receiver": session.user_id} total = notify_model().count_table(condition) limit = 10 pagination = Pagination("/notifications", total, limit=limit) page = pagination.true_page(web.input(p=1)["p"]) notify_result = notify_model().get_all(condition, order="id DESC", limit=limit, offset=(page - 1) * limit) notifications = [] if notify_result is not None: for notify in notify_result: post = None user = None comment = None notify_type = notify_type_model().get_one({"id": notify.type_id}).name user = user_model().get_one({"id": notify.user_id}) if notify_type == "post_at": post = post_model().get_one({"id": notify.foreign_id}) elif notify_type == "comment" or notify_type == "comment_at": comment = comment_model().get_one({"id": notify.foreign_id}) post = post_model().get_one({"id": comment.post_id}) notifications.append( {"notify": notify, "post": post, "user": user, "comment": comment, "type": notify_type} ) notify_model().mark_as_read(session.user_id) crumb.append("提醒系统") return render.notify("提醒系统", crumb.output(), total, notifications, pagination.output())
def GET(self, node_name): limit = 10 node = node_model().get_one({'name': node_name}) if node is None: self.crumb.append('节点未找到') return render.node_nf('节点未找到', self.crumb.output()) else: self.crumb.append(node.display_name) node_fav = False if session.user_id: if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id}): node_fav = True total_rows = post_model().count_table({'node_id':node.id}) pagination = Pagination('/node/'+node_name, total_rows, limit = limit) page = pagination.true_page(web.input(p=1)['p']) posts = post_model().trends(limit, (page-1) * limit, node.id) return render.node_posts(posts, node, total_rows, node_fav, self.crumb.output(), pagination.output())
def GET(self, node_name): limit = 10 node = node_model().get_one({'name': node_name}) if node is None: self.crumb.append('节点未找到') return render.node_nf('节点未找到', self.crumb.output()) else: self.crumb.append(node.display_name) node_fav = False if session.user_id: if user_meta_model().get_one({ 'user_id': session.user_id, 'meta_key': 'node_fav', 'meta_value': node.id }): node_fav = True total_rows = post_model().count_table({'node_id': node.id}) pagination = Pagination('/node/' + node_name, total_rows, limit=limit) page = pagination.true_page(web.input(p=1)['p']) posts_result = post_model().get_all({'node_id': node.id}, limit=limit, offset=(page - 1) * limit, order='time DESC') posts = [] for post_result in posts_result: post = {'post': post_result} user = user_model().get_one({'id': post_result.user_id}) post['user'] = user comment = comment_model().get_one({'post_id': post_result.id}, order='time DESC') if comment: comment_user = user_model().get_one( {'id': comment.user_id}) post['comment_user'] = comment_user else: post['comment_user'] = None posts.append(post) return render.node_posts(posts, node, total_rows, node_fav, self.crumb.output(), pagination.output())
def GET(self): crumb = Crumb() condition = {'receiver': session.user_id} total = notify_model().count_table(condition) limit = 10 pagination = Pagination('/notifications', total, limit=limit) page = pagination.true_page(web.input(p=1)['p']) notify_result = notify_model().get_all(condition, order='id DESC', limit=limit, offset=(page - 1) * limit) notifications = [] if notify_result is not None: for notify in notify_result: post = None user = None comment = None notify_type = notify_type_model().get_one({ 'id': notify.type_id }).name user = user_model().get_one({'id': notify.user_id}) if notify_type == 'post_at': post = post_model().get_one({'id': notify.foreign_id}) elif notify_type == 'comment' or notify_type == 'comment_at': comment = comment_model().get_one( {'id': notify.foreign_id}) post = post_model().get_one({'id': comment.post_id}) notifications.append({ 'notify': notify, 'post': post, 'user': user, 'comment': comment, 'type': notify_type }) notify_model().mark_as_read(session.user_id) crumb.append('提醒系统') return render.notify('提醒系统', crumb.output(), total, notifications, pagination.output())