def fun_get_comment_by_position(article_id=None, pos=0, article_type="blog", page_cap=10, load_one='no', load_before='no', before_pos=0): ''' get comment by position, return [1|0, 'info', first_post, last_pos, len] ''' ''' info contains a dict{ 'comment':{'0': comment(0) }, 'ref_commet':{'1':comment(0) } } ''' try: if article_type == "blog": AF_Object = Blog(_id=article_id) elif article_type == "group-topic": AF_Object = Topic(_id=article_id) elif article_type == 'group-notice': AF_Object = Bulletin(_id=article_id) elif article_type == 'group-feedback': AF_Object = Feedback(_id=article_id) elif article_type == "group-doc": AF_Object = Blog(_id=article_id) else: return [1, '不支持当前类型!'] except Exception, e: logging.error(traceback.format_exc()) logging.error('%s not exist, id %s' % (article_type, article_id)) return [1, '文章不存在!']
def post(self): user = self.current_user article_id = is_value(self.get_argument("article_id", None)) article_type = is_value(self.get_argument("article_type", None)) result = {'kind': 1, 'info': ''} if article_id is None or article_type is None or (article_type not in [ 'blog', 'comment', 'feedback', 'topic' ]): result['info'] = '参数错误!' self.write(json_encode(result)) return if article_type == "blog": try: obj = Blog(_id=article_id) if obj.author_id != user._id: result['info'] = '无权删除!' return self.write(json_encode(result)) except Exception, e: logging.error(traceback.format_exc()) logging.error('Blog not exist, id %s' % article_id) else: user.drafts_lib.delete_obj(article_id) result['kind'] = 0 return self.write(json_encode(result))
def fun_update_article(user, group=None, group_id='-1', article_id=0, article_type='blog', title='', summary='', body='', permission='public', keys=[], classes=[], father_id='-1', father_type='blog', do="post", ref_comments='', isedit='false'): if keys != []: keys = keys_to_list(keys) if article_type == "blog": # write blog start try: AF_Object = Blog(_id=article_id) if str(AF_Object.author_id) != str(user._id): return [1, '无权限操作他人的文章!'] except Exception, e: AF_Object = Blog() AF_Object.author = user AF_Object.env = user article_id = AF_Object._id (user.drafts_lib).add_obj(AF_Object) return fun_update_blog(user=user, blog=AF_Object, title=title, summary=summary, body=body, keys=keys, permission=permission, classes=classes, do=do)
def fun_do_like(user, kind="blog", obj_id='0', want="like"): #print user.favorite_lib.load_all() try: #print want if kind == "blog": obj = Blog(_id=obj_id) else: return [1, '暂不支持此类型!'] except Exception, e: logging.error('Blog not exist, id %s ' % str(obj_id)) return [1, '参数错误,对象不存在!']
def fun_update_comment(user, group_id='-1', article_id=0, article_type='blog', title='', summary='', body='', permission='public', keys=[], classes=[], father_id='-1', father_type='blog', do="post", ref_comments=''): # update comment, all comments group = None if father_type == 'blog': try: AF_Object = Blog(_id=father_id) except Exception, e: return [1, '文章不存在!']
#!/usr/bin/env python from global_info import * from article.blog import Blog from article.catalog import Catalog from user import User recent_blogs.set_all([None for i in range(500)]) blog_all = sorted([Blog(each) for each in Blog.datatype.find()], reverse=True) for each in blog_all: if each.is_posted is False: continue recent_blogs.push(each._id) recent_blogs.pop_head() recent_books.set_all([None for i in range(500)]) book_all = sorted([Catalog(each) for each in Catalog.datatype.find()], reverse=True) for each in book_all: recent_books.push(each._id) recent_books.pop_head() recent_users.set_all([None for i in range(500)]) user_all = sorted([User(each) for each in User.datatype.find()], reverse=True) for each in user_all: recent_users.push(each._id) recent_users.pop_head() unreg_users.set_all([None for i in range(5000)]) recent_feedbacks.set_all([None for i in range(500)])
def fun_view_blog(bid): try: AF_Article = Blog(_id=bid) except Exception, e: return [1, '无此文章!', '', '', '', '']
return [1, '文章不存在!'] else: # for group if father_type == 'group-notice': try: AF_Object = Bulletin(_id=father_id) group = BasicGroup(_id=AF_Object.group_id) if group.get_member_type(user) is None: return [1, '您不是该小组成员'] 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-doc": try: AF_Object = Blog(_id=father_id) group = BasicGroup(_id=AF_Object.group_id) if group.get_member_type(user) is None: return [1, '您不是该小组成员'] 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-topic": try: AF_Object = Topic(_id=father_id) group = BasicGroup(_id=AF_Object.group_id) if group.get_member_type(user) is None: return [1, '您不是该小组成员'] AF_Object.update_time = datetime.datetime.now() group.topic_list.pull(AF_Object._id)
url_tmp = urlparse.urlparse(section_url) url_tmp_info = url_tmp.path.split('/') if len(url_tmp_info ) < 5 or url_tmp_info[1] != 'book' or url_tmp_info[3] != 'catalog': return [1, '链接错误!'] book_id = url_tmp_info[2] node_id = url_tmp_info[4] try: book = Catalog(_id=book_id) except Exception, err: logging.error(traceback.format_exc()) logging.error('Catalog not exist, id %s' % book_id) return [1, '未找到该知识谱!'] if article_type == "blog": try: AF_Object = Blog(_id=article_id) if not AF_Object.is_posted: return [1, '该文章未发布!'] except Exception, err: logging.error(traceback.format_exc()) logging.error('%s not exist, id %s' % (article_type, article_id)) return [1, '未找到该文章!'] else: return [1, '暂时不支持!'] AF_Object.add_to_catalog(book, node_id) #book.recommend_blog_to(url_query["id"], AF_Object) restr = '成功添加到知识谱<a href="/book/%s" target="_blank">《%s》</a>的章节中!' % ( book_id, book.name) return [0, restr]
#!/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)
isnew = False elif article_type == "book-about": isnew = False try: book = Catalog(_id=group_id) AF_Object = book.about limit = book.authority_verify(user) if test_auth(limit, A_WRITE) is False: return [1, '您无权修改摘要!'] except Exception, err: logging.error(traceback.format_exc()) logging.error('Catalog not exist, id %s' % group_id) return [1, '未找到知识谱!'] elif article_type == "blog": try: AF_Object = Blog(_id=article_id) isnew = False except Exception, e: logging.error(traceback.format_exc()) logging.error('%s not exist, id %s' % (article_type, article_id)) AF_Object = Blog() AF_Object.author = user AF_Object.env = user article_id = str(AF_Object._id) isnew = True (user.drafts_lib).add_obj(AF_Object) elif article_type == "comment": return [1, '完善中'] elif article_type in Group_Article: # for group isnew = False