Example #1
0
def wp_get_recent_changes_from_cache(config_agent, tpl_render, req_path, limit, offset):
    view_settings = get_view_settings(config_agent)
    static_files = static_file.get_global_static_files(**view_settings)

    buf = cache.get_recent_changes_from_cache(config_agent)
    all_lines = buf.split()
    total_lines = len(all_lines)

    title = "Recent Changes (%d/%d)" % (offset, total_lines / limit)

    start = offset * limit
    end = start + limit
    lines = all_lines[start:end]

    buf = mdutils.sequence_to_unorder_list(lines, **view_settings)
    content = mdutils.md2html(config_agent=config_agent, req_path=req_path, text=buf, **view_settings)

    pg = paginator.Paginator()
    pg.total = total_lines
    pg.current_offset = offset
    pg.limit = limit
    pg.url = "/~recent"

    return tpl_render.canvas(
        config=config_agent.config,
        static_files=static_files,
        button_path=title,
        req_path=req_path,
        title=title,
        content=content,
        paginator=pg,
        **view_settings
    )
Example #2
0
def wp_get_recent_changes_from_cache(config_agent, tpl_render, req_path, limit,
                                     offset):
    view_settings = get_view_settings(config_agent)
    static_files = static_file.get_global_static_files(**view_settings)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(
        req_path, folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(
        config_agent=config_agent,
        local_full_path=local_full_path,
        req_path=req_path)

    buf = cache.get_recent_changes_from_cache(config_agent)
    all_lines = buf.split()
    total_lines = len(all_lines)

    title = "Recent Changes (%d/%d)" % (offset, total_lines / limit)

    start = offset * limit
    end = start + limit
    lines = all_lines[start:end]

    buf = mdutils.sequence_to_unorder_list(
        folder_pages_full_path=folder_pages_full_path,
        seq=lines,
        **view_settings)
    content = mdutils.md2html(config_agent=config_agent,
                              req_path=req_path,
                              text=buf,
                              static_file_prefix=static_file_prefix,
                              **view_settings)

    pg = paginator.Paginator()
    pg.total = total_lines
    pg.current_offset = offset
    pg.limit = limit
    pg.url = "/~recent"

    return tpl_render.canvas(config=config_agent.config,
                             static_files=static_files,
                             button_path=title,
                             req_path=req_path,
                             title=title,
                             content=content,
                             paginator=pg,
                             **view_settings)
Example #3
0
def wp_search(config_agent, tpl_render, req_path):
    view_settings = get_view_settings(config_agent)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(
        req_path, folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(
        config_agent=config_agent,
        local_full_path=local_full_path,
        req_path=req_path)

    keywords = web.input().get("k")
    keywords = web.utils.safestr(keywords)
    title = "Search %s" % keywords

    if keywords:
        limit = config_agent.config.getint("pagination", "search_page_limit")
        lines = search.search_by_filename_and_file_content(keywords,
                                                           limit=limit)
        if lines:
            buf = mdutils.sequence_to_unorder_list(
                folder_pages_full_path=folder_pages_full_path,
                seq=lines,
                **view_settings)
        else:
            buf = None
    else:
        buf = None

    if buf:
        content = mdutils.md2html(config_agent=config_agent,
                                  req_path=req_path,
                                  text=buf,
                                  static_file_prefix=static_file_prefix,
                                  **view_settings)
    else:
        content = "matched not found"

    static_files = static_file.get_global_static_files(**view_settings)

    return tpl_render.search(config_agent=config_agent,
                             static_files=static_files,
                             title=title,
                             keywords=keywords,
                             content=content)
Example #4
0
def wp_search(config_agent, tpl_render, req_path):
    view_settings = get_view_settings(config_agent)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(req_path,
                                                          folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(
        config_agent = config_agent,
        local_full_path = local_full_path,
        req_path = req_path)

    keywords = web.input().get("k")
    keywords = web.utils.safestr(keywords)
    title = "Search %s" % keywords

    if keywords:
        limit = config_agent.config.getint("pagination", "search_page_limit")
        lines = search.search_by_filename_and_file_content(keywords,
                                                          limit = limit)
        if lines:
            buf = mdutils.sequence_to_unorder_list(seq = lines, **view_settings)
        else:
            buf = None
    else:
        buf = None

    if buf:
        content = mdutils.md2html(config_agent = config_agent,
                                  req_path = req_path,
                                  text = buf,
                                  static_file_prefix = static_file_prefix,
                                  **view_settings)
    else:
       content = "matched not found"

    static_files = static_file.get_global_static_files(**view_settings)

    return tpl_render.search(config_agent = config_agent,
                             static_files = static_files,
                             title = title,
                             keywords = keywords,
                             content = content)
Example #5
0
def wp_get_all_pages(config_agent, tpl_render, req_path, limit, offset):
    view_settings = get_view_settings(config_agent)
    view_settings["show_toolbox"] = False

    static_files = static_file.get_global_static_files(**view_settings)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(req_path, folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(config_agent = config_agent,
                                                                                local_full_path = local_full_path,
                                                                                req_path = req_path)

    buf = cache.get_all_pages_list_from_cache(config_agent)
    all_lines = buf.split()
    total_lines = len(all_lines)
    title = "All Pages List (%d/%d)" % (offset, total_lines / limit)

    start = offset * limit
    end = start + limit
    lines = all_lines[start:end]

    buf = mdutils.sequence_to_unorder_list(lines, **view_settings)
    content = mdutils.md2html(config_agent = config_agent,
                              req_path = req_path, text = buf,
                              static_file_prefix = static_file_prefix,
                              **view_settings)

    pg = paginator.Paginator()
    pg.total = total_lines
    pg.current_offset = offset
    pg.limit = limit
    pg.url = "/~all"

    return tpl_render.canvas(config = config_agent.config,
                             static_files = static_files,
                             button_path = title,
                             req_path = "~all",
                             title = title,
                             content = content,
                             paginator = pg,
                             **view_settings)
Example #6
0
def wp_read(config_agent, tpl_render, req_path):
    view_settings = get_view_settings(config_agent)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(req_path, folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(config_agent = config_agent,
                                                                               local_full_path = local_full_path,
                                                                               req_path = req_path)
    path_info = web.ctx.environ["PATH_INFO"]

    HOME_PAGE = ""
    if req_path != HOME_PAGE and view_settings["button_mode_path"]:
        buf = mdutils.text_path_to_button_path("/%s" % req_path)
        button_path = mdutils.md2html(config_agent = config_agent, req_path = req_path, text = buf,
                                      static_file_prefix = static_file_prefix, **view_settings)
    else:
        button_path = None
        view_settings["show_quick_links"] = False

    if os.path.isfile(local_full_path):
        # os.path.exists(local_full_path)
        buf = commons.shutils.cat(local_full_path)
        buf = commons.strutils.strip_bom(buf)

    elif os.path.isdir(local_full_path):
        # os.path.exists(local_full_path)
        if req_path == HOME_PAGE:
            a = os.path.join(local_full_path, "index.md")
            b = os.path.join(local_full_path, "index.markdown")
            if os.path.exists(a) or os.path.exists(b):
                fixed_req_path = os.path.join(path_info, "index")
                return web.seeother(fixed_req_path)
            else:
                fixed_req_path = os.path.join(path_info, "~all")
                return web.seeother(fixed_req_path)
        else:
            # listdir /path/to/folder/*
            buf = shell.get_page_file_list_by_req_path(folder_pages_full_path = folder_pages_full_path, req_path = req_path)
            if buf:
                buf = mdutils.sequence_to_unorder_list(buf.split("\n"), **view_settings)
            else:
                buf = "folder `%s` exists, but there is no files" % path_info
    else:
        # not os.path.exists(local_full_path)
        if path_info.endswith("/"):
            fixed_req_path = path_info + "index?action=update"
        else:
            fixed_req_path = path_info + "?action=update"
        return web.seeother(fixed_req_path)

    title = mdutils.get_title_from_md(local_full_path = local_full_path)
    content = mdutils.md2html(config_agent = config_agent,
                              req_path = req_path,
                              text = buf,
                              static_file_prefix = static_file_prefix,
                              **view_settings)

    static_files = get_the_same_folders_cssjs_files(req_path = req_path, local_full_path = local_full_path,
                                                    folder_pages_full_path = folder_pages_full_path)
    if not static_files:
        static_files = static_file.get_global_static_files(**view_settings) + "\n"

    buf = tpl_render.canvas(config = config_agent.config,
                            static_files = static_files,
                            button_path = button_path,
                            req_path = req_path,
                            title = title,
                            content = content,
                            **view_settings)

    return buf
Example #7
0
def wp_read(config_agent, tpl_render, req_path):
    view_settings = get_view_settings(config_agent)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(req_path, folder_pages_full_path)

    HOME_PAGE = ""
    if req_path != HOME_PAGE and view_settings["button_mode_path"]:
        buf = mdutils.text_path_to_button_path("/%s" % req_path)
        button_path = mdutils.md2html(config_agent=config_agent, req_path=req_path, text=buf)
    else:
        button_path = None
        view_settings["show_quick_links"] = False

    if os.path.isfile(local_full_path):
        content = commons.shutils.cat(local_full_path)
        content = commons.strutils.strip_bom(content)

    elif os.path.isdir(local_full_path):
        # try /path/to/folder/index
        content = get_dot_idx_content_by_full_path(local_full_path) or ""
        if not content:
            # try /path/to/folder/*
            content = get_page_file_list_by_req_path(folder_pages_full_path=folder_pages_full_path, req_path=req_path)
            if content:
                content = mdutils.sequence_to_unorder_list(content.split("\n"), **view_settings)
    else:
        # /index does not exists
        if req_path == HOME_PAGE:
            return web.seeother("~all")
        else:
            return web.seeother("/%s?action=edit" % req_path)

    title = mdutils.get_title_from_md(full_path=local_full_path)
    content = mdutils.md2html(config_agent=config_agent, req_path=req_path, text=content)

    static_files = get_the_same_folders_cssjs_files(
        req_path=req_path, local_full_path=local_full_path, folder_pages_full_path=folder_pages_full_path
    )
    if not static_files:
        static_files = static_file.get_global_static_files(**view_settings) + "\n"

    buf = tpl_render.canvas(
        config=config_agent.config,
        static_files=static_files,
        button_path=button_path,
        req_path=req_path,
        title=title,
        content=content,
        **view_settings
    )
    #    try:
    #        buf = tpl_render.canvas(config = config_agent.config,
    #                                static_files = static_files, button_path = button_path, content = content,
    #                                **view_settings)
    #    except TypeError, ex:
    #        logging.error(str(ex))
    #        buf = "Rendering template for '%s' failed. \n" % req_path +\
    #                "try following command override old templtes files and fix it: \n\n" +\
    #                "    zwadmin.py upgrade <full path of instance>" + "\n"
    #        logging.error(buf)

    return buf
Example #8
0
def wp_read(config_agent, tpl_render, req_path):
    view_settings = get_view_settings(config_agent)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(
        req_path, folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(
        config_agent=config_agent,
        local_full_path=local_full_path,
        req_path=req_path)
    path_info = web.ctx.environ["PATH_INFO"]

    HOME_PAGE = ""
    if req_path != HOME_PAGE and view_settings["button_mode_path"]:
        buf = mdutils.text_path_to_button_path("/%s" % req_path)
        button_path = mdutils.md2html(config_agent=config_agent,
                                      req_path=req_path,
                                      text=buf,
                                      static_file_prefix=static_file_prefix,
                                      **view_settings)
    else:
        button_path = None
        view_settings["show_quick_links"] = False

    title = ""
    if os.path.isfile(local_full_path):
        # os.path.exists(local_full_path)
        buf = commons.shutils.cat(local_full_path)
        buf = commons.strutils.strip_bom(buf)

        title = mdutils.get_title_by_file_path_in_md(
            folder_pages_full_path=folder_pages_full_path,
            file_path_suffix=local_full_path)

    elif os.path.isdir(local_full_path):
        # os.path.exists(local_full_path)
        if req_path == HOME_PAGE:
            a = os.path.join(local_full_path, "index.md")
            b = os.path.join(local_full_path, "index.markdown")
            if os.path.exists(a) or os.path.exists(b):
                fixed_req_path = os.path.join(path_info, "index")
                return web.seeother(fixed_req_path)
            else:
                fixed_req_path = os.path.join(path_info, "~all")
                return web.seeother(fixed_req_path)
        else:
            # listdir /path/to/folder/*
            buf = shell.get_page_file_list_by_req_path(
                folder_pages_full_path=folder_pages_full_path,
                req_path=req_path)
            if buf:
                buf = mdutils.sequence_to_unorder_list(
                    folder_pages_full_path=folder_pages_full_path,
                    seq=buf.split("\n"),
                    **view_settings)
                title = req_path
            else:
                buf = "folder `%s` exists, but there is no files" % path_info
    else:
        # not os.path.exists(local_full_path)
        readonly = config_agent.config.get("main", "readonly")
        if readonly:
            raise web.Forbidden()
        else:
            if path_info.endswith("/"):
                fixed_req_path = path_info + "index?action=update"
            else:
                fixed_req_path = path_info + "?action=update"
            return web.seeother(fixed_req_path)

    content = mdutils.md2html(config_agent=config_agent,
                              req_path=req_path,
                              text=buf,
                              static_file_prefix=static_file_prefix,
                              **view_settings)

    static_files = get_the_same_folders_cssjs_files(
        req_path=req_path,
        local_full_path=local_full_path,
        folder_pages_full_path=folder_pages_full_path)
    if not static_files:
        static_files = static_file.get_global_static_files(
            **view_settings) + "\n"

    buf = tpl_render.canvas(config=config_agent.config,
                            static_files=static_files,
                            button_path=button_path,
                            req_path=req_path,
                            title=title,
                            content=content,
                            **view_settings)

    return buf
Example #9
0
    def POST(self, req_path):
        inputs = web.input()
            
        if req_path == "~search":
            view_settings = page.get_view_settings(config_agent)

            keywords = inputs.get("k")
            keywords = web.utils.safestr(keywords)
            title = "Search %s" % keywords

            if keywords:
                limit = config_agent.config.getint("pagination", "search_page_limit")
                lines = search.search_by_filename_and_file_content(keywords, limit = limit)
                buf = mdutils.sequence_to_unorder_list(seq = lines, **view_settings)
            else:
                buf = None

            if buf:
                content = mdutils.md2html(config_agent = config_agent, req_path = req_path, text = buf, **view_settings)
            else:
                content = "matched not found"

            static_files = static_file.get_global_static_files(**view_settings)

            return tpl_render.search(static_files = static_files, title = title, keywords = keywords, content = content)

        elif req_path == "~settings":
            show_full_path = inputs.get("show_full_path")
            auto_toc = inputs.get("auto_toc")
            highlight_code = inputs.get("highlight_code")

            if show_full_path == "on":
                show_full_path = 1
            else:
                show_full_path = 0
            web.setcookie(name = "zw_show_full_path", value = show_full_path, expires = 31536000)

            if auto_toc == "on":
                auto_toc = 1
            else:
                auto_toc = 0
            web.setcookie(name = "zw_auto_toc", value = auto_toc, expires = 31536000)

            if highlight_code == "on":
                highlight_code = 1
            else:
                highlight_code = 0
            web.setcookie(name = "zw_highlight", value = highlight_code, expires = 31536000)


            latest_req_path = web.cookies().get("zw_latest_req_path")

            if latest_req_path and (latest_req_path not in consts.g_redirect_paths) and latest_req_path != "/":
                web.setcookie(name = "zw_latest_req_path", value = "", expires = -1)
                latest_req_path = "/" + latest_req_path
            else:
                latest_req_path = "/"

            web.seeother(latest_req_path)
            return

        elif req_path == "~new":
            real_req_path = inputs.get("path")
            fixed_req_path = web.lstrips(real_req_path, "/")

            content = inputs.get("content")
            content = web.utils.safestr(content)
        
            page.update_page_by_req_path(req_path = fixed_req_path, content = content)

            cache.update_recent_change_cache(config_agent)
            cache.update_all_pages_list_cache(config_agent)

            web.seeother(real_req_path)
            return

        else:
            raise web.NotFound()