def GET(self, post_id): if session.user_id is None: raise web.SeeOther('/login?next=/post/unfav/'+post_id) user_meta_model().delete({'user_id':session.user_id, 'meta_key':'post_fav','meta_value':post_id}) user_model().update({'id':session.user_id}, {'post_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'post_fav'})}) user_model().update_session(session.user_id) raise web.SeeOther('/post/'+post_id)
def GET(self, node_name): node = node_model().get_one({'name': node_name}) if node is None: self.crumb.append('节点未找到') return render.node_nf('节点未找到', self.crumb.output()) if session.user_id is None: raise web.SeeOther('/login?next=/node/'+node_name) user_meta_model().delete({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id}) user_model().update({'id':session.user_id}, {'node_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'node_fav'})}) user_model().update_session(session.user_id) raise web.SeeOther('/node/'+node_name)
def GET(self, post_id): post = post_model().get_one({'id':post_id}) if post is None: self.crumb.append('主题未找到') return render.post_nf('主题未找到', self.crumb.output()) if session.user_id is None: raise web.SeeOther('/login?next=/post/fav/'+post_id) user_meta_model().unique_insert({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post_id}) user_model().update({'id':session.user_id}, {'post_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'post_fav'})}) user_model().update_session(session.user_id) raise web.SeeOther('/post/' + post_id)
def GET(self, name): user = user_model().get_one({'name':name}) if user is None: crumb = Crumb() crumb.append('会员未找到') return render.user_nf('会员未找到', crumb.output()) else: if session.user_id is None: raise web.SeeOther('/login?next=/profile/'+name) user_meta_model().delete({'user_id':session.user_id, 'meta_key':'follow', 'meta_value':user.id}) user_model().update({'id':session.user_id}, {'user_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'follow'})}) user_model().update_session(session.user_id) raise web.SeeOther('/profile/'+name)
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): limit = 10 self.crumb.append('我关注的人的最新主题') # 取出收藏的节点id followings = user_meta_model().get_all({'user_id':session.user_id, 'meta_key':'follow'}) if len(followings) > 0 : user_favs = [] for following in followings: user_favs.append(following.meta_value) total_rows = post_model().count_table({'user_id':user_favs}) pagination = Pagination('/my/following', total_rows, limit = limit) page = pagination.true_page(web.input(p=1)['p']) posts_result = post_model().get_all(conditions = {'user_id': user_favs}, order = 'time DESC', limit = limit, offset = (page-1)*limit) posts = [] for post_result in posts_result: post = {'post':post_result} user = user_model().get_one({'id':post_result.user_id}) post['user'] = user node = node_model().get_one({'id':post_result.node_id}) post['node'] = node 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) else: posts = None total_rows = 0 pagination = Pagination('/my/nodes', total_rows) page = pagination.true_page(web.input(p=1)['p']) return render.following_posts('来自我收藏的节点的最新主题', posts, total_rows, self.crumb.output(), pagination.output())
def GET(self): limit = 10 self.crumb.append('我收藏的主题') user = user_model().get_one({'id':session.user_id}) pagination = Pagination('/my/posts', user.post_favs, limit = limit) if user.post_favs > 0: page = pagination.true_page(web.input(p=1)['p']) post_favs = user_meta_model().get_all({'user_id':user.id, 'meta_key':'post_fav'}, limit = limit, offset = (page-1)*limit, order = 'id DESC') posts = [] for post_fav in post_favs: post_result = post_model().get_one({'id':post_fav.meta_value}) post = {'post':post_result} user = user_model().get_one({'id':post_result.user_id}) post['user'] = user node = node_model().get_one({'id':post_result.node_id}) post['node'] = node 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) else: posts = None return render.post_favs('我收藏的主题', user, posts, self.crumb.output(), pagination.output())
def GET(self, name): limit = 10 user = user_model().get_one({'name': name}) if user is None: crumb = Crumb() crumb.append('会员未找到') return render.user_nf('会员未找到', crumb.output()) else: posts_result = post_model().get_all({'user_id': user.id}, limit=limit, order='time DESC') if len(posts_result) > 0: posts = [] for post_result in posts_result: post = {'post': post_result} node = node_model().get_one({'id': post_result.node_id}) post['node'] = node 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) else: posts = None comments_result = comment_model().get_all({'user_id': user.id}, limit=limit, order='time DESC') if len(comments_result) > 0: comments = [] for comment_result in comments_result: post = post_model().get_one({'id': comment_result.post_id}) post_user = user_model().get_one({'id': post.user_id}) comment = { 'post': post, 'comment': comment_result, 'post_user': post_user } comments.append(comment) else: comments = None following = False if session.user_id: if user_meta_model().get_one({ 'user_id': session.user_id, 'meta_key': 'follow', 'meta_value': user.id }): following = True return render.profile(user.name, user, posts, comments, following)
def GET(self, id): limit = 10 post_model().add_view(id) post = post_model().get_one({'id':id}) if post is None: self.crumb.append('主题未找到') return render.post_nf('主题未找到', self.crumb.output()) else: post_fav = False if session.user_id: if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post.id}): post_fav = True favs = user_meta_model().count_meta({'meta_key':'post_fav','meta_value':id}) node = node_model().get_one({'id':post.node_id}) user = user_model().get_one({'id':post.user_id}) #return user.name self.crumb.append(node.display_name, '/node/'+node.name) thanks = False if session.user_id is not None: if post_thanks_model().get_one({'user_id':session.user_id, 'post_id':post.id}): thanks = True condition = {'post_id' : post.id} # Pagination total = comment_model().count_table(condition) pagination = Pagination('/post/'+str(post.id), total, limit = 100) page = pagination.true_page(web.input(p=1)['p']) comments_result = comment_model().get_all(condition, order = 'time ASC', limit = 100, offset = (page-1)*100) comments = [] if comments_result is not None: for comment_result in comments_result: comment_user = user_model().get_one({'id':comment_result.user_id}) comment_thanks = False if session.user_id is not None: if comment_thanks_model().get_one({'user_id':session.user_id, 'comment_id':comment_result.id}): comment_thanks = True comments.append({'comment':comment_result, 'user':comment_user, 'thanks':comment_thanks}) form = comment_model().form return render.post_view(post, user, comments, form, post_fav, favs, thanks, self.crumb.output(), pagination)
def GET(self, id): limit = 10 post_model().add_view(id) post = post_model().get_one({'id':id}) if post is None: self.crumb.append('主题未找到') return render.post_nf('主题未找到', self.crumb.output()) else: post_fav = False if session.user_id: if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post.id}): post_fav = True favs = user_meta_model().count_meta({'meta_key':'post_fav','meta_value':id}) node = node_model().get_one({'id':post.node_id}) user = user_model().get_one({'id':post.user_id}) #return user.name self.crumb.append(node.display_name, '/node/'+node.name) thanks = False if session.user_id is not None: if post_thanks_model().get_one({'user_id':session.user_id, 'post_id':post.id}): thanks = True condition = {'post_id' : post.id} # Pagination total = comment_model().count_table(condition) pagination = Pagination('/post/'+str(post.id), total, limit = 100) page = pagination.true_page(web.input(p=(total/100)*100 + 1)['p']) comments_result = comment_model().get_all(condition, order = 'time ASC', limit = 100, offset = (page-1)*100) comments = [] if comments_result is not None: for comment_result in comments_result: comment_user = user_model().get_one({'id':comment_result.user_id}) comment_thanks = False if session.user_id is not None: if comment_thanks_model().get_one({'user_id':session.user_id, 'comment_id':comment_result.id}): comment_thanks = True comments.append({'comment':comment_result, 'user':comment_user, 'thanks':comment_thanks}) form = comment_model().form return render.post_view(post, user, comments, form, post_fav, favs, thanks, self.crumb.output(), pagination)
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, name): limit = 10 user = user_model().get_one({'name':name}) if user is None: crumb = Crumb() crumb.append('会员未找到') return render.user_nf('会员未找到', crumb.output()) else: posts_result = post_model().get_all({'user_id':user.id}, limit = limit, order = 'time DESC') if len(posts_result) > 0: posts = [] for post_result in posts_result: post = {'post':post_result} node = node_model().get_one({'id':post_result.node_id}) post['node'] = node 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) else: posts = None comments_result = comment_model().get_all({'user_id':user.id}, limit = limit, order = 'time DESC') if len(comments_result) > 0: comments = [] for comment_result in comments_result: post = post_model().get_one({'id':comment_result.post_id}) post_user = user_model().get_one({'id':post.user_id}) comment = {'post':post, 'comment':comment_result, 'post_user':post_user} comments.append(comment) else: comments = None following = False if session.user_id: if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'follow', 'meta_value':user.id}): following = True return render.profile(user.name, user, posts, comments, following)