Пример #1
0
def pre_render(kw):
    """模板引擎预处理过程"""
    user_name = xauth.current_name() or ""

    kw["math"] = math
    kw["_is_admin"] = xauth.is_admin()
    kw["_has_login"] = xauth.has_login()
    kw["_user_name"] = user_name
    kw["_user_agent"] = get_user_agent()
    # 处理首页公告
    kw["_top_notice"] = None
    # 用于渲染其他组件
    kw["_render"] = render
    kw["Storage"] = Storage
    kw["xutils"] = xutils
    kw["xconfig"] = xconfig
    kw["_user_config"] = get_user_config(user_name)
    kw["_notice_count"] = get_message_count(user_name)
    kw["T"] = T
    kw["HOME_PATH"] = xconfig.get_user_config(user_name, "HOME_PATH")
    if hasattr(web.ctx, "env"):
        kw["HOST"] = web.ctx.env.get("HTTP_HOST")

    if len(xconfig.errors) > 0:
        kw["warn"] = "; ".join(xconfig.errors)

    # render input
    _input = web.ctx.get("_xnote.input")
    if _input is not None:
        kw.update(_input)
Пример #2
0
    def GET(self, tagname):
        tagname = xutils.unquote(tagname)
        page = xutils.get_argument("page", 1, type=int)
        limit = xutils.get_argument("limit", xconfig.PAGE_SIZE, type=int)
        offset = (page - 1) * limit

        if xauth.has_login():
            user_name = xauth.get_current_name()
        else:
            user_name = ""

        # count_sql = "SELECT COUNT(1) AS amount FROM file_tag WHERE LOWER(name) = $name AND (user=$user OR is_public=1)"
        # sql = "SELECT f.* FROM file f, file_tag ft ON ft.file_id = f.id WHERE LOWER(ft.name) = $name AND (ft.user=$user OR ft.is_public=1) ORDER BY f.ctime DESC LIMIT $offset, $limit"
        # count = db.query(count_sql, vars=dict(name=tagname.lower(), user=user_name))[0].amount

        # files = db.query(sql,
        #     vars=dict(name=tagname.lower(), offset=offset, limit=limit, user=user_name))
        # files = [dao.FileDO.fromDict(f) for f in files]

        files = xutils.call("note.list_by_tag", user_name, tagname)
        count = len(files)

        files = files[offset:offset + limit]
        return xtemplate.render("note/tagname.html",
                                show_aside=True,
                                tagname=tagname,
                                files=files,
                                show_mdate=True,
                                page_max=math.ceil(count / limit),
                                page=page)
Пример #3
0
def pre_render(kw):
    """模板引擎预处理过程"""
    kw["math"]          = math
    kw["_is_admin"]     = xauth.is_admin()
    kw["_has_login"]    = xauth.has_login()
    user_name           = xauth.get_current_name() or ""
    kw["_user_name"]    = user_name
    kw["_user_agent"]   = get_user_agent()
    # 处理首页公告
    kw["_top_notice"]   = None
    # 用于渲染其他组件
    kw["_render"]       = render
    kw["Storage"]       = Storage
    kw["xutils"]        = xutils
    kw["xconfig"]       = xconfig
    kw["_notice_count"] = get_message_count(user_name)
    if hasattr(web.ctx, "env"):
        kw["HOST"] = web.ctx.env.get("HTTP_HOST")
    if xutils.sqlite3 is None:
        kw["warn"] = "WARN: sqlite3不可用"

    # render input
    _input = web.ctx.get("_xnote.input")
    if _input is not None:
        kw.update(_input)
Пример #4
0
    def GET(self, tagname):
        from . import dao
        tagname = xutils.unquote(tagname)
        db = xtables.get_file_table()
        page = xutils.get_argument("page", 1, type=int)
        limit = xutils.get_argument("limit", 10, type=int)
        offset = (page - 1) * limit
        pagesize = xconfig.PAGE_SIZE

        if xauth.has_login():
            user_name = xauth.get_current_name()
        else:
            user_name = ""
        count_sql = "SELECT COUNT(1) AS amount FROM file_tag WHERE LOWER(name) = $name AND (user=$user OR is_public=1)"
        sql = "SELECT f.* FROM file f, file_tag ft ON ft.file_id = f.id WHERE LOWER(ft.name) = $name AND (ft.user=$user OR ft.is_public=1) ORDER BY f.ctime DESC LIMIT $offset, $limit"
        count = db.query(count_sql,
                         vars=dict(name=tagname.lower(),
                                   user=user_name))[0].amount

        files = db.query(sql,
                         vars=dict(name=tagname.lower(),
                                   offset=offset,
                                   limit=limit,
                                   user=user_name))
        files = [dao.FileDO.fromDict(f) for f in files]
        return xtemplate.render("note/tagname.html",
                                show_aside=True,
                                tagname=tagname,
                                files=files,
                                show_mdate=True,
                                page_max=math.ceil(count / pagesize),
                                page=page)
Пример #5
0
 def GET(self):
     db = xtables.get_file_table()
     if xauth.has_login():
         user_name = xauth.get_current_name()
         tag_list = get_taglist(db, user_name)
     else:
         tag_list = get_taglist(db, "")
     return xtemplate.render("note/taglist.html", tag_list=tag_list)
Пример #6
0
def search_menu(files, name):
    for category in xconfig.MENU_LIST:
        if category.need_login and not xauth.has_login():
            continue
        if category.need_admin and not xauth.is_admin():
            continue
        for child in category.children:
            if text_contains(u(child.name), u(name)):
                files.append(Storage(name='菜单 - ' + child.name, url=child.url))
Пример #7
0
 def GET(self):
     if xauth.has_login():
         user_name = xauth.get_current_name()
         tag_list = xutils.call("note.list_tag", user_name)
     else:
         tag_list = xutils.call("note.list_tag", "")
     return xtemplate.render("note/taglist.html",
                             show_aside=True,
                             tag_list=tag_list)
Пример #8
0
    def GET(self, orderby="edit", show_notice=True):
        if not xauth.has_login():
            raise web.seeother("/note/public")
        if xutils.sqlite3 is None:
            raise web.seeother("/fs_list")
        days = xutils.get_argument("days", 30, type=int)
        page = xutils.get_argument("page", 1, type=int)
        pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int)
        page = max(1, page)
        offset = max(0, (page - 1) * pagesize)
        limit = pagesize
        time_attr = "ctime"

        show_mdate = False
        show_cdate = False
        show_adate = False
        dir_type = "recent_edit"

        creator = xauth.get_current_name()
        if orderby == "viewed":
            html_title = "Recent Viewed"
            files = xutils.call("note.list_recent_viewed", creator, offset,
                                limit)
            time_attr = "atime"
            show_adate = True
            dir_type = "recent_viewed"
        elif orderby == "created":
            html_title = "Recent Created"
            files = xutils.call("note.list_recent_created", creator, offset,
                                limit)
            time_attr = "ctime"
            show_cdate = True
            dir_type = "recent_created"
        else:
            html_title = "Recent Updated"
            files = xutils.call("note.list_recent_edit", creator, offset,
                                limit)
            time_attr = "mtime"
            show_mdate = True
            dir_type = "recent_edit"

        count = NOTE_DAO.count_user_note(creator)

        return xtemplate.render(VIEW_TPL,
                                pathlist=type_node_path(html_title, ""),
                                html_title=html_title,
                                file_type="group",
                                dir_type=dir_type,
                                files=files,
                                show_aside=True,
                                page=page,
                                show_cdate=show_cdate,
                                show_mdate=show_mdate,
                                show_adate=show_adate,
                                page_max=math.ceil(count / xconfig.PAGE_SIZE),
                                page_url="/note/recent_%s?page=" % orderby)
Пример #9
0
def check_webRootOut(path):
    source = os.path.abspath(WIKI_PATH)
    real_path = xutils.get_real_path(path)
    target = os.path.abspath(real_path)
    namepart, ext = os.path.splitext(target)
    #check admin
    if source != target[0:len(source)] or ext.lower() == ".py":
        if not xauth.has_login("admin"):
            raise web.seeother("/unauthorized")
    return False
Пример #10
0
    def GET(self, orderby="edit", show_notice=False):
        if not xauth.has_login():
            raise web.seeother("/note/public")
        if xutils.sqlite3 is None:
            raise web.seeother("/fs_list")
        days = xutils.get_argument("days", 30, type=int)
        page = xutils.get_argument("page", 1, type=int)
        pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int)
        page = max(1, page)
        offset = max(0, (page - 1) * pagesize)
        limit = pagesize
        time_attr = "ctime"

        creator = xauth.get_current_name()
        if orderby == "viewed":
            html_title = "Recent Viewed"
            files = xutils.call("note.list_recent_viewed", creator, offset,
                                limit)
            time_attr = "atime"
        elif orderby == "created":
            html_title = "Recent Created"
            files = xutils.call("note.list_recent_created", None, offset,
                                limit)
            time_attr = "ctime"
        else:
            html_title = "Recent Updated"
            files = xutils.call("note.list_recent_edit", None, offset, limit)
            time_attr = "mtime"

        groups = xutils.call("note.list_group", creator)
        count = xutils.call("note.count_user_note", creator)

        return xtemplate.render("note/recent.html",
                                html_title=html_title,
                                pathlist=[
                                    Storage(name=T(html_title),
                                            type="group",
                                            url="/note/recent_" + orderby)
                                ],
                                file_type="group",
                                files=files,
                                file=Storage(name=T(html_title), type="group"),
                                groups=groups,
                                show_notice=show_notice,
                                show_mdate=True,
                                show_groups=False,
                                show_aside=True,
                                page=page,
                                time_attr=time_attr,
                                page_max=math.ceil(count / xconfig.PAGE_SIZE),
                                page_url="/note/recent_%s?page=" % orderby)
Пример #11
0
    def GET(self, tagname):
        tagname = xutils.unquote(tagname)
        page = xutils.get_argument("page", 1, type=int)
        limit = xutils.get_argument("limit", xconfig.PAGE_SIZE, type=int)
        offset = (page - 1) * limit

        if xauth.has_login():
            user_name = xauth.get_current_name()
        else:
            user_name = ""
        files = xutils.call("note.list_by_tag", user_name, tagname)
        count = len(files)

        files = files[offset:offset + limit]
        return xtemplate.render("note/tagname.html",
                                show_aside=True,
                                tagname=tagname,
                                files=files,
                                show_mdate=True,
                                page_max=math.ceil(count / limit),
                                page=page)
Пример #12
0
def pre_render(kw):
    """ Main hook for template engine """
    kw["math"] = math
    kw["_is_admin"] = xauth.is_admin()
    kw["_has_login"] = xauth.has_login()
    kw["_user"] = xauth.get_current_user()
    kw["_user_agent"] = get_user_agent()
    # 处理首页公告
    kw["_top_notice"] = None
    # print(web.ctx.env)
    # kw["_nav_position"] = web.cookies(nav_position="top").nav_position
    kw["_nav_position"] = "top"
    # 用于渲染其他组件
    kw["_render"] = render
    kw["xutils"] = xutils
    if hasattr(web.ctx, "env"):
        kw["HOST"] = web.ctx.env.get("HTTP_HOST")

    # render input
    _input = web.ctx.get("_xnote.input")
    if _input is not None:
        kw.update(_input)
Пример #13
0
    def GET(self):
        if xauth.has_login():
            raise web.found(xconfig.HOME_PATH)
        else:
            raise web.found("/note/public")

        # 老的逻辑
        current_name = xauth.current_name()
        groups = xutils.call("note.list_group")
        notes = xutils.call("note.list_recent_edit", limit=xconfig.RECENT_SIZE)
        tools = list(filter(tool_filter, list_tools()))[:4]
        # tags        = xutils.call("note.list_tag", current_name)
        tags = []
        recent_search = xutils.call("search.list_recent", current_name,
                                    xconfig.RECENT_SEARCH_LIMIT)
        return xtemplate.render("index.html",
                                file_type="home",
                                show_aside=True,
                                recent_search=recent_search,
                                groups=groups,
                                notes=notes,
                                files=groups,
                                tags=tags,
                                tools=tools)
Пример #14
0
 def GET(self):
     if xauth.has_login():
         user_name = xauth.current_name()
         raise web.found(xuserconfig.get_home_path(user_name))
     else:
         raise web.found("/note/public")
Пример #15
0
    def GET(self, show_notice=True):
        if not xauth.has_login():
            raise web.seeother("/note/public")
        if xutils.sqlite3 is None:
            raise web.seeother("/fs_list")

        page = xutils.get_argument("page", 1, type=int)
        pagesize = xutils.get_argument("pagesize", xconfig.PAGE_SIZE, type=int)
        orderby = xutils.get_argument("orderby", "create")
        page = max(1, page)
        offset = max(0, (page - 1) * pagesize)
        limit = pagesize
        time_attr = "ctime"

        show_mdate = False
        show_cdate = False
        show_adate = False
        show_action_time = False
        show_hot_index = False
        dir_type = "recent_edit"

        creator = xauth.get_current_name()
        if orderby == "all":
            html_title = "All"
            files = NOTE_DAO.list_recent_events(creator, offset, limit)
            show_action_time = True
        elif orderby == "view":
            html_title = "Recent Viewed"
            files = NOTE_DAO.list_recent_viewed(creator, offset, limit)
            show_adate = True
            dir_type = "recent_viewed"
        elif orderby == "create":
            html_title = "Recent Created"
            files = NOTE_DAO.list_recent_created(creator, offset, limit)
            time_attr = "ctime"
            show_cdate = True
            dir_type = "recent_created"
        elif orderby == "hot":
            html_title = "Hot"
            files = NOTE_DAO.list_hot(creator, offset, limit)
            show_hot_index = True
        else:
            html_title = "Recent Updated"
            files = NOTE_DAO.list_recent_edit(creator, offset, limit)
            time_attr = "mtime"
            show_mdate = True
            dir_type = "recent_edit"

        count = NOTE_DAO.count_user_note(creator)

        return xtemplate.render("note/page/recent.html",
                                pathlist=type_node_path(html_title, ""),
                                html_title=html_title,
                                file_type="group",
                                dir_type=dir_type,
                                files=files,
                                show_aside=False,
                                show_size=False,
                                page=page,
                                time_attr=time_attr,
                                show_cdate=show_cdate,
                                show_mdate=show_mdate,
                                show_adate=show_adate,
                                show_next=False,
                                show_action_time=show_action_time,
                                show_hot_index=show_hot_index,
                                page_max=math.ceil(count / xconfig.PAGE_SIZE),
                                page_url="/note/recent_%s?page=" % orderby,
                                **SEARCH_DOC_DICT)
Пример #16
0
def get_user_config(user):
    if not xauth.has_login():
        return Storage()
    return xauth.get_user_config(user)
Пример #17
0
 def GET(self):
     if xauth.has_login():
         user_name = xauth.current_name()
         raise web.found(xconfig.get_user_config(user_name, "HOME_PATH"))
     else:
         raise web.found("/note/public")