def handle_note_files(kw, file): fpath = os.path.join(xconfig.UPLOAD_DIR, file.creator, str(file.parent_id), str(file.id)) filelist = [] # 处理相册 if file.type == "gallery": if os.path.exists(fpath): filelist = fsutil.list_files(fpath, webpath=True) file.path = fpath kw.path = fpath kw.filelist = filelist
def view_gallery_func(file, kw): fpath = os.path.join(xconfig.UPLOAD_DIR, file.creator, str(file.parent_id), str(file.id)) filelist = [] # 处理相册 # print(file) fpath = fsutil.get_gallery_path(file) # print(fpath) if fpath != None: filelist = fsutil.list_files(fpath, webpath=True) file.path = fpath kw.show_aside = False kw.path = fpath kw.filelist = filelist
def GET(self): path = xutils.get_argument("path") path = xutils.get_real_path(path) error = "" if path == None or path == "": path = xconfig.DATA_DIR if not os.path.exists(path): error = "[%s] not exits!" % path filelist = [] else: filelist = fsutil.list_files(path) return xtemplate.render("fs/fs_sidebar.html", error = error, path = path, filelist = filelist)
def handle_note_files(kw, file): fpath = os.path.join(xconfig.UPLOAD_DIR, file.creator, str(file.parent_id), str(file.id)) filelist = [] # 处理相册 if file.type == "gallery": print(file) fpath = fsutil.get_gallery_path(file) print(fpath) if fpath != None: filelist = fsutil.list_files(fpath, webpath = True) file.path = fpath kw.show_aside = False kw.path = fpath kw.filelist = filelist file.path = fpath
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)