Пример #1
0
def fire_update_event(note):
    event_body = dict(id=note.id, 
            name = note.name, 
            mtime = dateutil.format_datetime(), 
            content = note.content, 
            version = note.version+1)
    xmanager.fire('note.updated', event_body)
Пример #2
0
def update_visit_log(log, name):
    log.name = name
    log.time = dateutil.format_datetime()
    if log.visit_cnt is None:
        log.visit_cnt = 1
    log.visit_cnt += 1
    dbutil.put(log.key, log)
Пример #3
0
    def POST(self):
        user = xauth.current_name()
        note_id = xutils.get_argument("note_id")
        content = xutils.get_argument("content")
        version = xutils.get_argument("version", 1, type=int)
        note = NOTE_DAO.get_by_id(note_id)

        if note == None:
            return dict(code="404", message="note not found")

        if note.creator != user:
            return dict(code="403", message="unauthorized")

        if note.list_items is None:
            note.list_items = []
        note.list_items.append(content)
        NOTE_DAO.update0(note)
        xmanager.fire(
            'note.updated',
            dict(id=note_id,
                 name=note.name,
                 mtime=dateutil.format_datetime(),
                 content=content,
                 version=version + 1))
        return dict(code="success")
Пример #4
0
def add_visit_log(user_name, url, name=None):
    exist_log = find_visit_log(user_name, url)
    if exist_log != None:
        update_visit_log(exist_log, name)
        return

    log = Storage()
    log.name = name
    log.url = url
    log.time = dateutil.format_datetime()

    dbutil.insert("plugin_visit_log:%s" % user_name, log)
Пример #5
0
    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))
Пример #6
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

        if xauth.is_admin():
            where = dict(id=id)
        else:
            where = dict(id=id, creator=name)
        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)
        rowcount = xutils.call("note.update", where, **kw)
        if rowcount > 0:
            xmanager.fire(
                'note.updated',
                dict(id=id,
                     name=name,
                     mtime=dateutil.format_datetime(),
                     content=content,
                     version=version + 1))
            return dict(code="success")
        else:
            return dict(code="fail", message="更新失败")
Пример #7
0
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()
Пример #8
0
    def GET(self, name=""):
        user_name = xauth.current_name()
        name = xutils.unquote(name)

        if not name.endswith(".py"):
            name += ".py"
        try:
            url = "/plugins/" + name
            plugin = load_plugin(name)
            if plugin != None:
                # 访问日志
                add_visit_log(user_name, url)
                plugin.atime = dateutil.format_datetime()
                # 渲染页面
                return plugin.clazz().render()
            else:
                # 删除日志
                delete_visit_log(user_name, name, url)
                return xtemplate.render("error.html",
                                        error="plugin `%s` not found!" % name)
        except:
            error = xutils.print_exc()
            return xtemplate.render("error.html", error=error)
Пример #9
0
def touch_note(note_id):
    note = get_by_id(note_id)
    if note != None:
        note.mtime = dateutil.format_datetime()
        update_index(note)
Пример #10
0
def touch_note(note_id):
    note = get_by_id(note_id)
    if note != None:
        note.mtime = dateutil.format_datetime()
        kv_put_note(note_id, note)