def fun_article_delete_src(user, article_id=0, article_type='blog', src_type='code', alias=0, group_id='-1'): if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if src_type not in Agree_Src: return [1, '不支持当前类型的资源!'] if article_type == "about": AF_Object = About(_id=user.about._id) elif article_type == "book-about": 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, '未找到该知识谱!']
def fun_new_article_pic(user, article_id=0, article_type='blog', title='', url='', thumb='', father_id=0, group_id='-1'): isnew = 0 if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if article_type == "about": AF_Object = About(_id=user.about._id) isnew = 0 elif article_type == "book-about": 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, '未找到该目录!']
def fun_article_update_src(user, article_id=0, article_type='blog', src_type='code', alias='1', title='', body='', source='', code_type='python', math_type='inline', group_id='-1'): ''' update the lib of the article, article_type is about|blog|comment article_id must be have need alias too, then we find the lib _id, create the object, and set of it ''' if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if src_type not in Agree_Src: return [1, '暂不支持当前资源的类型!'] if title is None: return [1, '请您填写标题/名称!'] if src_type != 'image': if body is None: if src_type == 'r': if source is None: return [1, '出处不能为空'] if re.search(r'^(http|https|ftp):\/\/.+$', source) is None: return [1, '请填写链接地址或者引用真实内容!'] body = '' else: return [1, '内容不能为空!'] if src_type == 'math': if math_type not in ['display', 'inline']: math_type = 'display' body = math_encode(xhtml_unescape(body)) if src_type == 'code': if code_type not in Agree_Code: return [1, '目前不支持此类型的程序代码!'] if article_type == "about": AF_Object = About(_id=user.about._id) elif article_type == "book-about": 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, '您无权修改!'] pass except Exception, err: logging.error(traceback.format_exc()) logging.error('Catalog not exist, id %s' % group_id) return [1, '未找到该知识谱!']
def fun_article_update_src(user, article_id=0, article_type='blog', src_type='code', alias='1', title='', body='', source='', code_type='python', math_type='inline', group_id='-1'): ''' update the lib of the article, article_type is about|blog|comment article_id must be have need alias too, then we find the lib _id, create the object, and set of it ''' if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if src_type not in Agree_Src: return [1, '暂不支持当前资源的类型!'] if title is None: return [1, '请您填写标题/名称!'] if src_type != 'image': if body is None: if src_type == 'r': if source is None: return [1, '出处不能为空'] if re.search(r'^(http|https|ftp):\/\/.+$', source) is None: return [1, '请填写链接地址或者引用真实内容!'] body = '' else: return [1, '内容不能为空!'] if src_type == 'math': if math_type not in ['display', 'inline']: math_type = 'display' body = math_encode( xhtml_unescape(body) ) if src_type == 'code': if code_type not in Agree_Code: return [1, '目前不支持此类型的程序代码!'] if article_type == "about": AF_Object = About(_id=user.about._id) elif article_type == "book-about": 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, '您无权修改!'] pass except Exception, err: logging.error(traceback.format_exc()) logging.error('Catalog not exist, id %s' % group_id) return [1, '未找到该知识谱!']
def fun_article_new_src(user, article_id='-1', article_type='blog', src_type='code', title='', body='', source='', code_type='python', math_type='inline', father_id='-1', group_id='-1'): if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if src_type not in Agree_Src: return [1, '不支持当前类型的资源!'] if title is None: return [1, '名称不能为空!'] if body is None: if src_type != 'reference': return [1, '内容不能为空!'] else: if re.search(r'^(http|https|ftp):\/\/.+$', source) is None: return [1, '请填写链接地址或者引用真实内容!'] body = '' else: if src_type == 'math': body = math_encode(escape.xhtml_unescape(body)) elif src_type == 'code': if code_type not in Agree_Code: return [1, '请选择代码种类!'] if article_type == "about": AF_Object = user.about article_id = str(user.about._id) 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, '未找到知识谱!']
def fun_new_article_pic(user, article_id=0, article_type='blog', title='', url='', thumb='', father_id=0, group_id='-1'): isnew = 0 if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if article_type == "about": AF_Object = About(_id=user.about._id) isnew = 0 elif article_type == "book-about": 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, '未找到该目录!']
def fun_article_delete_src(user, article_id=0, article_type='blog', src_type='code', alias=0, group_id='-1'): if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if src_type not in Agree_Src: return [1, '不支持当前类型的资源!'] if article_type == "about": AF_Object = About(_id=user.about._id) elif article_type == "book-about": 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, '未找到该知识谱!']
def fun_article_new_src(user, article_id='-1', article_type='blog', src_type='code', title='', body='', source='', code_type='python', math_type='inline', father_id='-1', group_id='-1'): if article_type not in Article_Type: return [1, '不支持当前文章类型!'] if src_type not in Agree_Src: return [1, '不支持当前类型的资源!'] if title is None: return [1, '名称不能为空!'] if body is None: if src_type != 'reference': return [1, '内容不能为空!'] else: if re.search(r'^(http|https|ftp):\/\/.+$', source) is None: return [1, '请填写链接地址或者引用真实内容!'] body = '' else: if src_type == 'math': body = math_encode(escape.xhtml_unescape(body)) elif src_type == 'code': if code_type not in Agree_Code: return [1, '请选择代码种类!'] if article_type == "about": AF_Object = user.about article_id = str(user.about._id) 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, '未找到知识谱!']
# write blog end elif article_type == "about": # write user about start AF_Object = user.about AF_Object.body = body AF_Object.env = user return [0, ''] # write user about end elif article_type == "book-about": try: book = Catalog(_id=group_id) except Exception, err: logging.error(traceback.format_exc()) logging.error('Catalog not exist, id %s' % group_id) else: limit = book.authority_verify(user) if test_auth(limit, A_WRITE) is False: return [1, '您无权修改摘要!'] book.about.body = body book.about.env = book return [0, '摘要更新成功!'] elif article_type == "comment": # write comment, maybe blog comment, topic reply, and so on return fun_update_comment(user=user, article_id=article_id, group_id=group_id, father_id=father_id, father_type=father_type, ref_comments=ref_comments, article_type=article_type,
# write blog end elif article_type == "about": # write user about start AF_Object = user.about AF_Object.body = body AF_Object.env = user return [0, ''] # write user about end elif article_type == "book-about": try: book = Catalog(_id=group_id) except Exception, err: logging.error(traceback.format_exc()) logging.error('Catalog not exist, id %s' % group_id) else: limit = book.authority_verify(user) if test_auth(limit, A_WRITE) is False: return [1, '您无权修改摘要!'] book.about.body = body book.about.env = book return [0, '摘要更新成功!'] elif article_type == "comment": # write comment, maybe blog comment, topic reply, and so on return fun_update_comment(user=user, article_id=article_id, group_id=group_id, father_id=father_id, father_type=father_type, ref_comments=ref_comments, article_type=article_type, body=body) # write comment end else: # for group return fun_update_group_article(user=user, group_id=group_id, article_id=article_id, article_type=article_type, title=title, body=body, classes=classes, do=do)