def tool_filter(item): if item.role is None: return True if xauth.get_current_role() == "admin": return True if xauth.get_current_role() == item.role: return True return False
def GET(self): """search files by name and content""" load_rules() key = xutils.get_argument("key", "") title = xutils.get_argument("title", "") category = xutils.get_argument("category", "") page = xutils.get_argument("page", 1, type = int) user_name = xauth.get_current_role() page_url = "/search/search?key=%s&category=%s&page="\ % (key, category) pagesize = xconfig.PAGE_SIZE offset = (page-1) * pagesize limit = pagesize if key == "" or key == None: return xtemplate.render("search_result.html", category=category, files=[], count=0) files = self.do_search(key, offset, pagesize) count = len(files) files = files[offset:offset+limit] return xtemplate.render("search_result.html", category = category, files = files, title = title, page_max = math.ceil(count/pagesize), page_url = page_url)
def GET(self): """search files by name and content""" if not mappings_loaded: load_mappings() key = xutils.get_argument("key", "") title = xutils.get_argument("title", "") content = xutils.get_argument("content", "") page = xutils.get_argument("page", 1, type=int) user_name = xauth.get_current_role() xutils.get_argument("page_url", "/search/search?key=%s&page=" % key) pagesize = config.PAGE_SIZE if key == "" or key == None: return xtemplate.render("file-list.html", files=[], count=0) # app 为None,不用全局使用session store = MemStore() store_key = "s_" + user_name + "-" + key # print("STORE KEY: ", store_key) if store.has_key(store_key): # print("HIT %s" % store_key) files = store[store_key] else: files = self.full_search(key) # store[store_key] = files count = len(files) pagestart = (page - 1) * pagesize files = files[pagestart:pagestart + pagesize] return xtemplate.render("file-list.html", files=files, count=count, title=title, content=content)
def GET(self): db = dao.get_file_db() user_name = xauth.get_current_role() # if user_name == "admin": # sql = "SELECT name, COUNT(*) AS amount FROM file_tag GROUP BY name ORDER BY amount DESC, name ASC"; # else: # sql = "SELECT name, COUNT(*) AS amount FROM file_tag WHERE groups in $groups GROUP BY name ORDER BY amount DESC, name ASC"; tag_list = get_taglist(db, user_name) return xtemplate.render("note/taglist.html", tag_list=tag_list)
def GET(self): db = dao.get_file_db() user_name = xauth.get_current_role() # if user_name == "admin": # sql = "SELECT name, COUNT(*) AS amount FROM file_tag GROUP BY name ORDER BY amount DESC, name ASC"; # else: # sql = "SELECT name, COUNT(*) AS amount FROM file_tag WHERE groups in $groups GROUP BY name ORDER BY amount DESC, name ASC"; groups = ["*", user_name] sql = "SELECT name, COUNT(*) AS amount FROM file_tag GROUP BY name ORDER BY amount DESC, name ASC" tag_list = db.query(sql, vars=dict(groups=groups)) return xtemplate.render("file/taglist.html", tag_list=list(tag_list))
def GET(self): id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) if id == "" and name == "": raise HTTPError(504) if id != "": id = int(id) file = dao.get_by_id(id) elif name is not None: file = dao.get_by_name(name) if file is None: raise web.notfound() if not file.is_public and xauth.get_current_user() is None: return xauth.redirect_to_login() db = xtables.get_file_table() pathlist = dao.get_pathlist(db, file) user_name = xauth.get_current_name() can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() if role != "admin" and file.groups != '*' and file.groups != role: raise web.seeother("/unauthorized") files = [] amount = 0 if file.type == "group": amount = db.count(where="parent_id=%s AND is_deleted=0" % file.id) files = db.select(where=dict(parent_id=file.id, is_deleted=0), order="priority DESC, sctime DESC", limit=10, offset=(page-1)*10) elif file.type == "post": file.content = file.content.replace(u'\xad', '\n') file.content = file.content.replace("\n", "<br/>") dao.visit_by_id(id) else: dao.visit_by_id(id) return xtemplate.render("file/view.html", file=file, content = file.get_content(), date2str=date2str, can_edit = can_edit, pathlist = pathlist, page_max = math.ceil(amount/10), page = page, page_url = "/file/view?id=%s&page=" % id, files = files)
def find_plugins(category): role = xauth.get_current_role() plugins = [] if role is None: # not logged in return plugins if category == "None": category = None for fname in xconfig.PLUGINS: p = xconfig.PLUGINS.get(fname) if p and xutils.attrget(p.clazz, "category") == category: required_role = xutils.attrget(p.clazz, "required_role") if role == "admin" or required_role is None or required_role == role: plugins.append(p) plugins.sort() return plugins
def find_plugins(category, orderby=None): role = xauth.get_current_role() user_name = xauth.current_name() plugins = [] if role is None: # not logged in return plugins if category == "None": category = None for fname in xconfig.PLUGINS_DICT: p = xconfig.PLUGINS_DICT.get(fname) if p and p.category == category: required_role = p.required_role if role == "admin" or required_role is None or required_role == role: plugins.append(p) return sorted_plugins(user_name, plugins, orderby)
def is_visible(self): import xauth if self.role != None: user_role = xauth.get_current_role() return user_role == self.role return True
def GET(self, op, id = None): if id is None: id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) show_menu = xutils.get_argument("show_menu", "true") != "false" show_search = xutils.get_argument("show_search", "true") != "false" orderby = xutils.get_argument("orderby", None) is_iframe = xutils.get_argument("is_iframe", "false") user_name = xauth.current_name() show_add_file = False title = None show_pagination = True show_search_div = False kw = Storage() kw.show_left = False kw.show_groups = False kw.show_aside = True kw.groups = [] kw.recommended_notes = [] if id == "0": raise web.found("/") # 回收站的笔记也能看到 if id == "" and name == "": raise HTTPError(504) if id != "": file = NOTE_DAO.get_by_id(id) elif name is not None: file = NOTE_DAO.get_by_name(name) if file is None: raise web.notfound() if file.type != "group" and not file.is_public and user_name != "admin" and user_name != file.creator: raise web.seeother("/unauthorized") pathlist = xutils.call("note.list_path", file) can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() # 定义一些变量 show_mdate = False files = [] recent_created = [] amount = 0 show_recommend = False template_name = "note/view.html" next_note = None prev_note = None title = file.name if file.type == "group": if orderby != None and file.orderby != orderby: NOTE_DAO.update(where = dict(id = file.id, creator = file.creator), orderby = orderby) else: orderby = file.orderby files = NOTE_DAO.list_by_parent(user_name, file.id, (page-1)*pagesize, pagesize, orderby) amount = NOTE_DAO.count(user_name, file.id) content = file.content show_search_div = True show_add_file = True show_mdate = True kw.show_aside = False elif file.type == "md" or file.type == "text": content = file.content show_recommend = True show_pagination = False if op == "edit": show_recommend = False template_name = "note/editor/markdown_edit.html" elif file.type == "list": kw.show_aside = False show_pagination = False else: # post/html 等其他类型 handle_note_content(file) show_recommend = True show_pagination = False # 处理笔记背后的文件系统 handle_note_files(kw, file) if show_recommend and user_name is not None: # 推荐系统 handle_note_recommend(kw, file, user_name) xmanager.fire("note.view", file) if op == "edit": kw.show_aside = False if is_iframe == "true": show_menu = False show_search = False kw.show_menu = show_menu kw.show_search = show_search # 如果是页面,需要查出上级目录列表 handle_left_dir(kw, user_name, file, op) return xtemplate.render(template_name, html_title = title, file = file, note_id = id, op = op, show_mdate = show_mdate, show_add_file = show_add_file, show_pagination = show_pagination, can_edit = can_edit, pathlist = pathlist, page_max = math.ceil(amount/pagesize), page = page, page_url = "/note/view?id=%s&orderby=%s&page=" % (id, orderby), files = files, recent_created = recent_created, is_iframe = is_iframe, **kw)
def GET(self, op): id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) db = xtables.get_file_table() user_name = xauth.get_current_name() show_add_file = False if id == "" and name == "": raise HTTPError(504) if id != "": id = int(id) file = dao.get_by_id(id, db=db) elif name is not None: file = dao.get_by_name(name, db=db) if file is None: raise web.notfound() if not file.is_public and user_name != "admin" and user_name != file.creator: raise web.seeother("/unauthorized") show_search_div = False pathlist = dao.get_pathlist(db, file) can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() # 定义一些变量 files = [] amount = 0 template_name = "note/view.html" xconfig.note_history.put( dict(user=user_name, file_id=id, name=file.name)) if file.type == "group": amount = db.count( where="parent_id=$id AND is_deleted=0 AND creator=$creator", vars=dict(id=file.id, creator=user_name)) files = db.select(where=dict(parent_id=file.id, is_deleted=0, creator=user_name), order="priority DESC, name", limit=pagesize, offset=(page - 1) * pagesize) content = file.content show_search_div = True show_add_file = True elif file.type == "md" or file.type == "text": content = file.content if op == "edit": template_name = "note/markdown_edit.html" else: content = file.content content = content.replace(u'\xad', '\n') content = content.replace(u'\n', '<br/>') file.data = file.data.replace(u"\xad", "\n") file.data = file.data.replace(u'\n', '<br/>') if file.data == None or file.data == "": file.data = content xmanager.fire("note.view", file) return xtemplate.render(template_name, file=file, op=op, show_add_file=show_add_file, can_edit=can_edit, pathlist=pathlist, page_max=math.ceil(amount / pagesize), page=page, page_url="/file/view?id=%s&page=" % id, files=files)
def GET(self, op, id=None): if id is None: id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) show_menu = xutils.get_argument("show_menu", "true") != "false" show_search = xutils.get_argument("show_search", "true") != "false" orderby = xutils.get_argument("orderby", None) is_iframe = xutils.get_argument("is_iframe", "false") token = xutils.get_argument("token", "") user_name = xauth.current_name() kw = Storage() kw.show_left = False kw.show_groups = False kw.show_aside = True kw.groups = [] kw.files = [] kw.op = op kw.user_name = user_name kw.page = page kw.orderby = orderby kw.pagesize = pagesize kw.recommended_notes = [] kw.show_add_file = False kw.template_name = "note/page/view.html" kw.search_action = "/note/timeline" kw.search_placeholder = "搜索笔记" if id == "0": raise web.found("/") # 回收站的笔记也能看到 file = find_note_for_view(token, id, name) if file is None: raise web.notfound() if token == "": check_auth(file, user_name) pathlist = NOTE_DAO.list_path(file) can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() # 定义一些变量 show_mdate = False recent_created = [] show_recommend = False next_note = None prev_note = None event_ctx = Storage(id=file.id, user_name=user_name) xmanager.fire("note.view", event_ctx) view_func = VIEW_FUNC_DICT.get(file.type, view_md_func) view_func(file, kw) if show_recommend and user_name is not None: # 推荐系统 handle_note_recommend(kw, file, user_name) if op == "edit": kw.show_aside = False kw.show_search = False kw.show_comment = False if is_iframe == "true": kw.show_menu = False kw.show_search = False template_name = kw['template_name'] del kw['template_name'] # 如果是页面,需要查出上级目录列表 handle_left_dir(kw, user_name, file, op) return xtemplate.render_by_ua( template_name, html_title=file.name, file=file, note_id=id, show_mdate=show_mdate, can_edit=can_edit, pathlist=pathlist, page_url="/note/view?id=%s&orderby=%s&page=" % (id, orderby), recent_created=recent_created, CREATE_BTN_TEXT_DICT=CREATE_BTN_TEXT_DICT, is_iframe=is_iframe, **kw)
def GET(self, op): id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) show_menu = xutils.get_argument("show_menu", "true") != "false" orderby = xutils.get_argument("orderby", "mtiem_desc") user_name = xauth.get_current_name() show_add_file = False title = None show_pagination = True show_search_div = False if id == "0": raise web.found("/") # 回收站的笔记也能看到 if id == "" and name == "": raise HTTPError(504) if id != "": file = xutils.call("note.get_by_id", id) elif name is not None: file = xutils.call("note.get_by_name", name, db=db) if file is None: raise web.notfound() if file.type != "group" and not file.is_public and user_name != "admin" and user_name != file.creator: raise web.seeother("/unauthorized") pathlist = xutils.call("note.list_path", file) can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() # 定义一些变量 show_groups = False show_mdate = False files = [] recent_created = [] groups = [] amount = 0 show_recommend = False template_name = "note/view.html" next_note = None prev_note = None filelist = None xconfig.note_history.put(dict(user=user_name, link = "/note/view?id=%s" % id, name = file.name)) recommended_notes = [] title = file.name if file.type == "group": files = xutils.call("note.list_by_parent", user_name, file.id, (page-1)*pagesize, pagesize, orderby) amount = xutils.call("note.count", user_name, file.id) content = file.content show_search_div = True show_add_file = True show_mdate = True elif file.type == "md" or file.type == "text": content = file.content show_recommend = True show_pagination = False if op == "edit": show_recommend = False template_name = "note/editor/markdown_edit.html" else: content = file.content content = content.replace(u'\xad', '\n') content = content.replace(u'\n', '<br/>') file.data = file.data.replace(u"\xad", "\n") file.data = file.data.replace(u'\n', '<br/>') if file.data == None or file.data == "": file.data = content show_recommend = True show_pagination = False fpath = os.path.join(xconfig.UPLOAD_DIR, file.creator, str(file.parent_id), str(id)) # 处理相册 if file.type == "gallery": if os.path.exists(fpath): filelist = fsutil.list_files(fpath, webpath = True) else: filelist = [] file.path = fpath if show_recommend and user_name is not None: show_groups = False # 推荐系统 ctx = Storage(id=file.id, name = file.name, creator = file.creator, content = file.content, parent_id = file.parent_id, result = []) xmanager.fire("note.recommend", ctx) recommended_notes = ctx.result next_note = xutils.call("note.find_next_note", file) prev_note = xutils.call("note.find_prev_note", file) xmanager.fire("note.view", file) show_aside = True if op == "edit": show_aside = False return xtemplate.render(template_name, show_aside = show_aside, html_title = title, file = file, path = fpath, filelist = filelist, note_id = id, op = op, show_mdate = show_mdate, show_add_file = show_add_file, show_menu = show_menu, show_pagination = show_pagination, can_edit = can_edit, pathlist = pathlist, page_max = math.ceil(amount/pagesize), page = page, page_url = "/note/view?id=%s&orderby=%s&page=" % (id, orderby), files = files, recent_created = recent_created, show_groups = show_groups, groups = groups, prev_note = prev_note, next_note = next_note, recommended_notes = recommended_notes)
def GET(self, op): id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) show_menu = xutils.get_argument("show_menu", "true") != "false" db = xtables.get_file_table() user_name = xauth.get_current_name() show_add_file = False title = None show_pagination = True show_search_div = False if id == "" and name == "": raise HTTPError(504) if id != "": id = int(id) file = dao.get_by_id(id, db=db) elif name is not None: file = dao.get_by_name(name, db=db) if file is None: raise web.notfound() if file.is_deleted == 1: raise web.seeother("/") if file.type != "group" and not file.is_public and user_name != "admin" and user_name != file.creator: raise web.seeother("/unauthorized") pathlist = dao.get_pathlist(db, file) can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() # 定义一些变量 show_groups = False show_mdate = False files = [] recent_created = [] groups = [] amount = 0 show_recommend = False template_name = "note/view.html" next_note = None prev_note = None xconfig.note_history.put( dict(user=user_name, link="/note/view?id=%s" % id, name=file.name)) recommended_notes = [] title = file.name if file.type == "group": where_sql = "parent_id=$parent_id AND is_deleted=0 AND (creator=$creator OR is_public=1)" if xauth.is_admin(): where_sql = "parent_id=$parent_id AND is_deleted=0" amount = db.count(where=where_sql, vars=dict(parent_id=file.id, creator=user_name)) files = db.select(where=where_sql, vars=dict(parent_id=file.id, is_deleted=0, creator=user_name), order="name", limit=pagesize, offset=(page - 1) * pagesize) content = file.content show_search_div = True show_add_file = True show_mdate = True # recent_created = xutils.call("note.list_recent_created", file.id, 10) elif file.type == "md" or file.type == "text": content = file.content if op == "edit": template_name = "note/markdown_edit.html" show_recommend = True show_pagination = False else: content = file.content content = content.replace(u'\xad', '\n') content = content.replace(u'\n', '<br/>') file.data = file.data.replace(u"\xad", "\n") file.data = file.data.replace(u'\n', '<br/>') if file.data == None or file.data == "": file.data = content show_recommend = True show_pagination = False if show_recommend: show_groups = False # 推荐系统 ctx = Storage(id=file.id, name=file.name, creator=file.creator, content=file.content, parent_id=file.parent_id, result=[]) xmanager.fire("note.recommend", ctx) recommended_notes = ctx.result next_note = xutils.call("note.find_next_note", file) prev_note = xutils.call("note.find_prev_note", file) xmanager.fire("note.view", file) show_aside = True if op == "edit": show_aside = False return xtemplate.render(template_name, show_aside=show_aside, html_title=title, file=file, note_id=id, op=op, show_mdate=show_mdate, show_add_file=show_add_file, show_menu=show_menu, show_pagination=show_pagination, can_edit=can_edit, pathlist=pathlist, page_max=math.ceil(amount / pagesize), page=page, page_url="/note/view?id=%s&page=" % id, files=files, recent_created=recent_created, show_groups=show_groups, groups=groups, prev_note=prev_note, next_note=next_note, recommended_notes=recommended_notes)