def fun_get_draft_list(user, page=1, page_cap=10): tmp_dict = user.drafts_lib.load_all() tmp_list = tmp_dict.keys() tmp_list.sort() tmp_list.reverse() #print tmp_list sum_count = len(tmp_list) sum_page = (sum_count % page_cap and sum_count / page_cap + 1) or sum_count / page_cap if page > sum_page: return ([], 0) tmp_list.reverse() min_index, max_index = get_index_list_by_page(tmp_list, page=page, page_cap=page_cap) tmp_draft = [] com_draft = [] com_list = [] blog_draft = [] feedback_draft = [] topic_draft = [] for iii in tmp_list[min_index:max_index]: #print 'draft type ', tmp_dict[iii][0] if tmp_dict[iii][0] == 'Blog': blog_draft.append({ 'type': tmp_dict[iii][0], 'id': iii, 'time': tmp_dict[iii][1] }) elif tmp_dict[iii][0] == 'Comment': com_list.append(iii) else: tmp_draft.append({ 'type': tmp_dict[iii][0], 'id': iii, 'time': tmp_dict[iii][1] }) com_con = Comment.get_instances('_id', com_list) for kkk in com_con: com_draft.append({ 'type': 'Comment', 'id': kkk._id, 'time': kkk.update_time, 'father': kkk.father_id }) tmp_draft.extend(blog_draft) tmp_draft.extend(com_draft) tmp_draft.reverse() return (tmp_draft, sum_count)
def fun_get_draft_list(user, page=1, page_cap=10): tmp_dict = user.drafts_lib.load_all() tmp_list = tmp_dict.keys() tmp_list.sort() tmp_list.reverse() #print tmp_list sum_count = len(tmp_list) sum_page = (sum_count % page_cap and sum_count /page_cap + 1) or sum_count / page_cap if page > sum_page: return ([], 0) tmp_list.reverse() min_index, max_index = get_index_list_by_page(tmp_list, page=page, page_cap=page_cap) tmp_draft = [] com_draft = [] com_list = [] blog_draft = [] feedback_draft = [] topic_draft = [] for iii in tmp_list[min_index:max_index]: #print 'draft type ', tmp_dict[iii][0] if tmp_dict[iii][0] == 'Blog': blog_draft.append({'type': tmp_dict[iii][0], 'id':iii, 'time':tmp_dict[iii][1]}) elif tmp_dict[iii][0] == 'Comment': com_list.append(iii) else: tmp_draft.append({'type': tmp_dict[iii][0], 'id':iii, 'time':tmp_dict[iii][1]}) com_con = Comment.get_instances('_id', com_list) for kkk in com_con: com_draft.append({'type': 'Comment', 'id':kkk._id, 'time':kkk.update_time, 'father':kkk.father_id}) tmp_draft.extend(blog_draft) tmp_draft.extend(com_draft) tmp_draft.reverse() return (tmp_draft, sum_count)
return [1, '您不是该小组成员'] AF_Object.update_time = datetime.datetime.now() group.topic_list.pull(AF_Object._id) group.topic_list.push(AF_Object._id) except Exception, e: logging.error(traceback.format_exc()) logging.error('%s not exist, id %s' % (father_type, father_id)) return [1, '该话题不存在!'] elif father_type == "group-feedback": return [1, '不支持当前操作!'] else: return [1, '完善中!'] # create comment and save it ref_comments_list = str_to_int_list(ref_comments) #print ref_comments_list AF_Comment = Comment() AF_Comment.author = user AF_Comment.set_propertys(**{ 'body': body, 'father': AF_Object, 'ref_comments': ref_comments_list }) if father_type != 'blog': AF_Comment.set_propertys(**{'group_id': AF_Object.group_id}) # post to the AF_Object AF_Object.comment_list.push(AF_Comment._id) # post notification to_blog_author_mes = format_notification(note_from=user, note_to_what=AF_Object,
#!/usr/bin/env python from article.blog import Blog from article.about import About from article.comment import Comment from article.reference import Reference from article.tableform import Tableform from article.langcode import Langcode from tornado.escape import xhtml_unescape blogs_all = [Blog(each) for each in Blog.datatype.find()] comments_all = [Comment(each) for each in Comment.datatype.find()] about_all = About.find() ref_all = Reference.find() table_all = Tableform.find() code_all = Langcode.find() for each in blogs_all + comments_all + about_all: each.abstract = xhtml_unescape(each.abstract) each.body = xhtml_unescape(each.body) for each in ref_all: each.body = xhtml_unescape(each.body) for each in code_all: each.code = xhtml_unescape(each.code) for each in table_all: each.tableform = xhtml_unescape(each.tableform)
return [1, '您不是该小组成员'] AF_Object.update_time = datetime.datetime.now() group.topic_list.pull(AF_Object._id) group.topic_list.push(AF_Object._id) except Exception, e: logging.error(traceback.format_exc()) logging.error('%s not exist, id %s' %(father_type, father_id)) return [1, '该话题不存在!'] elif father_type == "group-feedback": return [1, '不支持当前操作!'] else: return [1, '完善中!'] # create comment and save it ref_comments_list = str_to_int_list(ref_comments) #print ref_comments_list AF_Comment = Comment() AF_Comment.author = user AF_Comment.set_propertys(**{'body':body, 'father':AF_Object, 'ref_comments':ref_comments_list}) if father_type != 'blog': AF_Comment.set_propertys(**{'group_id': AF_Object.group_id}) # post to the AF_Object AF_Object.comment_list.push(AF_Comment._id) # post notification to_blog_author_mes = format_notification(note_from=user, note_to_what=AF_Object, note_from_what=AF_Comment, father_type=father_type, group=group) to_comment_author_mes = format_notification(note_from=user, note_to_what=AF_Object, note_from_what=AF_Comment,do="reply_comment", father_type=father_type, group=group) ''' first post to the object[blog] author, tell him his blog hava comments '''