Exemplo n.º 1
0
def on_search_plugins(ctx):
    if not xauth.is_admin():
        return
    if not ctx.search_tool:
        return
    if ctx.search_dict:
        return

    results = []

    for plugin in search_plugins(ctx.key):
        result = SearchResult()
        result.category = "plugin"
        result.icon = "fa-cube"
        result.name = u(plugin.name)
        result.name = u(plugin.title + "(" + plugin.name + ")")
        result.url = u(plugin.url)
        result.edit_link = plugin.edit_link
        results.append(result)

    result_count = len(results)
    if ctx.category != "plugin" and len(results) > 3:
        results = results[:3]
        more = SearchResult()
        more.name = u("查看更多插件(%s)") % result_count
        more.icon = "fa-cube"
        more.url = "/plugins_list?category=plugin&key=" + ctx.key
        results.append(more)
    ctx.tools += results
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
 def convert(x):
     r = SearchResult()
     r.name = x.ctime
     r.url = '#'
     r.command = None
     r.raw = x.content
     return r
Exemplo n.º 5
0
def wrap_results(dicts, origin_key):
    files = []
    for f0 in dicts:
        f = SearchResult()
        f.name = u("翻译 - ") + u(f0[origin_key])
        f.raw = f0["en"] + "\n"
        f.raw += f0["cn"].replace("\\n", "\n")
        f.url = "#"
        files.append(f)
    return files
Exemplo n.º 6
0
def search_plugins(name):
    results = []
    dirname = xconfig.PLUGINS_DIR
    for fname in xutils.listdir(dirname):
        if name in fname:
            result = SearchResult()
            result.category = "plugin"
            result.name = u("插件 - " + fname)
            result.url = u("/plugins/" + fname)
            result.edit_link = u("/code/edit?path=" +
                                 os.path.join(dirname, fname))
            results.append(result)
    return results
Exemplo n.º 7
0
def file_wrapper(dict, option=None):
    """build fileDO from dict"""
    name = dict['name']
    file = SearchResult()
    for key in dict:
        file[key] = dict[key]
        # setattr(file, key, dict[key])
    if hasattr(file, "content") and file.content is None:
        file.content = ""
    if option:
        file.option = option
    file.url = "/note/view?id={}".format(dict["id"])
    # 文档类型,和文件系统file区分
    file.category = "note"
    return file
Exemplo n.º 8
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
Exemplo n.º 9
0
def on_search_message(ctx):
    key = ctx.key
    touch_key_by_content(ctx.user_name, 'key', key)

    messages, count = MSG_DAO.search(ctx.user_name, key, 0, 3)
    for message in messages:
        item = SearchResult()
        if message.content != None and len(
                message.content) > xconfig.SEARCH_SUMMARY_LEN:
            message.content = message.content[:xconfig.
                                              SEARCH_SUMMARY_LEN] + "......"
        process_message(message)
        item.name = u('记事 - ') + message.ctime
        item.html = message.html
        ctx.messages.append(item)
        # print(message)
    if count > 3:
        more = SearchResult()
        more.name = "查看更多记事(%s)" % count
        more.url = "/message?key=" + ctx.key
        ctx.messages.append(more)