Exemplo n.º 1
0
 def count_comment(self, post_id):
     super(post_model,
           self).query('update ' + self._tb +
                       ' set comments = (select count(*) from ' +
                       comment_model().table_name() + ' where ' +
                       comment_model().table_name() + '.post_id = ' +
                       str(post_id) + ') where id = ' + str(post_id))
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
 def POST(self):
     import json
     json_dict = {'success':0, 'msg':'', 'script':''}
     comment_id = web.input(comment_id=None)['comment_id']
     comment = comment_model().get_one({'id':comment_id})
     if comment_id and comment:
         if session.user_id is None:
             post = post_model().get_one({'id':comment.post_id})
             json_dict['msg'] = '你要先登录的亲'
             json_dict['script'] = 'location.href=\'/login?next=/post/'+str(post.id)+'#reply-'+str(comment_id)+'\''
         elif comment.user_id != session.user_id:
             comment_thanks_id = comment_thanks_model().unique_insert({'user_id':session.user_id, 'comment_id':comment_id})
             if comment_thanks_id:
                 comment_thanks_model().update({'id':comment_thanks_id}, {'time':int(time.time())})
                 cost = money_model().cal_thanks()
                 money_type_id = money_type_model().get_one({'name':'comment_thanks'})['id']
                 money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':comment_thanks_id})
                 money_model().insert({'user_id':comment.user_id, 'money_type_id':money_type_id, 'amount':cost, 'foreign_id':comment_thanks_id, 'balance':user_model().update_money(comment.user_id, cost)})
                 comment_model().count_thanks(comment_id)
                 user_model().update_session(session.user_id)
                 json_dict['success'] = 1
             else:
                 json_dict['msg'] = '你已经感谢过了不是吗?'
         else:
             json_dict['msg'] = '你不能感谢你自己不是吗?'
     else:
         json_dict['message'] = '评论不存在'
     return json.dumps(json_dict)
Exemplo n.º 4
0
 def POST(self):
     import json
     json_dict = {'success': 0, 'msg': '', 'script': ''}
     comment_id = web.input(comment_id=None)['comment_id']
     comment = comment_model().get_one({'id': comment_id})
     if comment_id and comment:
         if session.user_id is None:
             post = post_model().get_one({'id': comment.post_id})
             json_dict['msg'] = '你要先登录的亲'
             json_dict[
                 'script'] = 'location.href=\'/login?next=/post/' + str(
                     post.id) + '#reply-' + str(comment_id) + '\''
         elif comment.user_id != session.user_id:
             comment_thanks_id = comment_thanks_model().unique_insert({
                 'user_id':
                 session.user_id,
                 'comment_id':
                 comment_id
             })
             if comment_thanks_id:
                 comment_thanks_model().update({'id': comment_thanks_id},
                                               {'time': int(time.time())})
                 cost = money_model().cal_thanks()
                 money_type_id = money_type_model().get_one(
                     {'name': 'comment_thanks'})['id']
                 money_model().insert({
                     'user_id':
                     session.user_id,
                     'money_type_id':
                     money_type_id,
                     'amount':
                     -cost,
                     'balance':
                     user_model().update_money(session.user_id, -cost),
                     'foreign_id':
                     comment_thanks_id
                 })
                 money_model().insert({
                     'user_id':
                     comment.user_id,
                     'money_type_id':
                     money_type_id,
                     'amount':
                     cost,
                     'foreign_id':
                     comment_thanks_id,
                     'balance':
                     user_model().update_money(comment.user_id, cost)
                 })
                 comment_model().count_thanks(comment_id)
                 user_model().update_session(session.user_id)
                 json_dict['success'] = 1
             else:
                 json_dict['msg'] = '你已经感谢过了不是吗?'
         else:
             json_dict['msg'] = '你不能感谢你自己不是吗?'
     else:
         json_dict['message'] = '评论不存在'
     return json.dumps(json_dict)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def GET(self):
     limit = 20
     total = money_model().count_table({'user_id':session.user_id})
     pagination = Pagination('/balance', total, limit = limit)
     page = pagination.true_page(web.input(p=1)['p'])
     records_result = money_model().get_all({'user_id':session.user_id}, limit = limit, offset = (page-1)*limit, order = 'id DESC')
     money_types_result = money_type_model().get_all()
     money_type = {}
     for money_type_result in money_types_result:
         money_type[money_type_result.id] = money_type_result.name
     records = []
     for record_result in records_result:
         # 发布的帖子或者是评论的帖子
         post = None
         # 发布或者收到的评论
         post_user = None
         post_thanks = None
         comment_thanks = None
         sender = None
         comment = None
         # 评论的用户
         comment_user = None
         try:
             type = money_type[record_result.money_type_id]
             if type == 'post':
                 post = post_model().get_one({'id':record_result.foreign_id})
             if type == 'comment':
                 comment = comment_model().get_one({'id':record_result.foreign_id})
                 comment_user = user_model().get_one({'id':comment.user_id})
                 post = post_model().get_one({'id':comment.post_id})
             if type == 'post_thanks':
                 post_thanks = post_thanks_model().get_one({'id':record_result.foreign_id})
                 post = post_model().get_one({'id':post_thanks.post_id})
                 sender = user_model().get_one({'id':post_thanks.user_id})
                 post_user = user_model().get_one({'id':post.user_id})
             if type == 'comment_thanks':
                 comment_thanks = comment_thanks_model().get_one({'id':record_result.foreign_id})
                 comment = comment_model().get_one({'id':comment_thanks.comment_id})
                 post = post_model().get_one({'id':comment.post_id})
                 comment_user = user_model().get_one({'id':comment.user_id})
                 sender = user_model().get_one({'id':comment_thanks.user_id})
         # 如果数据错误将不把这条记录输出到视图
         except AttributeError:
             continue
         else:
             record = {'record':record_result, 'type':type, 'comment':comment, 'post':post, 'post_user':post_user, 'sender':sender, 'comment_user':comment_user, 'post_thanks':post_thanks, 'comment_thanks':comment_thanks}
             records.append(record)
     self.crumb.append('账户余额')
     return render.money_record('账户余额', records, self.crumb.output(), pagination.output())
Exemplo n.º 7
0
 def GET(self):
     # sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     # post_ids = post_model().query_result(sql)
     crumb = Crumb()
     limit = 50
     total = post_model().count_table()
     pagination = Pagination("/recent", total, limit=limit)
     page = pagination.true_page(web.input(p=1)["p"])
     post_results = post_model().get_all(limit=limit, offset=(page - 1) * limit, order="time DESC")
     posts = []
     for post_result in post_results:
         # post_result = post_model().get_one({'id':row.post_id})
         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)
     crumb.append("最近的主题")
     return render.recent("最近的主题", total, crumb.output(), posts, pagination.output())
Exemplo n.º 8
0
 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())
Exemplo n.º 9
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login')
     post = post_model().get_one({'id': post_id})
     if post is not None:
         if not self.form.validates():
             raise web.SeeOther('/post/' + post_id)
         else:
             user_model().update_session(session.user_id)
             length, cost = money_model().cal_comment(self.form.d.content)
             if session.money < cost:
                 self.crumb.append('财富不够')
                 return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(',
                                        self.crumb.output())
             content = html2db(self.form.d.content)
             create_time = time.time()
             comment_id = comment_model().insert({
                 'user_id': session.user_id,
                 'post_id': post_id,
                 'content': content,
                 'time': create_time
             })
             money_type_id = money_type_model().get_one({'name':
                                                         'comment'})['id']
             money_model().insert({
                 'user_id':
                 session.user_id,
                 'money_type_id':
                 money_type_id,
                 'amount':
                 -cost,
                 'length':
                 length,
                 'balance':
                 user_model().update_money(session.user_id, -cost),
                 'foreign_id':
                 comment_id
             })
             if session.user_id != post.user_id:
                 money_model().insert({
                     'user_id':
                     post.user_id,
                     'money_type_id':
                     money_type_id,
                     'amount':
                     cost,
                     'length':
                     length,
                     'foreign_id':
                     comment_id,
                     'balance':
                     user_model().update_money(post.user_id, cost)
                 })
             user_model().update_session(session.user_id)
             post_model().update({'id': post_id},
                                 {'last_update': create_time})
             post_model().count_comment(post_id)
             raise web.SeeOther('/post/' + post_id)
     else:
         raise web.SeeOther('/post/' + post_id)
Exemplo n.º 10
0
 def GET(self):
     title = '首页'
     #sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     #post_ids = post_model().query_result(sql)
     post_results = post_model().get_all(order='last_update DESC', limit=20)
     posts = []
     for post_result in post_results:
         #post_result = post_model().get_one({'id':row.post_id})
         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)
     cats_result = cat_model().get_all()
     cats = []
     for cat_result in cats_result:
         cat = {'cat': cat_result}
         node = node_model().get_all({'category_id': cat_result.id})
         cat['node'] = node
         cats.append(cat)
     return render.index(cats, posts, title)
Exemplo n.º 11
0
 def GET(self):
     #sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     #post_ids = post_model().query_result(sql)
     crumb = Crumb()
     limit = 50
     total = post_model().count_table()
     pagination = Pagination('/recent', total, limit=limit)
     page = pagination.true_page(web.input(p=1)['p'])
     post_results = post_model().get_all(limit=limit,
                                         offset=(page - 1) * limit,
                                         order='time DESC')
     posts = []
     for post_result in post_results:
         #post_result = post_model().get_one({'id':row.post_id})
         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)
     crumb.append('最近的主题')
     return render.recent('最近的主题', total, crumb.output(), posts,
                          pagination.output())
Exemplo n.º 12
0
 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())
Exemplo n.º 13
0
 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())
Exemplo n.º 14
0
 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())
Exemplo n.º 15
0
 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())
Exemplo n.º 16
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login')
     post = post_model().get_one({'id':post_id})
     if post is not None:
         if not self.form.validates():
             raise web.SeeOther('/post/' + post_id)
         else:
             user_model().update_session(session.user_id)
             length, cost = money_model().cal_comment(self.form.d.content)
             if session.money < cost:
                 self.crumb.append('财富不够')
                 return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
             content = html2db(self.form.d.content)
             content, receiver_list = notify_model().convert_content(content)
             create_time = time.time()
             comment_id = comment_model().insert({'user_id' : session.user_id, 'post_id' : post_id, 'content' : content, 'time' : create_time})
             money_type_id = money_type_model().get_one({'name':'comment'})['id']
             money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':comment_id})
             if session.user_id != post.user_id:
                 money_model().insert({'user_id':post.user_id, 'money_type_id':money_type_id, 'amount':cost, 'length':length, 'foreign_id':comment_id, 'balance':user_model().update_money(post.user_id, cost)})
                 # notify
                 notify_model().insert({'user_id':session.user_id, 'receiver':post.user_id, 'type_id':notify_type_model().get_one({'name':'comment'}).id, 'foreign_id':comment_id})
             # notify
             receiver_list = list_diff(receiver_list, [session.name, user_model().get_one({'id':post.user_id}).name])
             notify_model().insert_notify(session.user_id, receiver_list, 'comment_at', comment_id)
             user_model().update_session(session.user_id)
             post_model().update({'id':post_id}, {'last_update':create_time})
             post_model().count_comment(post_id)
             raise web.SeeOther('/post/' + post_id)
     else:
          raise web.SeeOther('/post/' + post_id)
Exemplo n.º 17
0
 def GET(self):
 	title = '首页'
     #sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     #post_ids = post_model().query_result(sql)
     post_results = post_model().get_all(order='last_update DESC', limit=20)
     posts = []
     for post_result in post_results:
         #post_result = post_model().get_one({'id':row.post_id})
         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)
     cats_result = cat_model().get_all()
     cats = []
     for cat_result in cats_result:
         cat = {'cat':cat_result}
         node = node_model().get_all({'category_id':cat_result.id})
         cat['node'] = node
         cats.append(cat)
     return render.index(cats, posts, title)
Exemplo n.º 18
0
 def run(self):
     ltime = time.localtime(time.time())
     time_start = int(time.mktime(datetime.datetime(ltime.tm_year, ltime.tm_mon, ltime.tm_mday).timetuple()))
     time_end = time_start + 24 * 60 * 60
     sql = 'SELECT `post_id` FROM comment WHERE `time` >= '+str(time_start)+' AND `time` <= '+str(time_end)+' GROUP BY post_id ORDER BY count(post_id) DESC LIMIT 10'
     post_ids = comment_model().query_result(sql)
     posts = []
     for row in post_ids:
         post = post_model().get_one({'id':row.post_id})
         user = user_model().get_one({'id':post.user_id})
         posts.append({'post':post, 'user':user})
     return render.hot_posts_tody(posts)
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
 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())
Exemplo n.º 23
0
 def run(self):
     ltime = time.localtime(time.time())
     time_start = int(
         time.mktime(
             datetime.datetime(ltime.tm_year, ltime.tm_mon,
                               ltime.tm_mday).timetuple()))
     time_end = time_start + 24 * 60 * 60
     sql = 'SELECT `post_id` FROM comment WHERE `time` >= ' + str(
         time_start) + ' AND `time` <= ' + str(
             time_end
         ) + ' GROUP BY post_id ORDER BY count(post_id) DESC LIMIT 10'
     post_ids = comment_model().query_result(sql)
     posts = []
     for row in post_ids:
         post = post_model().get_one({'id': row.post_id})
         user = user_model().get_one({'id': post.user_id})
         posts.append({'post': post, 'user': user})
     return render.hot_posts_tody(posts)
Exemplo n.º 24
0
 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())
Exemplo n.º 25
0
 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())
Exemplo n.º 26
0
 def run(self):
     site_count = {}
     site_count['user'] = user_model().count_table()
     site_count['post'] = post_model().count_table()
     site_count['comment'] = comment_model().count_table()
     return render.site_statics(site_count)
Exemplo n.º 27
0
	def count_comment(self, post_id):
		super(post_model, self).query('update ' + self._tb + ' set comments = (select count(*) from ' + comment_model().table_name() + ' where ' + comment_model().table_name() + '.post_id = ' + str(post_id) + ') where id = ' + str(post_id))
Exemplo n.º 28
0
 def run(self):
     site_count = {}
     site_count['user'] = user_model().count_table()
     site_count['post'] = post_model().count_table()
     site_count['comment'] = comment_model().count_table()
     return render.site_statics(site_count)
Exemplo n.º 29
0
 def __init__(self):
     self.form = comment_model().form
Exemplo n.º 30
0
 def __init__(self):
     self.form = comment_model().form