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)
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)
def count_thanks(self, comment_id): super(comment_model, self).query('update ' + self._tb + ' set thanks = (select count(*) from ' + comment_thanks_model().table_name() + ' where ' + comment_thanks_model().table_name() + '.comment_id = ' + str(comment_id) + ') where id = ' + str(comment_id))
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())
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)