Esempio n. 1
0
    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)
Esempio n. 2
0
    def POST(self, method='POST'):
        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", "md")
        format = xutils.get_argument("_format", "")
        parent_id = xutils.get_argument("parent_id", "0")

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

        creator = xauth.current_name()
        note = Storage(name=name)
        note.atime = xutils.format_datetime()
        note.mtime = xutils.format_datetime()
        note.ctime = xutils.format_datetime()
        note.creator = creator
        note.parent_id = parent_id
        note.type = type
        note.content = content
        note.data = ""
        note.size = len(content)
        note.is_public = 0
        note.priority = 0
        note.version = 0
        note.is_deleted = 0

        code = "fail"
        error = ""
        try:
            if name == '':
                if method == 'POST':
                    message = 'name is empty'
                    raise Exception(message)
            else:
                f = xutils.call("note.get_by_name", name)
                if f != None:
                    key = name
                    message = u"%s 已存在" % name
                    raise Exception(message)
                inserted_id = xutils.call("note.create", note)
                if format == "json":
                    return dict(code="success", id=inserted_id)
                raise web.seeother("/note/view?id={}".format(inserted_id))
        except web.HTTPError as e1:
            xutils.print_exc()
            raise e1
        except Exception as e:
            xutils.print_exc()
            error = str(e)
            if format == 'json':
                return dict(code='fail', message=error)
        return xtemplate.render(
            "note/add.html",
            show_aside=True,
            key="",
            type=type,
            name=key,
            tags=tags,
            error=error,
            pathlist=[Storage(name=T("New_Note"), url="/note/add")],
            message=error,
            groups=xutils.call("note.list_group"),
            code=code)
Esempio n. 3
0
    def POST(self, method='POST'):
        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", "md")
        format    = xutils.get_argument("_format", "")
        parent_id = xutils.get_argument("parent_id", "0")

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

        type = NOTE_TYPE_MAPPING.get(type, type)

        creator        = xauth.current_name()
        note           = Storage(name = name)
        note.atime     = xutils.format_datetime()
        note.mtime     = xutils.format_datetime()
        note.ctime     = xutils.format_datetime()
        note.creator   = creator
        note.parent_id = parent_id
        note.type      = type
        note.content   = content
        note.data      = ""
        note.size      = len(content)
        note.is_public = 0
        note.priority  = 0
        note.version   = 0
        note.is_deleted = 0
        note.tags       = textutil.split_words(tags)

        heading = T("创建笔记")
        code = "fail"
        error = ""
        ctx = Storage(method = method)
        
        try:
            if type not in VALID_NOTE_TYPE_SET:
                raise Exception(u"无效的类型: %s" % type)

            create_func = CREATE_FUNC_DICT.get(type, default_create_func)
            inserted_id = create_func(note, ctx)
            if format == "json":
                return dict(code="success", id = inserted_id, url = "/note/edit?id=%s" % inserted_id)
            if inserted_id != None:
                raise web.seeother("/note/edit?id={}".format(inserted_id))
        except web.HTTPError as e1:
            xutils.print_exc()
            raise e1
        except Exception as e:
            xutils.print_exc()
            error = xutils.u(e)
            if format == 'json':
                return dict(code = 'fail', message = error)

        heading = get_heading_by_type(type)

        return xtemplate.render("note/page/create.html", 
            show_search = False,
            heading  = heading,
            key      = "", 
            type     = type,
            name     = key, 
            tags     = tags, 
            error    = error,
            message  = error,
            NOTE_TYPE_LIST = NOTE_TYPE_LIST,
            groups   = NOTE_DAO.list_group(creator),
            code     = code)
Esempio n. 4
0
    def POST(self, method='POST'):
        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", "md")
        format = xutils.get_argument("_format", "")
        parent_id = xutils.get_argument("parent_id", "0")

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

        creator = xauth.current_name()
        note = Storage(name=name)
        note.atime = xutils.format_datetime()
        note.mtime = xutils.format_datetime()
        note.ctime = xutils.format_datetime()
        note.creator = creator
        note.parent_id = parent_id
        note.type = type
        note.content = content
        note.data = ""
        note.size = len(content)
        note.is_public = 0
        note.priority = 0
        note.version = 0
        note.is_deleted = 0
        note.tags = textutil.split_words(tags)

        heading = T("创建笔记")
        code = "fail"
        error = ""

        try:
            if name == '':
                if method == 'POST':
                    message = 'name is empty'
                    raise Exception(message)
            else:
                f = NOTE_DAO.get_by_name(name)
                if f != None:
                    key = name
                    message = u"%s 已存在" % name
                    raise Exception(message)
                inserted_id = NOTE_DAO.create(note)
                if format == "json":
                    return dict(code="success", id=inserted_id)
                raise web.seeother("/note/{}".format(inserted_id))
        except web.HTTPError as e1:
            xutils.print_exc()
            raise e1
        except Exception as e:
            xutils.print_exc()
            error = str(e)
            if format == 'json':
                return dict(code='fail', message=error)

        heading = get_heading_by_type(type)

        return xtemplate.render("note/add.html",
                                show_search=False,
                                heading=heading,
                                key="",
                                type=type,
                                name=key,
                                tags=tags,
                                error=error,
                                message=error,
                                groups=NOTE_DAO.list_group(creator),
                                code=code)