def remove_from_query(context, *args, **kwargs):
""" Renders a link with modified current query parameters """
query_params = []
# go through current query params..
for key, value_list in context["request"].GET._iterlists():
# skip keys mentioned in the args
if not key in args:
for value in value_list:
# skip key-value pairs mentioned in kwargs
if not (key in kwargs and unicode(value) == unicode(kwargs[key])):
query_params.append((key, value))
# empty values will be removed
query_string = context["request"].path
if len(query_params):
query_string = "?%s" % urllib.urlencode([
(key, force_str(value)) for (key, value) in query_params if value
]).replace("&", "&")
return query_string
utility_tags.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录