def GET(self, name): limit = 10 user = user_model().get_one({'name':name}) crumb = Crumb() if user: crumb.append(name, '/profile/'+name) crumb.append('全部主题') total_rows = post_model().count_table({'user_id':user.id}) pagination = Pagination('/profile/'+name+'/posts', total_rows, limit = limit) page = pagination.true_page(web.input(p=1)['p']) posts_result = post_model().get_all({'user_id':user.id}, limit = limit, offset = (page-1) * limit, order = 'time DESC') 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) return render.user_posts('全部主题', user, posts, total_rows, crumb.output(), pagination.output()) else: crumb.append('会员未找到') return render.user_nf('会员未找到', crumb.output())
def GET(self, name): limit = 10 user = user_model().get_one({'name': name}) crumb = Crumb() if user: crumb.append(name, '/profile/' + name) crumb.append('全部回复') total = comment_model().count_table({'user_id': user.id}) pagination = Pagination('/profile/' + name + '/comments', total, limit=limit) page = pagination.true_page(web.input(p=1)['p']) comments_result = comment_model().get_all({'user_id': user.id}, limit=limit, offset=(page - 1) * 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 return render.user_comments('全部回复', comments, total, crumb.output(), pagination.output()) else: crumb.append('会员未找到') return render.user_nf('会员未找到', crumb.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, 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, 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, name): limit = 10 user = user_model().get_one({'name':name}) crumb = Crumb() if user: crumb.append(name, '/profile/'+name) crumb.append('全部回复') total = comment_model().count_table({'user_id':user.id}) pagination = Pagination('/profile/'+name+'/comments', total, limit = limit) page = pagination.true_page(web.input(p=1)['p']) comments_result = comment_model().get_all({'user_id':user.id}, limit = limit, offset = (page-1)*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 return render.user_comments('全部回复', comments, total, crumb.output(), pagination.output()) else: crumb.append('会员未找到') return render.user_nf('会员未找到', crumb.output())