コード例 #1
0
def create_log_func(note, ctx):
    date_str  = time.strftime("%Y.%m.%d")
    note.name = u"日志:" + date_str + dateutil.current_wday()
    return NOTE_DAO.create(note)
コード例 #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") + 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)
コード例 #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()

        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)