本文整理汇总了Python中purl.URL.remove_query_param方法的典型用法代码示例。如果您正苦于以下问题:Python URL.remove_query_param方法的具体用法?Python URL.remove_query_param怎么用?Python URL.remove_query_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类purl.URL
的用法示例。
在下文中一共展示了URL.remove_query_param方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: facet_data
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import remove_query_param [as 别名]
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
示例2: extra_context
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import remove_query_param [as 别名]
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
示例3: facet_data
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import remove_query_param [as 别名]
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
示例4: FacetMunger
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import remove_query_param [as 别名]
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')
#.........这里部分代码省略.........
示例5: test_remove_item_from_list
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import remove_query_param [as 别名]
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)
示例6: deselect
# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import remove_query_param [as 别名]
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