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): 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 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)
def __init__(self): super(notify_model, self).__init__('notify') self.types = {} types = notify_type_model().get_all() for type_ in types: self.types[type_.name] = type_.id
def __init__(self): super(notify_model, self).__init__("notify") self.types = {} types = notify_type_model().get_all() for type_ in types: self.types[type_.name] = type_.id
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)