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=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)