示例#1
0
def hdx_add_url_param(alternative_url=None,
                      controller=None,
                      action=None,
                      extras=None,
                      new_params=None,
                      unwanted_keys=[]):
    '''
    MODIFIED CKAN HELPER THAT ALLOWS REMOVING SOME PARAMS

    Adds extra parameters to existing ones

    controller action & extras (dict) are used to create the base url
    via url_for(controller=controller, action=action, **extras)
    controller & action default to the current ones

    This can be overriden providing an alternative_url, which will be used
    instead.
    '''

    params_nopage = [(k, v) for k, v in request.params.items()
                     if k != 'page' and k not in unwanted_keys]
    params = set(params_nopage)
    if new_params:
        params |= set(new_params.items())
    if alternative_url:
        return h._url_with_params(alternative_url, params)
    return h._create_url_with_params(params=params,
                                     controller=controller,
                                     action=action,
                                     extras=extras)
示例#2
0
def remove_url_param(key,
                     value=None,
                     replace=None,
                     controller=None,
                     action=None,
                     extras=None,
                     alternative_url=None):
    if isinstance(key, basestring):
        keys = [key]
    else:
        keys = key

    params_nopage = [(k, v) for k, v in request.params.items() if k != 'page']
    params = list(params_nopage)
    if value:
        params.remove((keys[0], value))
    else:
        for key in keys:
            [params.remove((k, v)) for (k, v) in params[:] if k == key]
    if replace is not None:
        params.append((keys[0], replace))
    if alternative_url:
        return ckan_helpers._url_with_params(alternative_url, params)
    return ckan_helpers._create_url_with_params(params=params,
                                                controller=controller,
                                                action=action,
                                                extras=extras)
示例#3
0
def replace_url_param(new_params,
                      alternative_url=None,
                      controller=None,
                      action=None,
                      extras=None):
    '''
    replace existing parameters with new ones

    controller action & extras (dict) are used to create the base url via
    :py:func:`~ckan.lib.helpers.url_for` controller & action default to the
    current ones

    This can be overriden providing an alternative_url, which will be used
    instead.
    '''
    params_cleaned = [(k, v) for k, v in toolkit.request.params.items()
                      if k not in new_params.keys()]
    params = set(params_cleaned)
    if new_params:
        params |= set(new_params.items())
    if alternative_url:
        return helpers._url_with_params(alternative_url, params)
    return helpers._create_url_with_params(params=params,
                                           controller=controller,
                                           action=action,
                                           extras=extras)
def _create_filter_url(params, extras=None):
    """
    Helper function to create filter URL
    @param params:
    @param extras:
    @return:
    """
    params_no_page = [(k, v) for k, v in params.items() if k != 'page']
    return h._create_url_with_params(list(params_no_page), extras=extras)
示例#5
0
    def h_add_url_param_unique(self,
                               alternative_url=None,
                               controller=None,
                               action=None,
                               extras=None,
                               new_params=None):
        from ckan.common import request
        from ckan.lib import helpers as h

        params_nopage = [(k, v) for k, v in request.params.items()
                         if ((k != 'page') and (k not in new_params))]
        params = set(params_nopage)
        if new_params:
            params |= set(new_params.items())
        if alternative_url:
            return h._url_with_params(alternative_url, params)
        return h._create_url_with_params(params=params,
                                         controller=controller,
                                         action=action,
                                         extras=extras)
def replace_url_param(new_params, alternative_url=None, controller=None,
                      action=None, extras=None):
    '''
    replace existing parameters with new ones

    controller action & extras (dict) are used to create the base url via
    :py:func:`~ckan.lib.helpers.url_for` controller & action default to the
    current ones

    This can be overriden providing an alternative_url, which will be used
    instead.
    '''
    params_cleaned = [(k, v) for k, v in toolkit.request.params.items()
                      if k not in new_params.keys()]
    params = set(params_cleaned)
    if new_params:
        params |= set(new_params.items())
    if alternative_url:
        return helpers._url_with_params(alternative_url, params)
    return helpers._create_url_with_params(params=params,
                                           controller=controller,
                                           action=action, extras=extras)
示例#7
0
def hdx_add_url_param(alternative_url=None, controller=None, action=None,
                      extras=None, new_params=None, unwanted_keys=[]):
    '''
    MODIFIED CKAN HELPER THAT ALLOWS REMOVING SOME PARAMS

    Adds extra parameters to existing ones

    controller action & extras (dict) are used to create the base url
    via url_for(controller=controller, action=action, **extras)
    controller & action default to the current ones

    This can be overriden providing an alternative_url, which will be used
    instead.
    '''

    params_nopage = [(k, v) for k, v in request.params.items()
                     if k != 'page' and k not in unwanted_keys]
    params = set(params_nopage)
    if new_params:
        params |= set(new_params.items())
    if alternative_url:
        return h._url_with_params(alternative_url, params)
    return h._create_url_with_params(params=params, controller=controller,
                                     action=action, extras=extras)