Example #1
0
class FacetBucketItem(object):
    def __init__(self,
                 facet,
                 key,
                 doc_count,
                 request_url,
                 selected,
                 formatter=None):
        self.facet = facet
        self.key = key
        self.doc_count = doc_count
        self.request_url = URL(request_url)
        self.selected = selected
        self.show_count = True
        self.formatter = formatter

    def name(self):
        return self.key

    def __str__(self):
        if self.formatter is not None:
            return f"{self.formatter(self.key)!s}"
        return f"{self.key!s}"

    def select_url(self):
        url = self.request_url.append_query_param(
            "selected_facets", "%s:%s" % (self.facet, self.key))
        return strip_pagination(url)

    def deselect_url(self):
        url = self.request_url.remove_query_param(
            "selected_facets", "%s:%s" % (self.facet, self.key))
        return strip_pagination(url)
Example #2
0
def facet_data(request, form, results):  # noqa (too complex (10))
    """
    Convert Haystack's facet data into a more useful datastructure that
    templates can use without having to manually construct URLs
    """
    facet_data = {}
    if not results:
        return facet_data

    base_url = URL(request.get_full_path())
    facet_counts = results.facet_counts()

    # Field facets
    valid_facets = [f for f in form.selected_facets if ':' in f]
    selected = dict(map(lambda x: x.split(':', 1), valid_facets))
    for key, facet in SEARCH_FACETS['fields'].items():
        facet_data[key] = {
            'name': facet['name'],
            'results': [],
            'order': facet['order'],
        }
        for name, count in facet_counts['fields'][key]:
            # Ignore zero-count facets for field
            if count == 0:
                continue
            field_filter = '%s_exact' % facet['field']
            datum = {'name': name, 'count': count}
            if selected.get(field_filter, None) == name:
                # This filter is selected - build the 'deselect' URL
                datum['selected'] = True
                url = base_url.remove_query_param(
                    'selected_facets', '%s:%s' % (field_filter, name))
                # Don't carry through pagination params
                if url.has_query_param('page'):
                    url = url.remove_query_param('page')
                datum['deselect_url'] = url.as_string()
            else:
                # This filter is not selected - built the 'select' URL
                datum['selected'] = False
                url = base_url.append_query_param(
                    'selected_facets', '%s:%s' % (field_filter, name))
                # Don't carry through pagination params
                if url.has_query_param('page'):
                    url = url.remove_query_param('page')
                datum['select_url'] = url.as_string()
            facet_data[key]['results'].append(datum)

    # Query facets
    for key, facet in SEARCH_FACETS['queries'].items():
        facet_data[key] = {'name': facet['name'], 'results': []}
        for name, query in facet['queries']:
            field_filter = '%s_exact' % facet['field']
            match = '%s_exact:%s' % (facet['field'], query)
            if match not in facet_counts['queries']:
                datum = {
                    'name': name,
                    'count': 0,
                }
            else:
                datum = {
                    'name': name,
                    'count': facet_counts['queries'][match],
                }
                if selected.get(field_filter, None) == query:
                    # Selected
                    datum['selected'] = True
                    url = base_url.remove_query_param('selected_facets', match)
                    datum['deselect_url'] = url.as_string()
                else:
                    datum['selected'] = False
                    url = base_url.append_query_param('selected_facets', match)
                    datum['select_url'] = url.as_string()
            sorted_datum = sorted(datum.items(), key=lambda x: x['name'])
            facet_data[key]['results'].append(sorted_datum)

    for k in facet_data:
        facet_data[k]['results'] = sorted(facet_data[k]['results'],
                                          key=lambda x: x['name'])

    facets = sorted(facet_data.items(), key=lambda x: x[1]['order'])

    return facets
Example #3
0
 def test_remove_item_from_list(self):
     base = URL('http://127.0.0.1/?q=a&q=b')
     url = base.remove_query_param('q', 'a')
     values = url.query_param('q', as_list=True)
     self.assertEqual(['b'], values)
Example #4
0
def facet_data(request, form, results):  # noqa (too complex (10))
    """
    Convert Haystack's facet data into a more useful datastructure that
    templates can use without having to manually construct URLs
    """
    facet_data = {}
    if not results:
        return facet_data

    base_url = URL(request.get_full_path())
    facet_counts = results.facet_counts()

    # Field facets
    valid_facets = [f for f in form.selected_facets if ':' in f]
    selected = dict(
        map(lambda x: x.split(':', 1), valid_facets))
    for key, facet in settings.OSCAR_SEARCH_FACETS['fields'].items():
        facet_data[key] = {
            'name': facet['name'],
            'results': []}
        for name, count in facet_counts['fields'][key]:
            # Ignore zero-count facets for field
            if count == 0:
                continue
            field_filter = '%s_exact' % facet['field']
            datum = {
                'name': name,
                'count': count}
            if selected.get(field_filter, None) == name:
                # This filter is selected - build the 'deselect' URL
                datum['selected'] = True
                url = base_url.remove_query_param(
                    'selected_facets', '%s:%s' % (
                        field_filter, name))
                # Don't carry through pagination params
                if url.has_query_param('page'):
                    url = url.remove_query_param('page')
                datum['deselect_url'] = url.as_string()
            else:
                # This filter is not selected - built the 'select' URL
                datum['selected'] = False
                url = base_url.append_query_param(
                    'selected_facets', '%s:%s' % (
                        field_filter, name))
                # Don't carry through pagination params
                if url.has_query_param('page'):
                    url = url.remove_query_param('page')
                datum['select_url'] = url.as_string()
            facet_data[key]['results'].append(datum)

    # Query facets
    for key, facet in settings.OSCAR_SEARCH_FACETS['queries'].items():
        facet_data[key] = {
            'name': facet['name'],
            'results': []}
        for name, query in facet['queries']:
            field_filter = '%s_exact' % facet['field']
            match = '%s_exact:%s' % (facet['field'], query)
            if match not in facet_counts['queries']:
                datum = {
                    'name': name,
                    'count': 0,
                }
            else:
                datum = {
                    'name': name,
                    'count': facet_counts['queries'][match],
                }
                if selected.get(field_filter, None) == query:
                    # Selected
                    datum['selected'] = True
                    url = base_url.remove_query_param(
                        'selected_facets', match)
                    datum['deselect_url'] = url.as_string()
                else:
                    datum['selected'] = False
                    url = base_url.append_query_param(
                        'selected_facets', match)
                    datum['select_url'] = url.as_string()
                facet_data[key]['results'].append(datum)

    return facet_data
Example #5
0
class FacetMunger(object):
    def __init__(self, path, selected_multi_facets, facet_counts):
        self.base_url = URL(path)
        self.selected_facets = selected_multi_facets
        self.facet_counts = facet_counts

    def facet_data(self):
        facet_data = OrderedDict()
        # Haystack can return an empty dict for facet_counts when e.g. Solr
        # isn't running. Skip facet munging in that case.
        if self.facet_counts:
            self.munge_field_facets(facet_data)
            self.munge_query_facets(facet_data)
        return facet_data

    def munge_field_facets(self, clean_data):
        for key, facet in settings.OSCAR_SEARCH_FACETS['fields'].items():
            self.munge_field_facet(key, facet, clean_data)

    def munge_field_facet(self, key, facet, clean_data):
        clean_data[key] = {'name': facet['name'], 'results': []}
        for field_value, count in self.facet_counts['fields'][key]:
            field_name = '%s_exact' % facet['field']
            is_faceted_already = field_name in self.selected_facets
            datum = {
                'name': field_value,
                'count': count,
                # We don't show facet counts if a this field is already being
                # faceted (as we don't know them)
                'show_count': not is_faceted_already,
                'disabled': count == 0 and not is_faceted_already,
                'selected': False
            }
            if field_value in self.selected_facets.get(field_name, []):
                # This filter is selected - build the 'deselect' URL
                datum['selected'] = True
                url = self.base_url.remove_query_param(
                    'selected_facets', '%s:%s' % (field_name, field_value))
                datum['deselect_url'] = self.strip_pagination(url)
            else:
                # This filter is not selected - built the 'select' URL
                url = self.base_url.append_query_param(
                    'selected_facets', '%s:%s' % (field_name, field_value))
                datum['select_url'] = self.strip_pagination(url)

            clean_data[key]['results'].append(datum)

    def munge_query_facets(self, clean_data):
        for key, facet in settings.OSCAR_SEARCH_FACETS['queries'].items():
            self.munge_query_facet(key, facet, clean_data)

    def munge_query_facet(self, key, facet, clean_data):
        clean_data[key] = {'name': facet['name'], 'results': []}
        # Loop over the queries in OSCAR_SEARCH_FACETS rather than the returned
        # facet information from the search backend.
        for field_value, query in facet['queries']:
            field_name = '%s_exact' % facet['field']
            is_faceted_already = field_name in self.selected_facets

            match = '%s:%s' % (field_name, query)
            if match not in self.facet_counts['queries']:
                # This query was not returned
                datum = {
                    'name': field_value,
                    'count': 0,
                    'show_count': True,
                    'disabled': True,
                }
            else:
                count = self.facet_counts['queries'][match]
                datum = {
                    'name': field_value,
                    'count': count,
                    'show_count': not is_faceted_already,
                    'disabled': count == 0 and not is_faceted_already,
                    'selected': False,
                }
                if query in self.selected_facets.get(field_name, []):
                    # Selected
                    datum['selected'] = True
                    datum['show_count'] = True
                    url = self.base_url.remove_query_param(
                        'selected_facets', match)
                    datum['deselect_url'] = self.strip_pagination(url)
                else:
                    url = self.base_url.append_query_param(
                        'selected_facets', match)
                    datum['select_url'] = self.strip_pagination(url)
            clean_data[key]['results'].append(datum)

    def strip_pagination(self, url):
        if url.has_query_param('page'):
            url = url.remove_query_param('page')
        return url.as_string()
Example #6
0
def facet_data(request, form, results):
    """
    Convert Haystack's facet data into a more useful datastructure that
    templates can use without having to manually construct URLs
    """
    facet_data = {}
    base_url = URL(request.get_full_path())
    facet_counts = results.facet_counts()

    # Field facets
    selected = dict(map(lambda x: x.split(':'), form.selected_facets))
    for key, facet in settings.OSCAR_SEARCH_FACETS['fields'].items():
        facet_data[key] = {'name': facet['name'], 'results': []}
        for name, count in facet_counts['fields'][key]:
            # Ignore zero-count facets for field
            if count == 0:
                continue
            field_filter = '%s_exact' % facet['field']
            datum = {'name': name, 'count': count}
            if selected.get(field_filter, None) == name:
                # This filter is selected - build the 'deselect' URL
                datum['selected'] = True
                url = base_url.remove_query_param(
                    'selected_facets', '%s:%s' % (field_filter, name))
                datum['deselect_url'] = url.as_string()
            else:
                # This filter is not selected - built the 'select' URL
                datum['selected'] = False
                url = base_url.append_query_param(
                    'selected_facets', '%s:%s' % (field_filter, name))
                datum['select_url'] = url.as_string()
            facet_data[key]['results'].append(datum)

    # Query facets
    for key, facet in settings.OSCAR_SEARCH_FACETS['queries'].items():
        facet_data[key] = {'name': facet['name'], 'results': []}
        for name, query in facet['queries']:
            field_filter = '%s_exact' % facet['field']
            match = '%s_exact:%s' % (facet['field'], query)
            if match not in facet_counts['queries']:
                datum = {
                    'name': name,
                    'count': 0,
                }
            else:
                datum = {
                    'name': name,
                    'count': facet_counts['queries'][match],
                }
                if selected.get(field_filter, None) == query:
                    # Selected
                    datum['selected'] = True
                    url = base_url.remove_query_param('selected_facets', match)
                    datum['deselect_url'] = url.as_string()
                else:
                    datum['selected'] = False
                    url = base_url.append_query_param('selected_facets', match)
                    datum['select_url'] = url.as_string()
                facet_data[key]['results'].append(datum)

    return facet_data
Example #7
0
    def extra_context(self):
        extra = super(FacetedSearchView, self).extra_context()

        if 'fields' not in extra['facets']:
            # Looks like Solr is not responding correctly
            return extra

        # Convert facet data into a more useful datastructure

        # Field facets
        facet_data = {}
        base_url = URL(self.request.get_full_path())
        selected = dict(map(lambda x: x.split(':'), self.form.selected_facets))
        for field, facets in extra['facets']['fields'].items():
            facet_data[field] = []
            for name, count in facets:
                # Ignore zero-count facets for field
                if count == 0:
                    continue
                field_filter = '%s_exact' % field
                datum = {'name': name, 'count': count}
                if selected.get(field_filter, None) == name:
                    # This filter is selected - build the 'deselect' URL
                    datum['selected'] = True
                    url = base_url.remove_query_param(
                        'selected_facets', '%s:%s' % (field_filter, name))
                    datum['deselect_url'] = url.as_string()
                else:
                    # This filter is not selected - built the 'select' URL
                    datum['selected'] = False
                    url = base_url.append_query_param(
                        'selected_facets', '%s:%s' % (field_filter, name))
                    datum['select_url'] = url.as_string()
                facet_data[field].append(datum)

        # Query facets
        for key, facet in settings.OSCAR_SEARCH_FACETS['queries'].items():
            facet_data[key] = []
            for name, query in facet['queries']:
                field_filter = '%s_exact' % facet['field']
                match = '%s_exact:%s' % (facet['field'], query)
                if not match in extra['facets']['queries']:
                    datum = {
                        'name': name,
                        'count': 0,
                    }
                else:
                    datum = {
                        'name': name,
                        'count': extra['facets']['queries'][match],
                    }
                    if selected.get(field_filter, None) == query:
                        # Selected
                        datum['selected'] = True
                        url = base_url.remove_query_param(
                            'selected_facets', match)
                        datum['deselect_url'] = url.as_string()
                    else:
                        datum['selected'] = False
                        url = base_url.append_query_param(
                            'selected_facets', match)
                        datum['select_url'] = url.as_string()
                    facet_data[key].append(datum)

        extra['facet_data'] = facet_data

        return extra
Example #8
0
class FacetMunger(object):
    def __init__(self, path, selected_multi_facets, facet_counts):
        self.base_url = URL(path)
        self.selected_facets = selected_multi_facets
        self.facet_counts = facet_counts

    def facet_data(self):
        facet_data = {}
        # Haystack can return an empty dict for facet_counts when e.g. Solr
        # isn't running. Skip facet munging in that case.
        if self.facet_counts:
            self.munge_field_facets(facet_data)
            self.munge_query_facets(facet_data)
        return facet_data

    def munge_field_facets(self, clean_data):
        for key, facet in settings.OSCAR_SEARCH_FACETS["fields"].items():
            self.munge_field_facet(key, facet, clean_data)

    def munge_field_facet(self, key, facet, clean_data):
        clean_data[key] = {"name": facet["name"], "results": []}
        for field_value, count in self.facet_counts["fields"][key]:
            field_name = "%s_exact" % facet["field"]
            is_faceted_already = field_name in self.selected_facets
            datum = {
                "name": field_value,
                "count": count,
                # We don't show facet counts if a this field is already being
                # faceted (as we don't know them)
                "show_count": not is_faceted_already,
                "disabled": count == 0 and not is_faceted_already,
                "selected": False,
            }
            if field_value in self.selected_facets.get(field_name, []):
                # This filter is selected - build the 'deselect' URL
                datum["selected"] = True
                url = self.base_url.remove_query_param("selected_facets", "%s:%s" % (field_name, field_value))
                datum["deselect_url"] = self.strip_pagination(url)
            else:
                # This filter is not selected - built the 'select' URL
                url = self.base_url.append_query_param("selected_facets", "%s:%s" % (field_name, field_value))
                datum["select_url"] = self.strip_pagination(url)

            clean_data[key]["results"].append(datum)

    def munge_query_facets(self, clean_data):
        for key, facet in settings.OSCAR_SEARCH_FACETS["queries"].items():
            self.munge_query_facet(key, facet, clean_data)

    def munge_query_facet(self, key, facet, clean_data):
        clean_data[key] = {"name": facet["name"], "results": []}
        # Loop over the queries in OSCAR_SEARCH_FACETS rather than the returned
        # facet information from the search backend.
        for field_value, query in facet["queries"]:
            field_name = "%s_exact" % facet["field"]
            is_faceted_already = field_name in self.selected_facets

            match = "%s:%s" % (field_name, query)
            if match not in self.facet_counts["queries"]:
                # This query was not returned
                datum = {"name": field_value, "count": 0, "show_count": True, "disabled": True}
            else:
                count = self.facet_counts["queries"][match]
                datum = {
                    "name": field_value,
                    "count": count,
                    "show_count": not is_faceted_already,
                    "disabled": count == 0 and not is_faceted_already,
                    "selected": False,
                }
                if query in self.selected_facets.get(field_name, []):
                    # Selected
                    datum["selected"] = True
                    datum["show_count"] = True
                    url = self.base_url.remove_query_param("selected_facets", match)
                    datum["deselect_url"] = self.strip_pagination(url)
                else:
                    url = self.base_url.append_query_param("selected_facets", match)
                    datum["select_url"] = self.strip_pagination(url)
            clean_data[key]["results"].append(datum)

    def strip_pagination(self, url):
        if url.has_query_param("page"):
            url = url.remove_query_param("page")
        return url.as_string()
Example #9
0
    def extra_context(self):
        extra = super(FacetedSearchView, self).extra_context()

        if 'fields'  not in extra['facets']:
            # Looks like Solr is not responding correctly
            return extra

        # Convert facet data into a more useful datastructure

        # Field facets
        facet_data = {}
        base_url = URL(self.request.get_full_path())
        selected = dict(
            map(lambda x: x.split(':'), self.form.selected_facets))
        for field, facets in extra['facets']['fields'].items():
            facet_data[field] = []
            for name, count in facets:
                # Ignore zero-count facets for field
                if count == 0:
                    continue
                field_filter = '%s_exact' % field
                datum = {
                    'name': name,
                    'count': count}
                if selected.get(field_filter, None) == name:
                    # This filter is selected - build the 'deselect' URL
                    datum['selected'] = True
                    url = base_url.remove_query_param(
                        'selected_facets', '%s:%s' % (
                            field_filter, name))
                    datum['deselect_url'] = url.as_string()
                else:
                    # This filter is not selected - built the 'select' URL
                    datum['selected'] = False
                    url = base_url.append_query_param(
                        'selected_facets', '%s:%s' % (
                            field_filter, name))
                    datum['select_url'] = url.as_string()
                facet_data[field].append(datum)

        # Query facets
        for key, facet in settings.OSCAR_SEARCH_FACETS['queries'].items():
            facet_data[key] = []
            for name, query in facet['queries']:
                field_filter = '%s_exact' % facet['field']
                match = '%s_exact:%s' % (facet['field'], query)
                if not match in extra['facets']['queries']:
                    datum = {
                        'name': name,
                        'count': 0,
                    }
                else:
                    datum = {
                        'name': name,
                        'count': extra['facets']['queries'][match],
                    }
                    if selected.get(field_filter, None) == query:
                        # Selected
                        datum['selected'] = True
                        url = base_url.remove_query_param(
                            'selected_facets', match)
                        datum['deselect_url'] = url.as_string()
                    else:
                        datum['selected'] = False
                        url = base_url.append_query_param(
                            'selected_facets', match)
                        datum['select_url'] = url.as_string()
                    facet_data[key].append(datum)

        extra['facet_data'] = facet_data

        return extra
def facet_data(request, form, results):
    """
    Convert Haystack's facet data into a more useful datastructure that
    templates can use without having to manually construct URLs
    """
    facet_data = {}
    base_url = URL(request.get_full_path())
    facet_counts = results.facet_counts()

    # Field facets
    selected = dict(
        map(lambda x: x.split(':'), form.selected_facets))
    for field, facets in facet_counts['fields'].items():
        facet_data[field] = []
        for name, count in facets:
            # Ignore zero-count facets for field
            if count == 0:
                continue
            field_filter = '%s_exact' % field
            datum = {
                'name': name,
                'count': count}
            if selected.get(field_filter, None) == name:
                # This filter is selected - build the 'deselect' URL
                datum['selected'] = True
                url = base_url.remove_query_param(
                    'selected_facets', '%s:%s' % (
                        field_filter, name))
                datum['deselect_url'] = url.as_string()
            else:
                # This filter is not selected - built the 'select' URL
                datum['selected'] = False
                url = base_url.append_query_param(
                    'selected_facets', '%s:%s' % (
                        field_filter, name))
                datum['select_url'] = url.as_string()
            facet_data[field].append(datum)

    # Query facets
    for key, facet in settings.OSCAR_SEARCH_FACETS['queries'].items():
        facet_data[key] = []
        for name, query in facet_counts['queries'].items():
            field_filter = '%s_exact' % facet['field']
            match = '%s_exact:%s' % (facet['field'], query)
            if match not in facet_counts['queries']:
                datum = {
                    'name': name,
                    'count': 0,
                }
            else:
                datum = {
                    'name': name,
                    'count': facet_counts['queries'][match],
                }
                if selected.get(field_filter, None) == query:
                    # Selected
                    datum['selected'] = True
                    url = base_url.remove_query_param(
                        'selected_facets', match)
                    datum['deselect_url'] = url.as_string()
                else:
                    datum['selected'] = False
                    url = base_url.append_query_param(
                        'selected_facets', match)
                    datum['select_url'] = url.as_string()
                facet_data[key].append(datum)

    return facet_data
Example #11
0
class FacetMunger(object):

    def __init__(self, path, selected_multi_facets, facet_counts):
        self.base_url = URL(path)
        self.selected_facets = selected_multi_facets
        self.facet_counts = facet_counts

    def facet_data(self):
        facet_data = OrderedDict()
        # Haystack can return an empty dict for facet_counts when e.g. Solr
        # isn't running. Skip facet munging in that case.
        if self.facet_counts:
            self.munge_field_facets(facet_data)
            self.munge_query_facets(facet_data)
        return facet_data

    def munge_field_facets(self, clean_data):
        for key, facet in settings.GRAVYBOAT_SEARCH_FACETS['fields'].items():
            self.munge_field_facet(key, facet, clean_data)

    def munge_field_facet(self, key, facet, clean_data):
        clean_data[key] = {
            'name': facet['name'],
            'results': []}
        for field_value, count in self.facet_counts['fields'][key]:
            field_name = '%s_exact' % facet['field']
            is_faceted_already = field_name in self.selected_facets
            datum = {
                'name': field_value,
                'count': count,
                # We don't show facet counts if a this field is already being
                # faceted (as we don't know them)
                'show_count': not is_faceted_already,
                'disabled': count == 0 and not is_faceted_already,
                'selected': False
            }
            if field_value in self.selected_facets.get(field_name, []):
                # This filter is selected - build the 'deselect' URL
                datum['selected'] = True
                url = self.base_url.remove_query_param(
                    'selected_facets', '%s:%s' % (
                        field_name, field_value))
                datum['deselect_url'] = self.strip_pagination(url)
            else:
                # This filter is not selected - built the 'select' URL
                url = self.base_url.append_query_param(
                    'selected_facets', '%s:%s' % (
                        field_name, field_value))
                datum['select_url'] = self.strip_pagination(url)

            clean_data[key]['results'].append(datum)

    def munge_query_facets(self, clean_data):
        for key, facet in settings.GRAVYBOAT_SEARCH_FACETS['queries'].items():
            self.munge_query_facet(key, facet, clean_data)

    def munge_query_facet(self, key, facet, clean_data):
        clean_data[key] = {
            'name': facet['name'],
            'results': []}
        # Loop over the queries in GRAVYBOAT_SEARCH_FACETS rather than the returned
        # facet information from the search backend.
        for field_value, query in facet['queries']:
            field_name = '%s_exact' % facet['field']
            is_faceted_already = field_name in self.selected_facets

            match = '%s:%s' % (field_name, query)
            if match not in self.facet_counts['queries']:
                # This query was not returned
                datum = {
                    'name': field_value,
                    'count': 0,
                    'show_count': True,
                    'disabled': True,
                }
            else:
                count = self.facet_counts['queries'][match]
                datum = {
                    'name': field_value,
                    'count': count,
                    'show_count': not is_faceted_already,
                    'disabled': count == 0 and not is_faceted_already,
                    'selected': False,
                }
                if query in self.selected_facets.get(field_name, []):
                    # Selected
                    datum['selected'] = True
                    datum['show_count'] = True
                    url = self.base_url.remove_query_param(
                        'selected_facets', match)
                    datum['deselect_url'] = self.strip_pagination(url)
                else:
                    url = self.base_url.append_query_param(
                        'selected_facets', match)
                    datum['select_url'] = self.strip_pagination(url)
            clean_data[key]['results'].append(datum)

    def strip_pagination(self, url):
        if url.has_query_param('page'):
            url = url.remove_query_param('page')
        return url.as_string()
Example #12
0
File: tests.py Project: st4lk/purl
 def test_remove_item_from_list(self):
     base = URL('http://127.0.0.1/?q=a&q=b')
     url = base.remove_query_param('q', 'a')
     values = url.query_param('q', as_list=True)
     self.assertEqual(['b'], values)
Example #13
0
 def remove_page_arg(url):
     url = URL(url)
     return url.remove_query_param("page").as_string()
Example #14
0
 def deselect(self, url):
     url = URL(url)
     field_name = '%s_exact' % self.facet_name
     url = url.remove_query_param('selected_facets', '%s:%s' % (field_name, self.key))
     self.selected = False
     return url
Example #15
0
 def test_remove_item_from_list(self):
     base = URL("http://127.0.0.1/?q=a&q=b")
     url = base.remove_query_param("q", "a")
     values = url.query_param("q", as_list=True)
     self.assertEqual(["b"], values)