Example #1
0
File: main.py Project: rui/ZWiki
    def POST(self, req_path):
        f = special_path_mapping.get(req_path)
        inputs = web.input()

        if f:
            keywords = inputs.get("k")
            limit = inputs.get("limit")

            keywords = web.utils.safestr(keywords)
            search = f

            if limit:
                limit = int(limit) or conf.search_page_limit
                content = search(keywords, limit)
            else:
                content = search(keywords, conf.search_page_limit)
                
            if content:
                content = zmarkdown_utils.markdown(content)
            else:
                content = "not found matched"

            return t_render.search(keywords=keywords, content=content,
                                   static_files=DEFAULT_GLOBAL_STATIC_FILES)
        else:
            raise web.NotFound()
Example #2
0
File: main.py Project: rui/ZWiki
    def GET(self, req_path):
        f = special_path_mapping.get(req_path)

        if f:
            if req_path == "index":
                index = f
                content = index()
                content = zmarkdown_utils.markdown(content)

                static_files = DEFAULT_GLOBAL_STATIC_FILES
                static_files = "%s\n    %s" % (static_files, get_the_same_folders_cssjs_files(req_path))

                req_path = "~index"
                title = "index"
                return t_render.canvas(req_path=req_path, title=title, content=content, toolbox=False,
                                       static_files=static_files)

        raise web.NotFound()
Example #3
0
File: main.py Project: rui/ZWiki
    def GET(self):
        inputs = web.input()
        limit = inputs.get("limit")

        title = "Recnet Changes"
        static_file_prefix = "/static/pages"
        req_path = "/"        

        if limit:
            limit = int(limit) or conf.index_page_limit
            content = get_recent_change_list(limit)
        else:
            content = get_recent_change_list(conf.index_page_limit)

        fullpath = get_page_file_or_dir_fullpath_by_req_path(req_path)
        content = zmarkdown_utils.markdown(text=content,
                                           work_fullpath=fullpath,
                                           static_file_prefix=static_file_prefix)

        static_files = DEFAULT_GLOBAL_STATIC_FILES
        # static_files = "%s\n    %s" % (static_files, get_the_same_folders_cssjs_files(req_path))

        return t_render.canvas(req_path=req_path, title=title, content=content, toolbox=False,
                               static_files = static_files)
Example #4
0
File: main.py Project: rui/ZWiki
    def GET(self, req_path):
        req_path = cgi.escape(req_path)
        inputs = web.input()
        action = inputs.get("action", "read")

        if action and action not in ("edit", "read", "rename", "delete"):
            raise web.BadRequest()

        fullpath = get_page_file_or_dir_fullpath_by_req_path(req_path)

        if conf.use_button_mode_path:
            buf = zmarkdown_utils.convert_text_path_to_button_path("/%s" % req_path)
            title = zmarkdown_utils.markdown(buf)
        else:
            title = req_path

        if osp.isfile(fullpath):
            work_fullpath = osp.dirname(fullpath)
            static_file_prefix = osp.join("/static/pages", osp.dirname(req_path))
        elif osp.isdir(fullpath):
            work_fullpath = fullpath
            static_file_prefix = osp.join("/static/pages", req_path)            

        if action == "read":
            if osp.isfile(fullpath):
                content = zsh_util.cat(fullpath)
            elif osp.isdir(fullpath):
                dot_idx_content = get_dot_idx_content_by_fullpath(fullpath)
                page_file_list_content = get_page_file_list_content_by_fullpath(fullpath)
                content = ""

                if dot_idx_content:
                    content = dot_idx_content
                if page_file_list_content:
                    content = "%s\n\n----\n%s" % (content, page_file_list_content)
            else:
                web.seeother("/%s?action=edit" % req_path)
                return
            
            content = zmarkdown_utils.markdown(text=content,
                                               work_fullpath=work_fullpath,
                                               static_file_prefix=static_file_prefix)

            static_files = DEFAULT_GLOBAL_STATIC_FILES
            static_files = "%s\n    %s" % (static_files, get_the_same_folders_cssjs_files(req_path))

            return t_render.canvas(req_path=req_path, title=title, content=content, static_files=static_files)
        elif action == "edit":
            if osp.isfile(fullpath):
                content = zsh_util.cat(fullpath)
            elif osp.isdir(fullpath):
                content = get_dot_idx_content_by_fullpath(fullpath)
            elif not osp.exists(fullpath):
                content = ""
            else:
                raise Exception("unknow path")

            static_files = DEFAULT_GLOBAL_STATIC_FILES
            filepath = osp.join("/static", "css", "pagedown.css")
            static_files = _append_static_file(static_files, filepath, file_type="css", add_newline=True)                        
            filepath = osp.join("/static", "js", "editor.js")
            static_files = _append_static_file(static_files, filepath, file_type="js", add_newline=True)

            return t_render.editor(title, content, static_files=static_files)
        elif action == "rename":
            if not osp.exists(fullpath):
                raise web.NotFound()

            return t_render.rename(req_path, static_files=DEFAULT_GLOBAL_STATIC_FILES)
        elif action == "delete":
            delete_page_file_by_fullpath(fullpath)

            web.seeother("/")
            return

        raise web.BadRequest()