示例#1
0
文件: app.py 项目: jbradberry/dxr
def _browse_folder(tree, path, config):
    """Return a rendered folder listing for folder ``path``.

    Search for FILEs having folder == path. If any matches, render the folder
    listing. Otherwise, raise NotFound.

    """
    def item_or_list(item):
        """If item is a list, return its first element.

        Otherwise, just return it.

        """
        # TODO @pelmers: remove this function when format bumps to 20
        if isinstance(item, list):
            return item[0]
        return item

    frozen = frozen_config(tree)

    files_and_folders = filtered_query(
        frozen['es_alias'],
        FILE,
        filter={'folder': path},
        sort=[{'is_folder': 'desc'}, 'name'],
        size=1000000,
        include=['name', 'modified', 'size', 'link', 'path', 'is_binary',
                 'is_folder'])

    if not files_and_folders:
        raise NotFound

    return render_template(
        'folder.html',
        # Common template variables:
        www_root=config.www_root,
        tree=tree,
        tree_tuples=[
            (t['name'],
             url_for('.parallel', tree=t['name'], path=path),
             t['description'])
            for t in frozen_configs()],
        generated_date=frozen['generated_date'],
        google_analytics_key=config.google_analytics_key,
        paths_and_names=_linked_pathname(path, tree),
        filters=filter_menu_items(
            plugins_named(frozen['enabled_plugins'])),
        # Autofocus only at the root of each tree:
        should_autofocus_query=path == '',

        # Folder template variables:
        name=basename(path) or tree,
        path=path,
        files_and_folders=[
            (_icon_class_name(f),
             f['name'],
             decode_es_datetime(item_or_list(f['modified'])) if 'modified' in f else None,
             f.get('size'),
             url_for('.browse', tree=tree, path=f.get('link', f['path'])[0]))
            for f in files_and_folders])
示例#2
0
文件: app.py 项目: modulexcite/dxr
def _build_common_file_template(tree, path, date, config):
    """Return a dictionary of the common required file template parameters.
    """
    return {
        # Common template variables:
        'www_root':
        config.www_root,
        'tree':
        tree,
        'tree_tuples':
        [(t['name'], url_for('.parallel', tree=t['name'],
                             path=path), t['description'])
         for t in frozen_configs()],
        'generated_date':
        date,
        'google_analytics_key':
        config.google_analytics_key,
        'filters':
        filter_menu_items(plugins_named(
            frozen_config(tree)['enabled_plugins'])),
        # File template variables
        'paths_and_names':
        _linked_pathname(path, tree),
        'icon_url':
        url_for('.static', filename='icons/mimetypes/%s.png' % icon(path)),
        'path':
        path,
        'name':
        basename(path)
    }
示例#3
0
文件: app.py 项目: Darshnik/dxr
def _tree_tuples(query_text):
    """Return a list of rendering info for Switch Tree menu items."""
    return [(f['name'],
             url_for('.search',
                     tree=f['name'],
                     q=query_text),
             f['description'])
            for f in frozen_configs()]
示例#4
0
文件: app.py 项目: jay-z007/dxr
def _tree_tuples(query_text):
    """Return a list of rendering info for Switch Tree menu items."""
    return [(f['name'],
             url_for('.search',
                     tree=f['name'],
                     q=query_text),
             f['description'])
            for f in frozen_configs()]
示例#5
0
文件: app.py 项目: snyderp/dxr
def _tree_tuples(query_text, is_case_sensitive):
    """Return a list of rendering info for Switch Tree menu items."""
    return [(f['name'],
             url_for('.search',
                     tree=f['name'],
                     q=query_text,
                     **({'case': 'true'} if is_case_sensitive else {})),
             f['description'])
            for f in frozen_configs()]
示例#6
0
def _tree_tuples(endpoint, **kwargs):
    """Return a list of rendering info for Switch Tree menu items."""
    return [(f['name'],
             url_for(endpoint,
                     tree=f['name'],
                     **kwargs),
             f['description'],
             [(lang, color) for p in plugins_named(f['enabled_plugins'])
              for lang, color in sorted(p.badge_colors.iteritems())])
            for f in frozen_configs()]
示例#7
0
文件: app.py 项目: modulexcite/dxr
def _tree_tuples(query_text, is_case_sensitive):
    """Return a list of rendering info for Switch Tree menu items."""
    return [(f['name'],
             url_for('.search',
                     tree=f['name'],
                     q=query_text,
                     **({
                         'case': 'true'
                     } if is_case_sensitive else {})), f['description'])
            for f in frozen_configs()]
示例#8
0
文件: app.py 项目: kleintom/dxr
def _browse_folder(tree, path, config):
    """Return a rendered folder listing for folder ``path``.

    Search for FILEs having folder == path. If any matches, render the folder
    listing. Otherwise, raise NotFound.

    """
    frozen = frozen_config(tree)

    files_and_folders = filtered_query(frozen['es_alias'],
                                       FILE,
                                       filter={'folder': path},
                                       sort=[{
                                           'is_folder': 'desc'
                                       }, 'name'],
                                       size=10000,
                                       include=[
                                           'name', 'modified', 'size', 'link',
                                           'path', 'is_binary', 'is_folder'
                                       ])

    if not files_and_folders:
        raise NotFound

    return render_template(
        'folder.html',
        # Common template variables:
        www_root=config.www_root,
        tree=tree,
        tree_tuples=[(t['name'], url_for('.parallel',
                                         tree=t['name'],
                                         path=path), t['description'])
                     for t in frozen_configs()],
        generated_date=frozen['generated_date'],
        google_analytics_key=config.google_analytics_key,
        paths_and_names=_linked_pathname(path, tree),
        filters=filter_menu_items(plugins_named(frozen['enabled_plugins'])),
        # Autofocus only at the root of each tree:
        should_autofocus_query=path == '',

        # Folder template variables:
        name=basename(path) or tree,
        path=path,
        files_and_folders=[
            (_icon_class_name(f), f['name'],
             decode_es_datetime(f['modified']) if 'modified' in f else None,
             f.get('size'),
             url_for('.browse', tree=tree, path=f.get('link', f['path'])[0]))
            for f in files_and_folders
        ])
示例#9
0
文件: app.py 项目: nbstar/dxr
def _browse_folder(tree, path, config):
    """Return a rendered folder listing for folder ``path``.

    Search for FILEs having folder == path. If any matches, render the folder
    listing. Otherwise, raise NotFound.

    """
    frozen = frozen_config(tree)

    files_and_folders = filtered_query(
        frozen['es_alias'],
        FILE,
        filter={'folder': path},
        sort=[{'is_folder': 'desc'}, 'name'],
        size=10000,
        exclude=['raw_data'])
    if not files_and_folders:
        raise NotFound

    return render_template(
        'folder.html',
        # Common template variables:
        www_root=config.www_root,
        tree=tree,
        tree_tuples=[
            (t['name'],
             url_for('.parallel', tree=t['name'], path=path),
             t['description'])
            for t in frozen_configs()],
        generated_date=frozen['generated_date'],
        google_analytics_key=config.google_analytics_key,
        paths_and_names=_linked_pathname(path, tree),
        filters=filter_menu_items(
            plugins_named(frozen['enabled_plugins'])),
        # Autofocus only at the root of each tree:
        should_autofocus_query=path == '',

        # Folder template variables:
        name=basename(path) or tree,
        path=path,
        files_and_folders=[
            (_icon_class_name(f),
             f['name'],
             decode_es_datetime(f['modified']) if 'modified' in f else None,
             f.get('size'),
             url_for('.browse', tree=tree, path=f['path'][0]),
             f.get('is_binary', [False])[0])
            for f in files_and_folders])
示例#10
0
文件: app.py 项目: gartung/dxr
def _build_common_file_template(tree, path, date, config):
    """Return a dictionary of the common required file template parameters.
    """
    return {
        # Common template variables:
        'www_root': config.www_root,
        'tree': tree,
        'tree_tuples':
            [(t['name'],
              url_for('.parallel', tree=t['name'], path=path),
              t['description'])
            for t in frozen_configs()],
        'generated_date': date,
        'google_analytics_key': config.google_analytics_key,
        'filters': filter_menu_items(
            plugins_named(frozen_config(tree)['enabled_plugins'])),
        # File template variables
        'paths_and_names': _linked_pathname(path, tree),
        'icon': icon(path),
        'path': path,
        'name': basename(path)
    }