Beispiel #1
0
    def GET(self, path):
        # 文件路径默认都进行urlencode
        # 如果存储结构不采用urlencode,那么这里也必须unquote回去
        if not xconfig.USE_URLENCODE:
            path = xutils.unquote(path)

        if not os.path.exists(path):
            # /fs/ 文件名来源是文件系统提供的,尝试unquote不会出现问题
            path = xutils.unquote(path)
        return self.handle_get(path)
Beispiel #2
0
def list_search_func(context):
    # 主要是搜索
    offset     = context['offset']
    limit      = context['limit']
    search_key = context['search_key']
    type       = context['type']
    user_name  = context['user_name']
    parent_id  = xutils.get_argument("parent_id", "")
    words      = None
    rows       = []

    if parent_id == "":
        parent_id = None

    start_time = time.time()
    if search_key != None and search_key != "":
        # TODO 公共笔记的搜索
        search_key = xutils.unquote(search_key)
        words      = split_words(search_key)
        rows       = NOTE_DAO.search_name(words, user_name, parent_id = parent_id)
        rows       = rows[offset: offset + limit]
        cost_time  = time.time() - start_time
        NOTE_DAO.add_search_history(user_name, search_key, "note", cost_time)

    return build_date_result(rows, 'ctime', sticky_title = True, group_title = True)
Beispiel #3
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)
Beispiel #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)
Beispiel #5
0
 def GET(self, name=""):
     display_name = xutils.unquote(name)
     name = xutils.get_real_path(display_name)
     if not name.endswith(".py"):
         name += ".py"
     script_name = "plugins/" + name
     if not os.path.exists(os.path.join(xconfig.PLUGINS_DIR, name)):
         error = "file `%s` not found" % script_name
         return xtemplate.render("error.html", error=error)
     try:
         try:
             cacheutil.zadd("plugins.history", time.time(),
                            os.path.splitext(display_name)[0])
         except TypeError:
             cacheutil.delete("plugins.history")
             cacheutil.zadd("plugins.history", time.time(),
                            os.path.splitext(display_name)[0])
         vars = dict()
         vars["script_name"] = script_name
         xutils.load_script(script_name, vars)
         main_class = vars.get("Main")
         if main_class != None:
             return main_class().render()
         else:
             return xtemplate.render("error.html",
                                     error="class `Main` not found!")
     except:
         error = xutils.print_exc()
         return xtemplate.render("error.html", error=error)
Beispiel #6
0
def on_search_plugins(ctx):
    if not xauth.is_admin():
        return
    if not ctx.search_tool:
        return
    if ctx.search_dict:
        return
    name = ctx.key
    results = []
    dirname = xconfig.PLUGINS_DIR
    words = textutil.split_words(name)
    for fname in xutils.listdir(dirname):
        unquote_name = xutils.unquote(fname)
        unquote_name, ext = os.path.splitext(unquote_name)
        plugin_context = xconfig.PLUGINS.get(fname)
        if textutil.contains_all(unquote_name, words) \
                or (plugin_context != None and textutil.contains_all(plugin_context.title, words)):
            result = SearchResult()
            result.category = "plugin"
            result.name = u("[插件] " + unquote_name)
            if plugin_context != None:
                # result.raw = u(plugin_context.title)
                # result.name = u("插件 %s (%s)") % (u(plugin_context.title), unquote_name)
                if plugin_context.title != None:
                    result.name = u("[插件] " + plugin_context.title + "(" +
                                    unquote_name + ")")
            result.url = u("/plugins/" + unquote_name)
            result.edit_link = u("/code/edit?path=" +
                                 os.path.join(dirname, fname))
            results.append(result)
    ctx.tools += results
Beispiel #7
0
    def GET(self, tagname):
        tagname = xutils.unquote(tagname)
        db = dao.get_file_db()
        page = xutils.get_argument("page", 1, type=int)
        limit = xutils.get_argument("limit", 10, type=int)
        offset = (page - 1) * limit

        # role = xauth.get_current_role()
        role = "admin"

        if role == "admin":
            count_sql = "SELECT COUNT(1) AS amount FROM file_tag WHERE UPPER(name) = $name"
            sql = "SELECT f.* FROM file f, file_tag ft ON ft.file_id = f.id WHERE UPPER(ft.name) = $name ORDER BY f.sctime DESC LIMIT $offset, $limit"
        else:
            count_sql = "SELECT COUNT(1) AS amount FROM file_tag WHERE UPPER(name) = $name AND groups IN $groups"
            sql = "SELECT f.* FROM file f, file_tag ft ON ft.file_id = f.id WHERE UPPER(ft.name) = $name AND f.groups IN $groups ORDER BY f.sctime DESC LIMIT $offset, $limit"
        groups = ["*", role]
        # tag_list = db.select("file_tag", where="UPPER(name) = $name", vars=dict(name=tagname.upper()))
        count = db.query(count_sql,
                         vars=dict(name=tagname.upper(),
                                   groups=groups))[0].amount

        files = db.query(sql,
                         vars=dict(name=tagname.upper(),
                                   offset=offset,
                                   limit=limit,
                                   groups=groups))
        files = [dao.FileDO.fromDict(f) for f in files]
        return xtemplate.render("file/tagname.html",
                                tagname=tagname,
                                files=files,
                                count=count,
                                page=page)
Beispiel #8
0
    def handle_file_stat(self, merge):
        path = self.path
        try:
            st = os.stat(path)
            self.cdate = xutils.format_date(st.st_ctime)
        except:
            st = Storage()

        self.name = xutils.unquote(self.name)
        if os.path.isfile(path):
            self.type = "file"
            self.name = decode_name(self.name)
            _, self.ext = os.path.splitext(self.name)
            self.size = format_size(st.st_size)
        else:
            children = try_listdir(path)
            self.type = "dir"
            self.path = fixed_dir_path(self.path)

            if children != None:
                self.size = len(children)
            else:
                self.size = "ERR"

            if merge and self.size == 1:
                new_path = os.path.join(path, children[0])
                if not os.path.isdir(new_path):
                    return
                if parent is None:
                    parent = os.path.dirname(path)
                self.__init__(new_path, parent)
Beispiel #9
0
def build_plugin_links(dirname, fnames):
    links = []
    for fname in fnames:
        fpath = os.path.join(dirname, fname)
        if not os.path.exists(fpath):
            continue
        name, ext = os.path.splitext(fname)
        name = xutils.unquote(name)
        item = link(name, "/plugins/" + name)
        item.editable = True
        # st = os.stat(fpath)
        # item.atime = xutils.format_date(st.st_atime)
        atime = cacheutil.zscore("plugins.history", fname)
        if atime:
            item.atime = xutils.format_date(atime)
        else:
            item.atime = ""

        item.edit_link = "/code/edit?path=" + fpath
        plugin_context = xconfig.PLUGINS.get(fname)
        item.title = ''
        if plugin_context is not None:
            item.title = plugin_context.title
            item.category = plugin_context.category
        else:
            item.title = name
        links.append(item)
    return links
Beispiel #10
0
def on_search_plugins(ctx):
    if not xauth.is_admin():
        return
    if not ctx.search_tool:
        return
    if ctx.search_dict:
        return
    name = ctx.key
    results = []
    words = textutil.split_words(name)
    for name in xconfig.PLUGINS_DICT:
        plugin = xconfig.PLUGINS_DICT[name]
        unquote_name = xutils.unquote(plugin.fname)
        unquote_name, ext = os.path.splitext(unquote_name)
        plugin_context = plugin
        if textutil.contains_all(unquote_name, words) \
                or (textutil.contains_all(plugin_context.title, words)):
            result = SearchResult()
            result.category = "plugin"
            result.icon = "fa-cube"
            result.name = u(unquote_name)
            if plugin_context != None:
                # result.raw = u(plugin_context.title)
                # result.name = u("插件 %s (%s)") % (u(plugin_context.title), unquote_name)
                if plugin_context.title != None:
                    result.name = u(plugin_context.title + "(" + unquote_name +
                                    ")")
            result.url = u(plugin.url)
            result.edit_link = u("/code/edit?path=" + plugin.fpath)
            results.append(result)
    ctx.tools += results
Beispiel #11
0
    def __init__(self, path, parent=None):
        self.path = path
        self.name = os.path.basename(path)
        self.size = '-'
        self.cdate = '-'
        _, self.ext = os.path.splitext(path)
        self.ext = self.ext.lower()

        if parent != None:
            self.name = get_relative_path(path, parent)

        # 处理Windows盘符
        if path.endswith(":"):
            self.name = path

        self.name = xutils.unquote(self.name)
        if os.path.isfile(path):
            self.type = "file"
            self.name = decode_name(self.name)
            _, self.ext = os.path.splitext(self.name)
        else:
            self.type = "dir"
            self.path += "/"

        try:
            st = os.stat(path)
            self.size = format_size(st.st_size)
            self.cdate = xutils.format_date(st.st_ctime)
        except:
            pass
Beispiel #12
0
def log_plugin_visit(name):
    try:
        fname = xutils.unquote(name)
        cacheutil.zadd("plugins.history", time.time(), fname)
    except TypeError:
        cacheutil.delete("plugins.history")
        cacheutil.zadd("plugins.history", time.time(), fname)
Beispiel #13
0
    def GET(self, path_key=None):
        """search files by name and content"""
        load_rules()
        key = xutils.get_argument("key", "")
        title = xutils.get_argument("title", "")
        category = xutils.get_argument("category", "default")
        page = xutils.get_argument("page", 1, type=int)
        user_name = xauth.get_current_name()
        page_url  =  "/search/search?key=%s&category=%s&page="\
            % (key, category)
        pagesize = xconfig.SEARCH_PAGE_SIZE
        offset = (page - 1) * pagesize
        limit = pagesize

        if path_key:
            key = xutils.unquote(path_key)

        if key == "" or key == None:
            raise web.found("/search/history")
        key = key.strip()
        ctx = Storage()
        files = self.do_search(ctx, key, offset, pagesize)
        count = len(files)
        files = files[offset:offset + limit]
        fill_note_info(files)
        return xtemplate.render("search/page/search_result.html",
                                show_aside=False,
                                key=key,
                                html_title="Search",
                                category=category,
                                files=files,
                                title=title,
                                page_max=int(math.ceil(count / pagesize)),
                                page_url=page_url,
                                **ctx)
Beispiel #14
0
    def GET(self, path=""):
        if path == "":
            path = xutils.get_argument("path")
        else:
            path = xutils.unquote(path)

        basename = os.path.basename(path)
        op = xutils.get_argument("op")
        path = xutils.get_real_path(path)
        kw = Storage()

        if os.path.isfile(path):
            check_resource(path)
            type = "file"
            content = xutils.readfile(path)
            _, ext = os.path.splitext(path)
            if ext == ".csv" and not content.startswith("```csv"):
                content = "```csv\n" + content + "\n```"
            children = None
        else:
            # file not exists or not readable
            children = None
            content = "File \"%s\" does not exists" % path
            type = "file"

        handle_layout(kw)
        return render("code/preview.html",
                      html_title=basename,
                      os=os,
                      path=path,
                      content=content,
                      type=type,
                      has_readme=False,
                      **kw)
Beispiel #15
0
    def GET(self, tagname):
        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
        role = "admin"

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

        files = db.query(sql,
                         vars=dict(name=tagname.lower(),
                                   offset=offset,
                                   limit=limit,
                                   groups=groups))
        files = [dao.FileDO.fromDict(f) for f in files]
        return xtemplate.render("note/tagname.html",
                                tagname=tagname,
                                files=files,
                                page_max=math.ceil(count / pagesize),
                                page=page)
Beispiel #16
0
    def GET(self):
        task_list = xmanager.get_task_list()
        for task in task_list:
            if task.url is None: task.url = ""
            task.url = xutils.unquote(task.url)
            parts = task.url.split("://")
            task.protocol = "unknown"
            if len(parts) == 2:
                protocol = parts[0]
                name = parts[1]
                task.protocol = protocol
                if protocol == "script":
                    task.script_name = name

        def set_display_name(file):
            file.display_name = file.name if file.name != "" else file.url
            if file.protocol == "script":
                file.display_name = file.url
            return file

        task_list = list(map(set_display_name, task_list))
        return xtemplate.render("system/crontab.html",
                                show_aside=False,
                                task_list=task_list,
                                display_time_rule=display_time_rule)
Beispiel #17
0
 def GET(self, name=""):
     name = xutils.unquote(name)
     table = xtables.get_dict_table()
     item = table.select_first(where=dict(key=name))
     value = ""
     if item != None:
         value = item.value
     return xtemplate.render("dict/dict_edit.html", name=name, value=value)
Beispiel #18
0
    def GET(self):
        offset = xutils.get_argument("offset", 0, type=int)
        limit = xutils.get_argument("limit", 20, type=int)
        type = xutils.get_argument("type", "root")
        parent_id = xutils.get_argument("parent_id", None, type=str)
        search_key = xutils.get_argument("key", None, type=str)
        user_name = xauth.current_name()

        if type == "public":
            rows = NOTE_DAO.list_public(offset, limit)
        elif type == "sticky":
            rows = NOTE_DAO.list_sticky(user_name, offset, limit)
        elif type == "removed":
            rows = NOTE_DAO.list_removed(user_name, offset, limit)
        elif type in ("md", "group", "gallery", "document", "list", "table",
                      "csv"):
            rows = NOTE_DAO.list_by_type(user_name, type, offset, limit)
        elif type == "archived":
            rows = NOTE_DAO.list_archived(user_name, offset, limit)
        elif type == "all":
            rows = NOTE_DAO.list_recent_created(user_name, offset, limit)
        elif type == "root":
            rows = NOTE_DAO.list_group(user_name)
            rows.insert(0, TaskGroup())
            orderby = "mtime"
        else:
            # 主要是搜索
            words = None
            if search_key != None and search_key != "":
                # TODO 公共笔记的搜索
                search_key = xutils.unquote(search_key)
                search_key_lower = search_key.lower()
                parent_id = None
                words = textutil.split_words(search_key_lower)
                # groups = search_group(user_name, words)

            def list_func(key, value):
                if value.is_deleted:
                    return False
                if value.name is None:
                    return False
                if parent_id != None and str(
                        value.parent_id) != str(parent_id):
                    return False
                if words != None and not textutil.contains_all(
                        value.name.lower(), words):
                    return False
                return True

            # TODO 搜索公开内容
            rows = NOTE_DAO.list_by_func(user_name, list_func, offset, limit)

        orderby = "ctime"
        if type in ("mtime", "group", "root"):
            orderby = "mtime"

        return build_date_result(rows, type, orderby)
Beispiel #19
0
 def GET(self, path=""):
     path = xutils.unquote(path)
     template_name = "code/preview.html"
     if not path.endswith(".md"):
         return render(template_name, error="file extension error")
     content = xutils.readfile(path)
     return render(template_name,
                   content=content,
                   os=os,
                   type="file",
                   path=path)
Beispiel #20
0
 def GET(self, name):
     name = xutils.unquote(name)
     if not name.endswith(".html"):
         name += ".html"
     # Chrome下面 tools/timeline不能正常渲染
     web.header("Content-Type", "text/html")
     fpath = os.path.join(xconfig.HANDLERS_DIR, "tools", name)
     if os.path.exists(fpath):
         return xtemplate.render("tools/" + name)
     else:
         raise web.notfound()
Beispiel #21
0
 def POST(self, name=""):
     key = xutils.get_argument("name", "")
     value = xutils.get_argument("value", "")
     if key != "" and value != "":
         key = xutils.unquote(key)
         table = xtables.get_dict_table()
         item = table.select_first(where=dict(key=key))
         if item != None:
             table.update(value=value, where=dict(key=key))
         else:
             table.insert(key=key, value=value)
     return self.GET(name)
Beispiel #22
0
 def GET(self, msg=None):
     repeat = xutils.get_argument("repeat", 3, type=int)
     content = xutils.get_argument("content")
     repeat = min(10, repeat)
     if msg is None:
         msg = content
     if xconfig.is_mute():
         return dict(code="fail", message="mute")
     msg = xutils.unquote(msg)
     for i in range(repeat):
         xutils.say(msg)
         time.sleep(2)
     return dict(code="success")
Beispiel #23
0
def search_plugins(name):
    results = []
    dirname = xconfig.PLUGINS_DIR
    words = textutil.split_words(name)
    for fname in xutils.listdir(dirname):
        unquote_name = xutils.unquote(fname)
        if textutil.contains_all(unquote_name, words):
            result = SearchResult()
            result.category = "plugin"
            result.name = u("插件 - " + unquote_name)
            result.url = u("/plugins/" + fname)
            result.edit_link = u("/code/edit?path=" +
                                 os.path.join(dirname, fname))
            results.append(result)
    return results
Beispiel #24
0
 def GET(self, name=""):
     display_name = xutils.unquote(name)
     name = xutils.get_real_path(display_name)
     if not name.endswith(".py"):
         name += ".py"
     try:
         main_class = load_plugin(name)
         if main_class != None:
             return main_class().render()
         else:
             return xtemplate.render("error.html",
                                     error="plugin `%s` not found!" % name)
     except:
         error = xutils.print_exc()
         return xtemplate.render("error.html", error=error)
Beispiel #25
0
 def GET(self, path=""):
     path = xutils.unquote(path)
     template_name = "code/preview.html"
     if not path.endswith(".md"):
         return render(template_name, error="file extension error")
     if not os.path.exists(path):
         return render(template_name, error="文件不存在")
     basename = os.path.basename(path)
     content = xutils.readfile(path)
     return render(template_name,
                   html_title=basename,
                   content=content,
                   os=os,
                   type="file",
                   path=path)
Beispiel #26
0
 def GET(self, name):
     user_name = xauth.current_name()
     url = "/tools/" + name
     fname = xutils.unquote(name)
     if not name.endswith(".html"):
         fname += ".html"
     # Chrome下面 tools/timeline不能正常渲染
     web.header("Content-Type", "text/html")
     fpath = os.path.join(xconfig.HANDLERS_DIR, "tools", fname)
     if os.path.exists(fpath):
         if user_name != None:
             tool_name = get_inner_tool_name(url)
             add_visit_log(user_name, url)
         return xtemplate.render("tools/" + fname, show_aside=False)
     else:
         raise web.notfound()
Beispiel #27
0
    def edit_GET(self, name):
        name = xutils.unquote(name)
        origin_name = name
        path = os.path.join(WIKI_PATH, name)

        if name == "":
            name = "/"
        else:
            name = "/" + name
        if os.path.isdir(path):
            type = "dir"
            content = None
            children = []
            parent = name
            for child in os.listdir(path):
                if child.startswith("_"):
                    continue
                children.append(FileItem(parent, child, path))
            children.sort(key=lambda item: item.key)
        if not os.path.exists(path):
            type = "file"
            content = ""
            children = None
        else:
            type = "file"
            content = xutils.readfile(path)
            children = None

        parent = os.path.dirname(name)
        parentname = os.path.basename(parent)
        if parentname == "":
            parentname = "/"

        return render("code/wiki_edit.html",
                      show_aside=False,
                      os=os,
                      parent=parent,
                      parentname=parentname,
                      wikilist=get_path_list(name),
                      name=origin_name,
                      basename=os.path.basename(name),
                      children=children,
                      content=content,
                      type=type)
Beispiel #28
0
    def __init__(self, path, parent=None, merge=False):
        self.path = path
        self.name = os.path.basename(path)
        self.size = '-'
        self.cdate = '-'
        _, self.ext = os.path.splitext(path)
        self.ext = self.ext.lower()

        if parent != None:
            self.name = get_relative_path(path, parent)

        # 处理Windows盘符
        if path.endswith(":"):
            self.name = path

        try:
            st = os.stat(path)
            self.cdate = xutils.format_date(st.st_ctime)
        except:
            st = Storage()

        self.name = xutils.unquote(self.name)
        if os.path.isfile(path):
            self.type = "file"
            self.name = decode_name(self.name)
            _, self.ext = os.path.splitext(self.name)
            self.size = format_size(st.st_size)
        else:
            children = try_listdir(path)
            self.type = "dir"
            self.path += "/"
            if children != None:
                self.size = len(children)
            else:
                self.size = "ERR"

            if merge and self.size == 1:
                new_path = os.path.join(path, children[0])
                if not os.path.isdir(new_path):
                    return
                if parent is None:
                    parent = os.path.dirname(path)
                self.__init__(new_path, parent)
Beispiel #29
0
 def GET(self, path):
     path = xutils.unquote(path)
     path = xutils.get_real_path(path)
     if not self.is_path_allowed(path):
         xauth.check_login("admin")
     data_prefix = config.DATA_DIR
     if not path.startswith("static"):
         newpath = os.path.join(data_prefix, path)
     else:
         newpath = path
         # 兼容static目录数据
         if not os.path.exists(newpath):
             # len("static/") = 7
             newpath = os.path.join(data_prefix, newpath[7:])
     path = newpath
     if not os.path.isfile(path):
         # 静态文件不允许访问文件夹
         web.ctx.status = "404 Not Found"
         return "Not Readable %s" % path
     return self.handle_get(path)
Beispiel #30
0
    def GET(self, name=""):
        name = xutils.unquote(name)
        op = xutils.get_argument("op")
        path = xutils.get_argument("path")
        origin_name = name
        if name == "":
            name = "/"
        else:
            name = "/" + name
        path = xutils.get_real_path(path)
        has_readme = False
        if os.path.isfile(path):
            check_resource(path)
            type = "file"
            content = xutils.readfile(path)
            _, ext = os.path.splitext(path)
            if ext == ".csv" and not content.startswith("```csv"):
                content = "```csv\n" + content + "\n```"
            children = None
        else:
            # file not exists or not readable
            children = None
            content = "File \"%s\" does not exists" % origin_name
            type = "file"

        parent = os.path.dirname(name)
        parentname = os.path.basename(parent)
        if parentname == "":
            parentname = "/"

        return render("code/preview.html",
                      os=os,
                      path=path,
                      parent=parent,
                      parentname=parentname,
                      wikilist=get_path_list(name),
                      name=origin_name,
                      children=children,
                      content=content,
                      type=type,
                      has_readme=has_readme)