本文整理汇总了Python中django.utils.http.urlquote_plus方法的典型用法代码示例。如果您正苦于以下问题:Python http.urlquote_plus方法的具体用法?Python http.urlquote_plus怎么用?Python http.urlquote_plus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.http
的用法示例。
在下文中一共展示了http.urlquote_plus方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_query_parameter
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def make_query_parameter(self,
predicate,
obj,
item_type=False):
""" makes a query parameter depending on the value
of the predicate slug
"""
if 'http://' in predicate or 'https://' in predicate:
predicate = urlquote_plus(predicate)
if 'http://' in obj or 'https://' in obj:
obj = urlquote_plus(obj)
dc_terms_obj = DCterms()
if predicate in dc_terms_obj.DC_SLUG_TO_FIELDS:
# there's a query parameter for this dc-terms metadata
query = dc_terms_obj.DC_SLUG_TO_FIELDS[predicate]
query += '=' + obj
elif item_type == 'predicates':
query = 'prop=' + obj
elif item_type == 'types':
query = 'obj=' + obj
else:
query = 'prop=' + predicate + '---' + obj
return query
示例2: get
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def get(self, request, *args, **kwargs):
def unwhitespace(val):
return " ".join(val.split())
if 'ps_q' in request.GET:
# Keeping Unicode in URL, replacing space with '+'.
query = uri_to_iri(urlquote_plus(unwhitespace(request.GET['ps_q'])))
params = {'query': query} if query else None
return HttpResponseRedirect(reverse_lazy('search', kwargs=params))
query = kwargs['query'] or '' # Avoiding query=None
self.query = unwhitespace(unquote_plus(query))
# Exclude places whose owner blocked unauthenticated viewing.
if not request.user.is_authenticated:
self.queryset = self.queryset.exclude(owner__pref__public_listing=False)
return super().get(request, *args, **kwargs)
示例3: encode_url_context_path
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def encode_url_context_path(self, context):
""" encodes a context path for a URL, retains
the path '/' characters
"""
if '/' in context:
context_ex = context.split('/')
else:
context_ex = [context]
quote_context_list = []
for c_part in context_ex:
url_c_part = urlquote_plus(c_part)
quote_context_list.append(url_c_part)
return '/'.join(quote_context_list)
示例4: get_prev_marker
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def get_prev_marker(self):
"""Returns the identifier for the first object in the current data set
for APIs that use marker/limit-based paging.
"""
return http.urlquote_plus(self.get_object_id(self.data[0])) \
if self.data else ''
示例5: get_marker
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def get_marker(self):
"""Returns the identifier for the last object in the current data set
for APIs that use marker/limit-based paging.
"""
return http.urlquote_plus(self.get_object_id(self.data[-1])) \
if self.data else ''
示例6: __call__
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def __call__(self, request):
if is_public_path(request.path):
return self.get_response(request)
if request.user.is_anonymous:
return HttpResponseRedirect(
"/MAAS/?next=%s" % urlquote_plus(request.path)
)
return self.get_response(request)
示例7: create_opengraph
# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlquote_plus [as 别名]
def create_opengraph(self):
""" creates opengraph metadata to facilitate snippets for
social media sites
"""
rp = RootPath()
base_url = rp.get_baseurl()
if isinstance(self.project_hero_uri, str):
self.og_image = self.project_hero_uri
else:
if self.observations is not False:
for obs in self.observations:
if obs.media_link_count >0:
for link in obs.media_links:
self.og_image = link.media[0].thumbnail
break
if self.content is not False:
# use a preview or a thumbnail image as the og_image
# also maybe a short description
if 'preview' in self.content and self.fullimage:
if isinstance(self.content['preview'], str):
self.og_image = self.content['preview']
elif 'thumbnail' in self.content:
if isinstance(self.content['thumbnail'], str):
self.og_image = self.content['thumbnail']
else:
# don't use any image
pass
if 'sum_text' in self.content:
# we have summary text, so use it
if len(self.content['sum_text']) > 0:
self.og_description = self.content['sum_text']
if not isinstance(self.og_image, str):
if isinstance(self.item_category_icon, str):
# we don't have an og_image yet, but we do have a category icon,
# so use that
self.og_image = self.item_category_icon
else:
# use the default Open Context icon
rp = RootPath()
base_url = rp.get_baseurl()
self.og_image = base_url + self.OPEN_CONTEXT_ICON
# do this anyway, since small pictures do not work.
self.og_image = base_url + self.OPEN_CONTEXT_ICON
if isinstance(self.og_image, str):
# if the base URL is not in the sting, we need to use a proxy
if base_url not in self.og_image:
proxy_url = base_url + '/entities/proxy/'
proxy_url += urlquote_plus(self.og_image)
self.og_image = proxy_url
self.og_title = self.citation.cite_title
if not isinstance(self.og_description, str):
self.og_description = ''
if isinstance(self.item_category_label, str) and self.act_nav == 'subjects':
self.og_description += self.item_category_label
if self.act_nav in self.ITEM_TYPE_DESCRIPTIONS:
if self.og_description == '':
self.og_description = 'A'
self.og_description += ' ' + self.ITEM_TYPE_DESCRIPTIONS[self.act_nav]
if self.act_nav != 'projects' and isinstance(self.project.label, str):
self.og_description += '; part of the ' + self.project.label
self.og_description += ' data publication.'