def create_message(**kw): tag = kw['tag'] if tag == 'key': key = "msg_key:%s:%s" % (kw['user'], dbutil.timeseq()) else: key = "message:%s:%s" % (kw['user'], dbutil.timeseq()) kw['id'] = key dbutil.put(key, kw) return key
def create_note(note_dict): content = note_dict["content"] data = note_dict["data"] creator = note_dict["creator"] priority = note_dict["priority"] mtime = note_dict["mtime"] parent_id = note_dict.get("parent_id", "0") name = note_dict.get("name") note_id = dbutil.timeseq() note_dict["id"] = note_id kv_put_note(note_id, note_dict) # 更新分组下面页面的数量 TODO update_children_count(note_dict["parent_id"]) xmanager.fire("note.add", dict(name=name, type=type)) # 创建对应的文件夹 if type != "group": dirname = os.path.join(xconfig.UPLOAD_DIR, creator, str(parent_id), str(note_id)) else: dirname = os.path.join(xconfig.UPLOAD_DIR, creator, str(note_id)) xutils.makedirs(dirname) return note_id
def add_cron_task(url, mtime, ctime, tm_wday, tm_hour, tm_min, name="", message="", sound=0, webpage=0): id = dbutil.timeseq() key = "schedule:%s" % id data = dict(id=id, name=name, url=url, mtime=xutils.format_datetime(), ctime=xutils.format_datetime(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min, message=message, sound=sound, webpage=webpage) dbutil.put(key, data) return id
def create_note(note_dict): content = note_dict["content"] data = note_dict["data"] creator = note_dict["creator"] priority = note_dict["priority"] mtime = note_dict["mtime"] parent_id = note_dict.get("parent_id", "0") name = note_dict.get("name") note_id = dbutil.timeseq() note_dict["id"] = note_id kv_put_note(note_id, note_dict) # 更新分组下面页面的数量 update_children_count(note_dict["parent_id"]) xmanager.fire("note.add", dict(name=name, type=type)) # 创建对应的文件夹 if type == "gallery": dirname = os.path.join(xconfig.UPLOAD_DIR, creator, str(note_id)) xutils.makedirs(dirname) # 更新统计数量 refresh_note_stat(creator) # 更新目录修改时间 touch_note(parent_id) return note_id
def add_edit_log(note): creator = note.creator note_id = note.id delete_old_edit_log(creator, note_id) key = "note_edit_log:%s:%s" % (creator, dbutil.timeseq()) edit_log = Storage(id=note_id) dbutil.put(key, edit_log)
def create_message(**kw): if xconfig.DB_ENGINE == "sqlite": db = xtables.get_message_table() return db.insert(**kw) else: key = "message:%s:%s" % (kw['user'], dbutil.timeseq()) kw['id'] = key dbutil.put(key, kw) return key
def save_comment(comment): timeseq = dbutil.timeseq() comment["timeseq"] = timeseq key = "note_comment:%s:%s" % (comment["note_id"], timeseq) dbutil.put(key, comment) key2 = "comment_index:%s:%s" % (comment["user"], timeseq) comment_index = comment.copy() dbutil.put(key2, comment_index)
def add_visit_log(user_name, note): note_id = note.id # 先删除历史的浏览记录,只保留最新的 delete_old_visit_log(user_name, note_id) key = "note_visit_log:%s:%s" % (user_name, dbutil.timeseq()) visit_log = Storage(id=note_id) dbutil.put(key, visit_log)
def POST(self): id = xutils.get_argument("id") name = xutils.get_argument("name") url = xutils.get_argument("url") tm_wday = xutils.get_argument("tm_wday") tm_hour = xutils.get_argument("tm_hour") tm_min = xutils.get_argument("tm_min") message = xutils.get_argument("message") sound_value = xutils.get_argument("sound") webpage_value = xutils.get_argument("webpage") sound = 1 if sound_value == "on" else 0 webpage = 1 if webpage_value == "on" else 0 # db = xtables.get_schedule_table() if id == "" or id is None: id = dbutil.timeseq() key = "schedule:%s" % id data = dict(id=id, name=name, url=url, mtime=xutils.format_datetime(), ctime=xutils.format_datetime(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min, message=message, sound=sound, webpage=webpage) dbutil.put(key, data) else: key = "schedule:%s" % id data = dbutil.get(key) if data is not None: data.mtime = xutils.format_datetime() data.name = name data.url = url data.tm_wday = tm_wday data.tm_hour = tm_hour data.tm_min = tm_min data.message = message data.sound = sound data.webpage = webpage dbutil.put(key, data) xmanager.load_tasks() raise web.seeother("/system/crontab")
def add_alarm(tm_hour, tm_min, message): url = "/api/alarm" tm_wday = "no-repeat" name = "[提醒] %s" % message id = dbutil.timeseq() key = "schedule:%s" % id data = dict(id=id, name=name, url=url, mtime=xutils.format_datetime(), ctime=xutils.format_datetime(), tm_wday=tm_wday, tm_hour=tm_hour, tm_min=tm_min, message=message) dbutil.put(key, data) xmanager.load_tasks()
def create_note(note_dict): content = note_dict["content"] data = note_dict["data"] creator = note_dict["creator"] priority = note_dict["priority"] mtime = note_dict["mtime"] if xconfig.DB_ENGINE == "sqlite": db = xtables.get_file_table() id = db.insert(**note_dict) update_note_content(id, content, data) return id else: id = dbutil.timeseq() key = "note_full:%s" % id note_dict["id"] = id dbutil.put(key, note_dict) score = "%02d:%s" % (priority, mtime) dbutil.zadd("note_recent:%s" % creator, score, id) update_children_count(note_dict["parent_id"]) return id
def create_note_base(note_dict, date_str): if date_str is None or date_str == "": note_id = dbutil.timeseq() note_dict["id"] = note_id kv_put_note(note_id, note_dict) return note_id else: timestamp = int(dateutil.parse_date_to_timestamp(date_str) * 1000) try: CREATE_LOCK.acquire() while True: note_id = format_note_id(timestamp) note_dict["ctime"] = dateutil.format_datetime(timestamp / 1000) old = get_by_id(note_id) if old is None: note_dict["id"] = note_id kv_put_note(note_id, note_dict) return note_id else: timestamp += 1 finally: CREATE_LOCK.release()
def add_search_history(user, search_key, cost_time=0): key = "msg_search_history:%s:%s" % (user, dbutil.timeseq()) dbutil.put(key, Storage(key=search_key, cost_time=cost_time))
def create_message(**kw): key = "message:%s:%s" % (kw['user'], dbutil.timeseq()) kw['id'] = key dbutil.put(key, kw) return key
def add_search_history(user, search_key, category="default", cost_time=0): key = "search_history:%s:%s" % (user, dbutil.timeseq()) dbutil.put(key, Storage(key=search_key, category=category, cost_time=cost_time))
def save_comment(comment): key = "note_comment:%s:%s" % (comment["note_id"], dbutil.timeseq()) dbutil.put(key, comment)
def add_edit_log(note): creator = note.creator note_id = note.id key = "note_edit_log:%s:%s" % (creator, dbutil.timeseq()) dbutil.put(key, note_id)