def GET(self): user_name = xauth.current_name() year = xutils.get_argument("year", time.strftime("%Y")) month = xutils.get_argument("month", time.strftime("%m")) if len(month) == 1: month = '0' + month date = year + "-" + month created = xutils.call("note.list_by_date", "ctime", user_name, date) by_name = xutils.call("note.list_by_date", "name", user_name, year + "_" + month) notes = [] dup = set() for v in created + by_name: if v.id in dup: continue dup.add(v.id) notes.append(v) return xtemplate.render("note/list_by_date.html", show_aside=True, link_by_month=link_by_month, year=int(year), month=int(month), notes=notes)
def GET(self): id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") file = None print("remove", id, name) if id == "" and name == "": return dict(code="fail", message="id,name至少一个不为空") if id != "": file = xutils.call("note.get_by_id", id) elif name != "": file = xutils.call("note.get_by_name", name) if file is None: return dict(code="fail", message="文件不存在") creator = xauth.current_name() if not xauth.is_admin() and file.creator != creator: return dict(code="fail", message="没有删除权限") if file.type == "group": children_count = xutils.call("note.count", creator, file.id) if children_count > 0: return dict(code="fail", message="分组不为空") xutils.call("note.delete", id) return dict(code="success")
def GET(self): page = xutils.get_argument("page", 1, type=int) user_name = xauth.get_current_name() pagesize = xconfig.PAGE_SIZE offset = (page - 1) * pagesize files = xutils.call("note.list_note", user_name, 0, offset, pagesize) amount = xutils.call("note.count", user_name, 0) parent = PathNode("智能分类", "/note/types") return xtemplate.render(VIEW_TPL, show_aside=True, file_type="group", pathlist=[ parent, Storage(name="默认分类", type="group", url="/note/default") ], files=files, file=Storage(name="默认分类", type="group"), page=page, page_max=math.ceil(amount / pagesize), groups=xutils.call("note.list_group"), show_mdate=True, page_url="/note/default?page=")
def POST(self): id = xutils.get_argument("id") name = xutils.get_argument("name") if name == "" or name is None: return dict(code="fail", message="名称为空") old = xutils.call("note.get_by_id", id) if old is None: return dict(code="fail", message="笔记不存在") if old.creator != xauth.get_current_name(): return dict(code="fail", message="没有权限") file = xutils.call("note.get_by_name", name) if file is not None and file.is_deleted == 0: return dict(code="fail", message="%r已存在" % name) xutils.call("note.update", dict(id=id), name=name) event_body = dict(action="rename", id=id, name=name, type=old.type) xmanager.fire("note.updated", event_body) xmanager.fire("note.rename", event_body) if old.type == "group": cacheutil.prefix_del("group.list") return dict(code="success")
def record_history(ctx): id = ctx.get("id") content = ctx.get("content") version = ctx.get("version") mtime = ctx.get("mtime") name = ctx.get("name") xutils.call("note.add_history", id, version, ctx)
def POST(self): user_name = xauth.current_name() part_file = True chunksize = 5 * 1024 * 1024 chunk = xutils.get_argument("chunk", 0, type=int) chunks = xutils.get_argument("chunks", 1, type=int) file = xutils.get_argument("file", {}) prefix = xutils.get_argument("prefix", "") dirname = xutils.get_argument("dirname", xconfig.DATA_DIR) dirname = dirname.replace("$DATA", xconfig.DATA_DIR) note_id = xutils.get_argument("note_id") # 不能访问上级目录 if ".." in dirname: return dict(code="fail", message="can not access parent directory") filename = None webpath = "" origin_name = "" if hasattr(file, "filename"): origin_name = file.filename xutils.trace("UploadFile", file.filename) filename = os.path.basename(file.filename) filename = xutils.get_real_path(filename) if dirname == "auto": filename = generate_filename(filename, prefix) filepath, webpath = xutils.get_upload_file_path(user_name, filename, replace_exists=True) dirname = os.path.dirname(filepath) filename = os.path.basename(filepath) else: # TODO check permission. pass if part_file: tmp_name = "%s_%d.part" % (filename, chunk) seek = 0 else: tmp_name = filename seek = chunk * chunksize xutils.makedirs(dirname) tmp_path = os.path.join(dirname, tmp_name) with open(tmp_path, "wb") as fp: fp.seek(seek) if seek != 0: xutils.log("seek to {}", seek) for file_chunk in file.file: fp.write(file_chunk) else: return dict(code="fail", message="require file") if part_file and chunk+1==chunks: self.merge_files(dirname, filename, chunks) try_touch_note(note_id) if note_id != None and note_id != "": xutils.call("note.touch", note_id) return dict(code="success", webpath=webpath, link=get_link(origin_name, webpath))
def GET(self): if xauth.has_login(): user_name = xauth.get_current_name() tag_list = xutils.call("note.list_tag", user_name) else: tag_list = xutils.call("note.list_tag", "") return xtemplate.render("note/taglist.html", show_aside=True, tag_list=tag_list)
def GET(self): id = xutils.get_argument("id", "") parent_id = xutils.get_argument("parent_id", "") file = xutils.call("note.get_by_id", id) if file is None: return dict(code="fail", message="file not exists") xutils.call("note.update", dict(id=id), parent_id=parent_id) return dict(code="success")
def GET(self, orderby="edit", show_notice=True): if not xauth.has_login(): raise web.seeother("/note/public") if xutils.sqlite3 is None: raise web.seeother("/fs_list") days = xutils.get_argument("days", 30, type=int) page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) page = max(1, page) offset = max(0, (page - 1) * pagesize) limit = pagesize time_attr = "ctime" show_mdate = False show_cdate = False show_adate = False dir_type = "recent_edit" creator = xauth.get_current_name() if orderby == "viewed": html_title = "Recent Viewed" files = xutils.call("note.list_recent_viewed", creator, offset, limit) time_attr = "atime" show_adate = True dir_type = "recent_viewed" elif orderby == "created": html_title = "Recent Created" files = xutils.call("note.list_recent_created", creator, offset, limit) time_attr = "ctime" show_cdate = True dir_type = "recent_created" else: html_title = "Recent Updated" files = xutils.call("note.list_recent_edit", creator, offset, limit) time_attr = "mtime" show_mdate = True dir_type = "recent_edit" count = NOTE_DAO.count_user_note(creator) return xtemplate.render(VIEW_TPL, pathlist=type_node_path(html_title, ""), html_title=html_title, file_type="group", dir_type=dir_type, files=files, show_aside=True, page=page, show_cdate=show_cdate, show_mdate=show_mdate, show_adate=show_adate, page_max=math.ceil(count / xconfig.PAGE_SIZE), page_url="/note/recent_%s?page=" % orderby)
def GET(self): note_id = xutils.get_argument("id") creator = xauth.current_name() note = xutils.call("note.get_by_id_creator", note_id, creator) if note is None: history_list = [] else: history_list = xutils.call("note.list_history", note_id) return xtemplate.render("note/history_list.html", history_list = history_list, show_aside = True)
def GET(self): note_id = xutils.get_argument("id") version = xutils.get_argument("version") creator = xauth.current_name() note = xutils.call("note.get_by_id_creator", note_id, creator) content = "" if note != None: note = xutils.call("note.get_history", note_id, version) if note != None: content = note.content return dict(code = "success", data = content)
def POST(self): id = xutils.get_argument("file_id") tags_str = xutils.get_argument("tags") user_name = xauth.get_current_name() note = xutils.call("note.get_by_id", id) if tags_str is None or tags_str == "": xutils.call("note.update_tags", note_id = id, creator = user_name, tags = []) return dict(code="success") new_tags = tags_str.split(" ") xutils.call("note.update_tags", note_id = id, creator = user_name, tags = new_tags) return dict(code="success", message="", data="OK")
def POST(self): is_public = xutils.get_argument("public", "") id = xutils.get_argument("id") content = xutils.get_argument("content") version = xutils.get_argument("version", 0, type=int) file_type = xutils.get_argument("type") name = xutils.get_argument("name", "") db = xtables.get_file_table() file = xutils.call("note.get_by_id", id) if file is None: return xtemplate.render("note/view.html", pathlist=[], file=file, content=content, error="笔记不存在") # 理论上一个人是不能改另一个用户的存档,但是可以拷贝成自己的 # 所以权限只能是创建者而不是修改者 update_kw = dict(content=content, type=file_type, size=len(content), version=version) if name != "" and name != None: update_kw["name"] = name # 不再处理文件,由JS提交 rowcount = xutils.call("note.update", where=dict(id=id, version=version), **update_kw) if rowcount > 0: xmanager.fire( 'note.updated', dict(id=id, name=file.name, mtime=dateutil.format_datetime(), content=content, version=version + 1)) raise web.seeother("/note/view?id=" + str(id)) else: # 传递旧的content cur_version = file.version file.content = content file.version = version return xtemplate.render( "note/view.html", pathlist=[], file=file, content=content, error="更新失败, 版本冲突,当前version={},最新version={}".format( version, cur_version))
def POST(self): id = xutils.get_argument("id") if id == "": return msg = xutils.call("message.find_by_id", id) if msg is None: return dict(code="fail", message="data not exists") if msg.user != xauth.current_name(): return dict(code="fail", message="no permission") xutils.call("message.delete", id) return dict(code="success")
def GET(self, orderby="edit", show_notice=False): if not xauth.has_login(): raise web.seeother("/note/public") if xutils.sqlite3 is None: raise web.seeother("/fs_list") days = xutils.get_argument("days", 30, type=int) page = xutils.get_argument("page", 1, type=int) pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) page = max(1, page) offset = max(0, (page - 1) * pagesize) limit = pagesize time_attr = "ctime" creator = xauth.get_current_name() if orderby == "viewed": html_title = "Recent Viewed" files = xutils.call("note.list_recent_viewed", creator, offset, limit) time_attr = "atime" elif orderby == "created": html_title = "Recent Created" files = xutils.call("note.list_recent_created", None, offset, limit) time_attr = "ctime" else: html_title = "Recent Updated" files = xutils.call("note.list_recent_edit", None, offset, limit) time_attr = "mtime" groups = xutils.call("note.list_group", creator) count = xutils.call("note.count_user_note", creator) return xtemplate.render("note/recent.html", html_title=html_title, pathlist=[ Storage(name=T(html_title), type="group", url="/note/recent_" + orderby) ], file_type="group", files=files, file=Storage(name=T(html_title), type="group"), groups=groups, show_notice=show_notice, show_mdate=True, show_groups=False, show_aside=True, page=page, time_attr=time_attr, page_max=math.ceil(count / xconfig.PAGE_SIZE), page_url="/note/recent_%s?page=" % orderby)
def POST(self): id = xutils.get_argument("file_id") tags_str = xutils.get_argument("tags") tag_db = xtables.get_file_tag_table() user_name = xauth.get_current_name() note = xutils.call("note.get_by_id", id) if tags_str is None or tags_str == "": # tag_db.delete(where=dict(file_id=id, user=user_name)) xutils.call("note.update", dict(id=id, creator=user_name), tags=[]) return dict(code="success") new_tags = tags_str.split(" ") xutils.call("note.update", dict(id=id, creator=user_name), tags=new_tags) return dict(code="success", message="", data="OK")
def fill_note_info(files): db = xtables.get_note_table() for file in files: if file.category == "note": parent = xutils.call("note.get_by_id", file.parent_id) if parent is not None: file.parent_name = parent.name
def POST(self): id = xutils.get_argument("id") content = xutils.get_argument("content") status = xutils.get_argument("status") location = xutils.get_argument("location", "") user_name = xauth.get_current_name() db = xtables.get_message_table() # 对消息进行语义分析处理,后期优化把所有规则统一管理起来 ctx = Storage(id=id, content=content, user=user_name, type="") for rule in rules: rule.match_execute(ctx, content) ip = get_remote_ip() if id == "" or id is None: ctime = xutils.get_argument("date", xutils.format_datetime()) inserted_id = xutils.call("message.create", content=content, user=user_name, status=get_status_by_code(status), ip=ip, mtime=ctime, ctime=ctime) id = inserted_id xmanager.fire( 'message.add', dict(id=id, user=user_name, content=content, ctime=ctime)) return dict(code="success", data=dict(id=inserted_id, content=content, ctime=ctime)) else: update_message_content(id, user_name, content) return dict(code="success", data=dict(id=id))
def handle(self, input): self.rows = 0 user_name = xauth.current_name() stat_list = [] admin_stat_list = [] stat_list.append( ["我的笔记", dbutil.count_table("note_tiny:%s" % user_name)]) stat_list.append( ["笔记本", xutils.call("note.count_by_type", user_name, "group")]) stat_list.append( ["备忘总数", dbutil.count_table("message:%s" % user_name)]) if xauth.is_admin(): admin_stat_list.append( ["note_full", dbutil.count_table("note_full")]) admin_stat_list.append( ["note_tiny", dbutil.count_table("note_tiny")]) admin_stat_list.append( ["note_index", dbutil.count_table("note_index")]) admin_stat_list.append( ["note_history", dbutil.count_table("note_history")]) admin_stat_list.append( ["note_comment", dbutil.count_table("note_comment")]) admin_stat_list.append( ["notebook", dbutil.count_table("notebook")]) admin_stat_list.append(["message", dbutil.count_table("message")]) admin_stat_list.append( ["schedule", dbutil.count_table("schedule")]) admin_stat_list.append(["user", dbutil.count_table("user")]) self.writetemplate(HTML, stat_list=stat_list, admin_stat_list=admin_stat_list)
def handle(self, input): self.rows = 0 user_name = xauth.current_name() stat_list = [] admin_stat_list = [] stat_list.append(["我的项目", xutils.call("note.count_by_type", user_name, "group")]) stat_list.append(["我的笔记", dbutil.count_table("note_tiny:%s" % user_name)]) stat_list.append(["待办事项", dbutil.count_table("message:%s" % user_name)]) stat_list.append(["搜索记录", dbutil.count_table("search_history:%s" % user_name)]) stat_list.append(["我的评论", dbutil.count_table("comment_index:%s" % user_name)]) if xauth.is_admin(): admin_stat_list.append(["note_full", dbutil.count_table("note_full")]) admin_stat_list.append(["note_tiny", dbutil.count_table("note_tiny")]) admin_stat_list.append(["note_index", dbutil.count_table("note_index")]) admin_stat_list.append(["note_history", dbutil.count_table("note_history")]) admin_stat_list.append(["note_comment", dbutil.count_table("note_comment")]) admin_stat_list.append(["comment_index", dbutil.count_table("comment_index")]) admin_stat_list.append(["note_deleted", dbutil.count_table("note_deleted")]) admin_stat_list.append(["notebook", dbutil.count_table("notebook")]) admin_stat_list.append(["search_history", dbutil.count_table("search_history")]) admin_stat_list.append(["message", dbutil.count_table("message")]) admin_stat_list.append(["msg_search_history", dbutil.count_table("msg_search_history")]) admin_stat_list.append(["msg_history", dbutil.count_table("msg_history")]) admin_stat_list.append(["msg_key", dbutil.count_table("msg_key")]) admin_stat_list.append(["user_stat", dbutil.count_table("user_stat")]) admin_stat_list.append(["schedule", dbutil.count_table("schedule")]) admin_stat_list.append(["user", dbutil.count_table("user")]) admin_stat_list.append(["record", dbutil.count_table("record")]) self.writetemplate(HTML, stat_list = stat_list, admin_stat_list = admin_stat_list)
def GET(self, tagname): tagname = xutils.unquote(tagname) page = xutils.get_argument("page", 1, type=int) limit = xutils.get_argument("limit", xconfig.PAGE_SIZE, type=int) offset = (page - 1) * limit if xauth.has_login(): user_name = xauth.get_current_name() else: user_name = "" # count_sql = "SELECT COUNT(1) AS amount FROM file_tag WHERE LOWER(name) = $name AND (user=$user OR is_public=1)" # sql = "SELECT f.* FROM file f, file_tag ft ON ft.file_id = f.id WHERE LOWER(ft.name) = $name AND (ft.user=$user OR ft.is_public=1) ORDER BY f.ctime DESC LIMIT $offset, $limit" # count = db.query(count_sql, vars=dict(name=tagname.lower(), user=user_name))[0].amount # files = db.query(sql, # vars=dict(name=tagname.lower(), offset=offset, limit=limit, user=user_name)) # files = [dao.FileDO.fromDict(f) for f in files] files = xutils.call("note.list_by_tag", user_name, tagname) count = len(files) files = files[offset:offset + limit] return xtemplate.render("note/tagname.html", show_aside=True, tagname=tagname, files=files, show_mdate=True, page_max=math.ceil(count / limit), page=page)
def GET(self): id = xutils.get_argument("id") file = xutils.call("note.get_by_id", id) user_name = xauth.current_name() if file.is_public != 1 and user_name != "admin" and user_name != file.creator: raise web.seeother("/unauthorized") return xtemplate.render("note/tools/print.html", show_menu = False, note = file)
def GET(self, id): note = xutils.call("note.get_by_id", id) tags = None if note and note.tags != None: tags = [Storage(name=name) for name in note.tags] if not isinstance(tags, list): tags = [] return dict(code="", message="", data=tags)
def GET(self): page = xutils.get_argument("page", 1, type=int) page = max(1, page) offset = (page - 1) * xconfig.PAGE_SIZE files = xutils.call("note.list_public", offset, xconfig.PAGE_SIZE) count = xutils.call("note.count_public") return xtemplate.render( VIEW_TPL, show_aside=True, pathlist=[Storage(name="公开笔记", url="/note/public")], file_type="group", files=files, page=page, show_cdate=True, groups=xutils.call("note.list_group"), page_max=math.ceil(count / xconfig.PAGE_SIZE), page_url="/note/public?page=")
def GET(self, id): creator = xauth.current_name() tags = xutils.call("note.get_tags", creator, id) if tags != None: tags = [Storage(name=name) for name in tags] if not isinstance(tags, list): tags = [] return dict(code="", message="", data=tags)
def GET(self): id = xutils.get_argument("id") file = xutils.call("note.get_by_id", id) user_name = xauth.current_name() check_auth(file, user_name) return xtemplate.render("note/page/print.html", show_menu=False, note=file)
def GET(self): pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int) page = xutils.get_argument("page", 1, type=int) status = xutils.get_argument("status") key = xutils.get_argument("key") tag = xutils.get_argument("tag") offset = (page - 1) * pagesize user_name = xauth.get_current_name() # 未完成任务的分页 undone_pagesize = 1000 status_num = None kw = "1=1" if status == "created": status_num = 0 kw = "status = 0" pagesize = undone_pagesize if status == "done": status_num = 100 kw = "status = 100" if status == "suspended": status_num = 50 kw = "status = 50" pagesize = undone_pagesize if tag == "file": chatlist, amount = xutils.call("message.list_file", user_name, offset, pagesize) elif key != "" and key != None: chatlist, amount = xutils.call("message.search", user_name, key, offset, pagesize) else: chatlist, amount = xutils.call("message.list", user_name, status_num, offset, pagesize) chatlist.reverse() page_max = math.ceil(amount / pagesize) chatlist = list(map(process_message, chatlist)) return dict(code="success", message="", pagesize=pagesize, data=chatlist, amount=amount, page_max=page_max, current_user=xauth.get_current_name())
def GET(self): user = xauth.current_name() files = xutils.call("note.list_sticky", user) return xtemplate.render(VIEW_TPL, pathlist=[PathNode("置顶笔记", "/note/sticky")], file_type="group", files=files, show_aside=True, show_mdate=True)
def get_message_count(user): if user is None: return 0 try: return xutils.call("message.count", user, 0) except: # 数据库被锁 xutils.print_exc() return 0
def GET(self): id = xutils.get_argument("id", "", type=int) filetype = xutils.get_argument("filetype", "") data = xutils.call("note.list_group", xauth.get_current_name()) web.header("Content-Type", "text/html; charset=utf-8") return xtemplate.render("note/group_select.html", id=id, filelist=data, file_type="group")