コード例 #1
0
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
コード例 #2
0
    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:
            db.insert(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)
        else:
            id = int(id)
            db.update(where=dict(id=id), name=name, url=url, 
                mtime=xutils.format_datetime(),
                tm_wday = tm_wday,
                tm_hour = tm_hour,
                tm_min = tm_min,
                message = message,
                sound = sound,
                webpage = webpage)
        xmanager.load_tasks()
        raise web.seeother("/file/group/memo")
コード例 #3
0
def update_message_status(id, status):
    if xconfig.DB_ENGINE == "sqlite":
        db = xtables.get_message_table()
        msg = db.select_first(where=dict(id=id))
        if msg is None:
            return dict(code="fail", message="data not exists")
        if msg.user != xauth.get_current_name():
            return dict(code="fail", message="no permission")
        db.update(status=status,
                  mtime=xutils.format_datetime(),
                  where=dict(id=id))
        xmanager.fire(
            "message.updated",
            Storage(id=id, status=status, user=msg.user, content=msg.content))
    else:
        user_name = xauth.current_name()
        data = dbutil.get(id)
        if data and data.user == user_name:
            data.status = status
            data.mtime = xutils.format_datetime()
            dbutil.put(id, data)
            xmanager.fire(
                "message.updated",
                Storage(id=id,
                        user=user_name,
                        status=status,
                        content=data.content))

    return dict(code="success")
コード例 #4
0
ファイル: message.py プロジェクト: licshire/xnote
    def POST(self):
        id = xutils.get_argument("id")
        content = xutils.get_argument("content")
        user_name = xauth.get_current_name()
        db = xtables.get_message_table()
        # 对消息进行语义分析处理,后期优化把所有规则统一管理起来
        ctx = Storage(content=content, user=user_name, type="")
        for rule in rules:
            rule.match_execute(ctx, content)
        xmanager.fire('message.update', ctx)

        if id == "" or id is None:
            ctime = xutils.get_argument("date", xutils.format_datetime())
            inserted_id = db.insert(content=content,
                                    user=user_name,
                                    ctime=ctime,
                                    type=ctx.get("type", ""))
            return dict(code="success",
                        data=dict(id=inserted_id, content=content,
                                  ctime=ctime))
        db.update(content=content,
                  mtime=xutils.format_datetime(),
                  type=ctx.get("type", ""),
                  where=dict(id=id, user=user_name))
        return dict(code="success")
コード例 #5
0
ファイル: edit.py プロジェクト: black0592/xnote
    def POST(self):
        name = xutils.get_argument("name", "")
        tags = xutils.get_argument("tags", "")
        key = xutils.get_argument("key", "")
        content = xutils.get_argument("content", "")
        type = xutils.get_argument("type", "post")
        format = xutils.get_argument("_format", "")
        parent_id = xutils.get_argument("parent_id", 0, type=int)

        if key == "":
            key = time.strftime("%Y.%m.%d")

        file = Storage(name=name)
        file.atime = xutils.format_datetime()
        file.mtime = xutils.format_datetime()
        file.ctime = xutils.format_datetime()
        file.creator = xauth.get_current_name()
        file.parent_id = parent_id
        file.type = type
        file.content = ""
        file.size = len(content)
        file.is_public = 0

        code = "fail"
        error = ""
        try:
            db = xtables.get_file_table()
            if name != '':
                f = get_by_name(db, name)
                if f != None:
                    key = name
                    raise Exception(u"%s 已存在" % name)
                file_dict = dict(**file)
                del file_dict["default_value"]
                inserted_id = db.insert(**file_dict)
                update_note_content(inserted_id, content)
                # 更新分组下面页面的数量
                update_children_count(parent_id, db=db)
                xmanager.fire("note.add", dict(name=name, type=type))
                if format == "json":
                    return dict(code="success", id=inserted_id)
                raise web.seeother("/note/view?id={}".format(inserted_id))
        except web.HTTPError as e1:
            raise e1
        except Exception as e:
            xutils.print_exc()
            error = str(e)
        return xtemplate.render("note/add.html",
                                key="",
                                name=key,
                                tags=tags,
                                error=error,
                                pathlist=get_pathlist(db, parent_id),
                                message=error,
                                groups=xutils.call("note.list_group"),
                                code=code)
コード例 #6
0
ファイル: edit.py プロジェクト: licshire/xnote
    def POST(self):
        name = xutils.get_argument("name", "")
        tags = xutils.get_argument("tags", "")
        key = xutils.get_argument("key", "")
        content = xutils.get_argument("content", "")
        type = xutils.get_argument("type", "post")
        format = xutils.get_argument("_format", "")
        parent_id = xutils.get_argument("parent_id", 0, type=int)

        if key == "":
            key = time.strftime("%Y.%m.%d")

        file = FileDO(name)
        file.atime = xutils.format_datetime()
        file.mtime = xutils.format_datetime()
        file.ctime = xutils.format_datetime()
        file.creator = xauth.get_current_name()
        # 默认私有
        file.groups = file.creator
        file.parent_id = parent_id
        file.type = type
        file.content = content
        file.size = len(content)

        code = "fail"
        error = ""
        try:
            db = xtables.get_file_table()
            if name != '':
                f = get_by_name(db, name)
                if f != None:
                    key = name
                    raise Exception(u"%s 已存在" % name)
                # 分组提前
                if file.type == "group":
                    file.priority = 1
                inserted_id = db.insert(**file)
                # 更新分组下面页面的数量
                dao.update_children_count(parent_id, db=db)
                if format == "json":
                    return dict(code="success", id=inserted_id)
                raise web.seeother("/file/view?id={}".format(inserted_id))
        except web.HTTPError as e1:
            raise e1
        except Exception as e:
            xutils.print_exc()
            error = str(e)
        return xtemplate.render("note/add.html",
                                key="",
                                name=key,
                                tags=tags,
                                error=error,
                                message=error,
                                code=code)
コード例 #7
0
ファイル: dao-old.py プロジェクト: dudefu/xnote
def delete_note(id):
    if xconfig.DB_ENGINE == "sqlite":
        db = xtables.get_file_table()
        sql = "UPDATE file SET is_deleted = 1, mtime=$mtime where id = $id"
        db.query(sql, vars=dict(mtime=xutils.format_datetime(), id=id))
    else:
        note = get_by_id(id)
        if note:
            note.mtime = xutils.format_datetime()
            note.is_deleted = 1
            kv_put_note(id, note)
            update_children_count(note.parent_id)
コード例 #8
0
ファイル: dao-old.py プロジェクト: dudefu/xnote
def visit_note(id):
    if xconfig.DB_ENGINE == "sqlite":
        db = xtables.get_file_table()
        sql = "UPDATE file SET visited_cnt = visited_cnt + 1, atime=$atime where id = $id"
        db.query(sql, vars=dict(atime=xutils.format_datetime(), id=id))
    else:
        note = get_by_id(id)
        if note:
            note.atime = xutils.format_datetime()
            if note.visited_cnt is None:
                note.visited_cnt = 0
            note.visited_cnt += 1
            kv_put_note(id, note)
コード例 #9
0
ファイル: message.py プロジェクト: Kevin-CodeHub/xnote
    def POST(self):
        id = xutils.get_argument("id")
        content = xutils.get_argument("content")
        tag = xutils.get_argument("tag", DEFAULT_TAG)
        location = xutils.get_argument("location", "")
        user_name = xauth.get_current_name()

        # 对消息进行语义分析处理,后期优化把所有规则统一管理起来
        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 = MSG_DAO.create(content=content,
                                         user=user_name,
                                         tag=tag,
                                         ip=ip,
                                         mtime=ctime,
                                         ctime=ctime)
            id = inserted_id
            MSG_DAO.refresh_message_stat(user_name)

            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))
コード例 #10
0
    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))
コード例 #11
0
ファイル: login.py プロジェクト: burushi/xnote
def save_login_info(name, value):
    db = xtables.get_record_table()
    message = "%s-%s" % (get_real_ip(), value)
    if name != "":
        db.insert(type="login", key=name, value=message, 
            ctime = xutils.format_datetime(), 
            cdate = xutils.format_date())
コード例 #12
0
 def POST(self):
     content = xutils.get_argument("content", "")
     data = xutils.get_argument("data", "")
     id = xutils.get_argument("id", "0", type=int)
     type = xutils.get_argument("type")
     name = xauth.get_current_name()
     db = xtables.get_file_table()
     where = None
     if xauth.is_admin():
         where = dict(id=id)
     else:
         where = dict(id=id, creator=name)
     kw = dict(size=len(content),
               mtime=xutils.format_datetime(),
               where=where)
     if type == "html":
         kw["data"] = data
         kw["content"] = data
         if xutils.bs4 is not None:
             soup = xutils.bs4.BeautifulSoup(data, "html.parser")
             content = soup.get_text(separator=" ")
             kw["content"] = content
         kw["size"] = len(content)
     else:
         kw["content"] = content
         kw["size"] = len(content)
     rowcount = db.update(**kw)
     if rowcount > 0:
         return dict(code="success")
     else:
         return dict(code="fail")
コード例 #13
0
def update_message_content(id, user_name, content):
    if xconfig.DB_ENGINE == "sqlite":
        db = xtables.get_message_table()
        db.update(content=content,
                  mtime=xutils.format_datetime(),
                  where=dict(id=id, user=user_name))
        xmanager.fire("message.update",
                      dict(id=id, user=user_name, content=content))
    else:
        data = dbutil.get(id)
        if data and data.user == user_name:
            data.content = content
            data.mtime = xutils.format_datetime()
            dbutil.put(id, data)
            xmanager.fire("message.update",
                          dict(id=id, user=user_name, content=content))
コード例 #14
0
    def POST(self):
        name = xutils.get_argument("username", "")
        pswd = xutils.get_argument("password", "")
        target = xutils.get_argument("target")
        users = xauth.get_users()
        error = ""

        if name in users:
            user = users[name]
            if pswd == user["password"]:
                save_login_info(name, "success")
                xauth.write_cookie(name)
                db = xtables.get_user_table()
                db.update(login_time=xutils.format_datetime(),
                          where=dict(name=name))
                if target is None:
                    raise web.seeother("/")
                raise web.seeother(target)
            else:
                error = "user or password error"
                save_login_info(name, pswd)
        else:
            error = "user or password error"
            save_login_info(name, pswd)

        return xtemplate.render("login.html",
                                username=name,
                                password=pswd,
                                error=error)
コード例 #15
0
def delete_note(id):
    print("try to delete note", id)
    note = get_by_id(id)
    if note is None:
        return

    if note.is_deleted == 1:
        # 已经被删除了,执行物理删除
        tiny_key = "note_tiny:%s:%s" % (note.creator, note.id)
        full_key = "note_full:%s" % note.id
        index_key = "note_index:%s" % note.id
        dbutil.delete(tiny_key)
        dbutil.delete(full_key)
        dbutil.delete(index_key)
        return

    note.mtime = xutils.format_datetime()
    note.is_deleted = 1
    kv_put_note(id, note)
    update_children_count(note.parent_id)
    delete_tags(note.creator, id)

    book_key = "notebook:%s:%020d" % (note.creator, int(id))
    dbutil.delete(book_key)

    # 更新数量统计
    refresh_note_stat(note.creator)
コード例 #16
0
ファイル: stats.py プロジェクト: zz-fork-repository/xnote
 def POST(self):
     coords = xutils.get_argument("coords")
     if coords != "null":
         db = xtables.get_record_table()
         db.insert(type="location", key=xauth.get_current_name(), cdate=xutils.format_date(), 
             ctime=xutils.format_datetime(), value=coords)
     return "{}"
コード例 #17
0
    def POST(self):
        content = xutils.get_argument("content", "")
        data    = xutils.get_argument("data", "")
        id      = xutils.get_argument("id")
        type    = xutils.get_argument("type")
        version = xutils.get_argument("version", 0, type=int)
        name    = xauth.get_current_name()
        where   = None

        try:
            file = check_get_note(id)
            kw = dict(size = len(content), 
                mtime = xutils.format_datetime(), 
                version = version + 1)

            if type == "html":
                kw["data"]    = data
                kw["content"] = data
                if xutils.bs4 is not None:
                    soup          = xutils.bs4.BeautifulSoup(data, "html.parser")
                    content       = soup.get_text(separator=" ")
                    kw["content"] = content
                kw["size"] = len(content)
            else:
                kw["content"] = content
                kw['data']    = ''
                kw["size"]    = len(content)

            update_and_notify(file, kw)
            return dict(code = "success")
        except NoteException as e:
            return dict(code = "fail", message = e.message)
コード例 #18
0
    def POST(self):
        name = xutils.get_argument("username", "")
        pswd = xutils.get_argument("password", "")
        target = xutils.get_argument("target")
        users = xauth.get_users()
        error = ""
        count = cacheutil.get("login.fail.count#%s" % name, 0)
        if count >= RETRY_LIMIT:
            error = "重试次数过多"
        elif name in users:
            user = users[name]
            if pswd == user["password"]:
                save_login_info(name, "success")
                xauth.write_cookie(name)
                xauth.update_user(name,
                                  dict(login_time=xutils.format_datetime()))
                if target is None:
                    raise web.seeother("/")
                raise web.seeother(target)
            else:
                error = "用户名或密码错误"
                save_login_info(name, pswd)
                cacheutil.set("login.fail.count#%s" % name, count + 1, 60)
        else:
            error = "用户名或密码错误"
            save_login_info(name, pswd)
            # 用户名异常的不做限制,防止缓存被刷爆
            # cacheutil.set("login.fail.count#%s" % name, count+1, 60)

        return xtemplate.render("login.html",
                                username=name,
                                password=pswd,
                                error=error)
コード例 #19
0
ファイル: dao.py プロジェクト: arong-me/xnote
def delete_note(id):
    note = get_by_id(id)
    if note:
        note.mtime = xutils.format_datetime()
        note.is_deleted = 1
        kv_put_note(id, note)
        update_children_count(note.parent_id)
コード例 #20
0
def delete_note(id):
    note = get_by_id(id)
    if note is None:
        return

    if note.is_deleted != 0:
        # 已经被删除了,执行物理删除
        tiny_key = "note_tiny:%s:%s" % (note.creator, note.id)
        full_key = "note_full:%s" % note.id
        index_key = "note_index:%s" % note.id
        dbutil.delete(tiny_key)
        dbutil.delete(full_key)
        dbutil.delete(index_key)
        delete_history(note.id)
        return

    # 标记删除
    note.mtime = xutils.format_datetime()
    note.is_deleted = 1
    kv_put_note(id, note)

    # 更新数量
    update_children_count(note.parent_id)
    delete_tags(note.creator, id)

    # 删除笔记本
    book_key = "notebook:%s:%s" % (note.creator, format_note_id(id))
    dbutil.delete(book_key)

    # 更新数量统计
    refresh_note_stat(note.creator)
コード例 #21
0
ファイル: dao.py プロジェクト: arong-me/xnote
def visit_note(id):
    note = get_by_id(id)
    if note:
        note.atime = xutils.format_datetime()
        if note.visited_cnt is None:
            note.visited_cnt = 0
        note.visited_cnt += 1
        kv_put_note(id, note)
コード例 #22
0
ファイル: dao.py プロジェクト: Alawnwei/xnote
def visit_note(id):
    note = get_by_id(id)
    if note:
        note.atime = xutils.format_datetime()
        if note.visited_cnt is None:
            note.visited_cnt = 0
        note.visited_cnt += 1
        update_index(note)
コード例 #23
0
    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")
コード例 #24
0
def visit_note(user_name, id):
    note = get_by_id(id)
    if note:
        note.atime = xutils.format_datetime()
        if note.visited_cnt is None:
            note.visited_cnt = 0
        note.visited_cnt += 1
        update_index(note)
        add_visit_log(user_name, note)
コード例 #25
0
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()
コード例 #26
0
    def POST(self):
        key = xutils.get_argument("key")
        value = xutils.get_argument("value")
        user = xauth.get_current_name()
        db = xtables.get_storage_table()
        config = db.select_first(where=dict(key=key, user=user))
        if config is None:
            db.insert(user = user, key = key, value = value, 
                ctime = xutils.format_datetime(), 
                mtime = xutils.format_datetime())
        else:
            db.update(value=value, mtime = xutils.format_datetime(), where=dict(key=key, user=user))

        config = Storage(key = key, value = value)
        return xtemplate.render("system/properties.html", 
            action = "/system/storage",
            show_aside = False,
            config = config)
コード例 #27
0
ファイル: message.py プロジェクト: driphub/xnote
 def POST(self):
     id = xutils.get_argument("id")
     msg = MSG_DAO.get_by_id(id)
     if msg is None:
         return failure(message="message not found, id:%s" % id)
     if msg.user != xauth.current_name():
         return failure(message="not authorized")
     msg.mtime = xutils.format_datetime()
     MSG_DAO.update(msg)
     return success()
コード例 #28
0
ファイル: login.py プロジェクト: gotonking/miniNote
def save_login_info(name, value):
    message = "%s-%s" % (get_real_ip(), value)
    if name != "":
        dbutil.insert(
            "record:login",
            dict(type="login",
                 key=name,
                 value=message,
                 ctime=xutils.format_datetime(),
                 cdate=xutils.format_date()))
コード例 #29
0
ファイル: message.py プロジェクト: Kevin-CodeHub/xnote
def update_message_tag(id, tag):
    user_name = xauth.current_name()
    data = dbutil.get(id)
    if data and data.user == user_name:
        # 修复status数据,全部采用tag
        if 'status' in data:
            del data['status']
        data.tag = tag
        data.mtime = xutils.format_datetime()
        if tag == "done":
            data.done_time = xutils.format_datetime()

        MSG_DAO.update(data)
        MSG_DAO.refresh_message_stat(user_name)
        xmanager.fire(
            "message.updated",
            Storage(id=id, user=user_name, tag=tag, content=data.content))

    return dict(code="success")
コード例 #30
0
ファイル: message.py プロジェクト: zenistzw/xnote
def update_message(id, status):
    db = xtables.get_message_table()
    msg = db.select_first(where=dict(id=id))
    if msg is None:
        return dict(code="fail", message="data not exists")
    if msg.user != xauth.get_current_name():
        return dict(code="fail", message="no permission")
    db.update(status=status, mtime=xutils.format_datetime(), where=dict(id=id))
    xmanager.fire("message.updated", Storage(id=id, status=status, user = msg.user, content=msg.content))
    return dict(code="success")