Exemplo n.º 1
0
def leagues_list():
    try:
        q = urlunquote(request.params["q"])
    except KeyError:
        is_search = False
    else:
        is_search = True

    db = request.db["football"]
    if is_search:
        item_count = football.get_leagues_count(db, dict={"name": q})
        page = Paginator.parse_page(request.params)
        pager = pager = Paginator(item_count, page, per_page=10)
        leagues = football.get_leagues(db, pager, dict={"name": q}, fixtures=False, teams=False)

    else:
        item_count = football.get_leagues_count(db)
        page = Paginator.parse_page(request.params)
        pager = pager = Paginator(item_count, page, per_page=10)
        leagues = football.get_leagues(db, pager, fixtures=False, teams=False)

    return dict(
        leagues=leagues,
        pager=pager,
        is_search=is_search,
        base_path=i18n_url("leagues:list"),
        view=request.params.get("view"),
    )
Exemplo n.º 2
0
 def unquoted(self, key):
     try:
         value = self.request.params[key]
     except KeyError:
         return None
     else:
         return urlunquote(value).strip()
def get_file_list(path=None, defaults=None):
    defaults = defaults or {}
    try:
        query = urlunquote(request.params['q']).strip()
    except KeyError:
        query = path or '.'
        is_search = False
    else:
        is_search = True

    show_hidden = request.params.get('hidden', 'no') == 'yes'

    manager = Manager(request.app.supervisor)
    if is_search:
        (dirs, files, meta, is_match) = manager.search(query, show_hidden)
        relpath = '.' if not is_match else query
        is_search = not is_match
        success = True  # search is always successful
    else:
        (success, dirs, files, meta) = manager.list(query, show_hidden)
        if not success:
            abort(404)
        relpath = query
    current = manager.get(relpath)
    up = get_parent_path(relpath)
    data = defaults.copy()
    data.update(dict(path=relpath,
                     current=current,
                     dirs=dirs,
                     files=files,
                     up=up,
                     is_search=is_search,
                     is_successful=success))
    return data
Exemplo n.º 4
0
def content_list():
    """ Show list of content """
    # parse search query
    query = urlunquote(request.params.get('q', '')).strip()
    # parse language filter
    default_lang = request.user.options.get('content_language', None)
    lang = request.params.get('language', default_lang)
    request.user.options['content_language'] = lang
    # parse content type filter
    content_type = request.params.get('content_type')
    if content_type not in metadata.CONTENT_TYPES:
        content_type = None
    # parse pagination params
    page = Paginator.parse_page(request.params)
    per_page = Paginator.parse_per_page(request.params)
    # get content list filtered by above parsed filter params
    item_count = content_count(query, lang, content_type)
    pager = Paginator(item_count, page, per_page)
    offset, limit = pager.items
    metas = filter_content(query,
                           lang,
                           content_type,
                           offset=offset,
                           limit=limit)
    return dict(metadata=metas,
                pager=pager,
                vals=request.params.decode(),
                query=query,
                chosen_lang=lang,
                content_types=metadata.CONTENT_TYPES,
                chosen_content_type=content_type,
                base_path=i18n_url('content:list'),
                view=request.params.get('view'))
def show_list_view(path, view, defaults):
    selected = request.query.get('selected', None)
    if selected:
        selected = urlunquote(selected)
    data = defaults.copy()
    paths = [f.rel_path for f in data['files']]
    data['facet_types'] = get_facet_types(paths)
    is_search = data.get('is_search', False)
    is_successful = data.get('is_successful', True)
    original_view = data.get('original_view')
    if not is_search and is_successful:
        # If no view was specified and we have an index file, then
        # we switch to the reader tab
        if view == 'html' or not original_view:
            data['index_file'] = find_html_index(paths, any_html=False)
            view = 'html' if data['index_file'] else view
            data['view'] = view

        if view == 'updates':
            data.update(get_descendants(path))
        elif view != 'generic':
            data['files'] = filter(
                lambda f: is_facet_valid(f.rel_path, view), data['files'])
    data['selected'] = selected
    return data
Exemplo n.º 6
0
def content_list():
    """ Show list of content """
    # parse search query
    query = urlunquote(request.params.get('q', '')).strip()
    # parse language filter
    default_lang = request.user.options.get('content_language', None)
    lang = request.params.get('language', default_lang)
    request.user.options['content_language'] = lang
    # parse content type filter
    content_type = request.params.get('content_type')
    if content_type not in metadata.CONTENT_TYPES:
        content_type = None
    # parse pagination params
    page = Paginator.parse_page(request.params)
    per_page = Paginator.parse_per_page(request.params)
    # get content list filtered by above parsed filter params
    item_count = content_count(query, lang, content_type)
    pager = Paginator(item_count, page, per_page)
    offset, limit = pager.items
    metas = filter_content(query,
                           lang,
                           content_type,
                           offset=offset,
                           limit=limit)
    return dict(metadata=metas,
                pager=pager,
                vals=request.params.decode(),
                query=query,
                chosen_lang=lang,
                content_types=metadata.CONTENT_TYPES,
                chosen_content_type=content_type,
                base_path=i18n_url('content:list'),
                view=request.params.get('view'))
Exemplo n.º 7
0
 def unquoted(self, key):
     try:
         value = self.request.params[key]
     except KeyError:
         return None
     else:
         return urlunquote(value).strip()
def handle_file_action(path):
    path = urlunquote(path)
    action = request.forms.get('action')
    if action == 'rename':
        return rename_path(path)
    elif action == 'delete':
        return delete_path(path)
    else:
        abort(400)
def direct_file(path):
    path = urlunquote(path)
    try:
        root = find_root(path)
    except RuntimeError:
        abort(404, _("File not found."))

    download = request.params.get('filename', False)
    return static_file(path, root=root, download=download)
def show_view(path, view, defaults):
    # Add all helpers
    defaults.update(dict(titlify=title_name, durify=durify,
                         get_selected=get_selected, get_adjacent=get_adjacent,
                         aspectify=aspectify))

    defaults.update(get_file_list(path))
    meta = request.query.get('info')
    if meta:
        return show_info_view(path, view, urlunquote(meta), defaults)
    return show_list_view(path, view, defaults)
def init_file_action(path=None):
    if path:
        path = urlunquote(path)
    else:
        path = '.'
    # Use 'generic' as default view
    original_view = request.query.get('view')
    view = original_view or 'generic'
    defaults = dict(path=path,
                    view=view,
                    original_view=original_view)
    action = request.query.get('action')
    if action == 'delete':
        return delete_path_confirm(path)
    elif action == 'thumb':
        return retrieve_thumb_url(path, defaults)
    return show_view(path, view, defaults)
        def wrapper(path, **kwargs):
            path = urlunquote(path)
            conf = request.app.config
            archive = Archive.setup(
                conf["library.backend"],
                request.app.supervisor.exts.fsal,
                request.db.content,
                contentdir=conf["library.contentdir"],
                meta_filenames=conf["library.metadata"],
            )
            content = archive.get_single(path)
            if not content:
                if abort_if_not_found:
                    abort(404)
                return func(path=path, meta=None, **kwargs)

            meta = metadata.Meta(request.app.supervisor, content.path, data=content)
            return func(path=path, meta=meta, **kwargs)
def retrieve_thumb_url(path, defaults):
    thumb_url = None
    thumb_path = get_thumb_path(urlunquote(request.query.get('target')))
    if thumb_path:
        thumb_url = quoted_url('files:direct', path=thumb_path)
    else:
        facet_type = request.query.get('facet', 'generic')
        try:
            facet = defaults['facets'][facet_type]
        except KeyError:
            pass
        else:
            cover = facet.get('cover')
            if cover:
                cover_path = os.path.join(facet['path'], cover)
                thumb_url = quoted_url('files:direct',
                                       path=cover_path)

    return dict(url=thumb_url)
Exemplo n.º 14
0
def urldecode_params(params):
    return {key: urlunquote(value) for key, value in params.items()}
Exemplo n.º 15
0
 def to_python(match):
     return urlunquote(match)
 def postprocess_region(self, value):
     return urlunquote(value)