当前位置: 首页>>代码示例>>Python>>正文


Python http.urlencode方法代码示例

本文整理汇总了Python中django.utils.http.urlencode方法的典型用法代码示例。如果您正苦于以下问题:Python http.urlencode方法的具体用法?Python http.urlencode怎么用?Python http.urlencode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.http的用法示例。


在下文中一共展示了http.urlencode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_query_string

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_query_string(self, new_params=None, remove=None):
        if new_params is None:
            new_params = {}
        if remove is None:
            remove = []
        p = dict(self.request.GET.items()).copy()
        arr_keys = list(p.keys())
        for r in remove:
            for k in arr_keys:
                if k.startswith(r):
                    del p[k]
        for k, v in new_params.items():
            if v is None:
                if k in p:
                    del p[k]
            else:
                p[k] = v
        return '?%s' % urlencode(p) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:20,代码来源:base.py

示例2: get_query_string

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_query_string(self, new_params=None, remove=None):
        new_params = {} if not new_params else new_params
        remove = [] if not remove else remove
        p = self.get_params().copy()
        for r in remove:
            for k in list(p):
                if k.startswith(r):
                    del p[k]
        for k, v in new_params.items():
            if v is None:
                if k in p:
                    del p[k]
            else:
                p[k] = v
        if p:
            return '?%s' % urlencode(sorted(p.items()))
        else:
            return '' 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:20,代码来源:list.py

示例3: get_query_string

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_query_string(params, new_params=None, remove=None):
    new_params = new_params if new_params else {}
    remove = remove if remove else []
    p = params.copy()
    for r in remove:
        for k in list(p):
            if k.startswith(r):
                del p[k]
    for k, v in new_params.items():
        if v is None:
            if k in p:
                del p[k]
        else:
            p[k] = v
    if p:
        return '?%s' % urlencode(sorted(p.items()))
    else:
        return '' 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:20,代码来源:utils.py

示例4: get_query_string

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_query_string(self, new_params=None, remove=None):
        if new_params is None:
            new_params = {}
        if remove is None:
            remove = []
        p = self.params.copy()
        for r in remove:
            for k in list(p):
                if k.startswith(r):
                    del p[k]
        for k, v in new_params.items():
            if v is None:
                if k in p:
                    del p[k]
            else:
                p[k] = v
        return '?%s' % urlencode(sorted(p.items())) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:main.py

示例5: get_preserved_filters

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_preserved_filters(self, request):
        """
        Returns the preserved filters querystring.
        """
        match = request.resolver_match
        if self.preserve_filters and match:
            opts = self.model._meta
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
            if current_url == changelist_url:
                preserved_filters = request.GET.urlencode()
            else:
                preserved_filters = request.GET.get('_changelist_filters')

            if preserved_filters:
                return urlencode({'_changelist_filters': preserved_filters})
        return '' 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:options.py

示例6: urlparams

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def urlparams(url_, hash=None, **query):
    """Add a fragment and/or query paramaters to a URL.

    New query params will be appended to exising parameters, except duplicate
    names, which will be replaced.
    """
    url = urlparse.urlparse(url_)
    fragment = hash if hash is not None else url.fragment

    # Use dict(parse_qsl) so we don't get lists of values.
    query_dict = dict(urlparse.parse_qsl(url.query))
    query_dict.update(query)

    query_string = urlencode(
        [(k, v) for k, v in query_dict.items() if v is not None])
    new = urlparse.ParseResult(url.scheme, url.netloc, url.path, url.params,
                               query_string, fragment)
    return new.geturl() 
开发者ID:mozilla,项目名称:sugardough,代码行数:20,代码来源:helpers.py

示例7: get_preserved_filters

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_preserved_filters(self, request):
        """
        Return the preserved filters querystring.
        """
        match = request.resolver_match
        if self.preserve_filters and match:
            opts = self.model._meta
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
            if current_url == changelist_url:
                preserved_filters = request.GET.urlencode()
            else:
                preserved_filters = request.GET.get('_changelist_filters')

            if preserved_filters:
                return urlencode({'_changelist_filters': preserved_filters})
        return '' 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:19,代码来源:options.py

示例8: register_crossref_doi

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def register_crossref_doi(identifier):
    from utils import setting_handler

    domain = identifier.article.journal.domain
    pingback_url = urlencode({'pingback': 'http://{0}{1}'.format(domain, reverse('crossref_pingback'))})

    use_crossref = setting_handler.get_setting('Identifiers', 'use_crossref',
                                               identifier.article.journal).processed_value

    if not use_crossref:
        logger.info("[DOI] Not using Crossref DOIs on this journal. Aborting registration.")
        return 'Crossref Disabled', 'Disabled'

    test_mode = setting_handler.get_setting(
            'Identifiers', 'crossref_test', identifier.article.journal
    ).processed_value or settings.DEBUG

    if test_mode:
        util_models.LogEntry.add_entry('Submission', "DOI registration running in test mode", 'Info',
                                       target=identifier.article)
    else:
        util_models.LogEntry.add_entry('Submission', "DOI registration running in live mode", 'Info',
                                       target=identifier.article)

    return send_crossref_deposit(test_mode, identifier) 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:27,代码来源:logic.py

示例9: dispatch

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def dispatch(self, request, *args, **kwargs):
        try:
            # Check that the logged-in user has a Comrade instance too:
            # even just trying to access the field will fail if not.
            request.user.comrade
        except Comrade.DoesNotExist:
            # If not, redirect to create one and remember to come back
            # here afterward.
            return HttpResponseRedirect(
                '{account_url}?{query_string}'.format(
                    account_url=reverse('account'),
                    query_string=urlencode({'next': request.path})))
        return super(ComradeRequiredMixin, self).dispatch(request, *args, **kwargs)

# If the logged-in user doesn't have an ApplicantApproval object,
# redirect them to create one.
# If the logged-in user has an ApplicantApproval object that isn't approved,
# redirect them to the eligibility results page.
#
# This mixin requires a 'round_slug' view keyword argument.
#
# Note that LoginRequiredMixin must be to the left of this class in the
# view's list of parent classes, and the base View must be to the right. 
开发者ID:outreachy,项目名称:website,代码行数:25,代码来源:mixins.py

示例10: querystring

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def querystring(context, **kwargs):
    """
    Print out the current querystring. Any keyword arguments to this template
    tag will be added to the querystring before it is printed out.

        <a href="/page/{% querystring key='value' %}">

    Will result in something like:

        <a href="/page/?foo=bar&key=value">
    """
    request = context['request']
    querydict = request.GET.copy()
    # Can't do querydict.update(kwargs), because QueryDict.update() appends to
    # the list of values, instead of replacing the values.
    for key, value in kwargs.items():
        if value is None:
            # Remove the key if the value is None
            querydict.pop(key, None)
        else:
            # Set the key otherwise
            querydict[key] = str(value)

    return '?' + querydict.urlencode() 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:wagtailadmin_tags.py

示例11: get_preserved_filters

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def get_preserved_filters(self, request):
        match = request.resolver_match
        if self.preserve_filters and match:
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_changelist' % self.get_base_viewname()
            if current_url == changelist_url:
                preserved_filters = request.GET.urlencode()
            else:
                preserved_filters = request.GET.get('_changelist_filters')

            if preserved_filters:
                return urlencode({'_changelist_filters': preserved_filters})
        return '' 
开发者ID:inueni,项目名称:django-subadmin,代码行数:15,代码来源:__init__.py

示例12: add_preserved_filters

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def add_preserved_filters(self, context, url, popup=False, to_field=None):
        opts = context.get('opts')
        preserved_filters = context.get('preserved_filters')

        parsed_url = list(urlparse(url))
        parsed_qs = dict(parse_qsl(parsed_url[4]))
        merged_qs = dict()

        if opts and preserved_filters:
            preserved_filters = dict(parse_qsl(preserved_filters))

            match_url = '/%s' % url.partition(get_script_prefix())[2]
            try:
                match = resolve(match_url)
            except Resolver404:
                pass
            else:
                current_url = '%s:%s' % (match.app_name, match.url_name)
                changelist_url = 'admin:%s_changelist' % self.get_base_viewname()
                if changelist_url == current_url and '_changelist_filters' in preserved_filters:
                    preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))

            merged_qs.update(preserved_filters)

        if popup:
            from django.contrib.admin.options import IS_POPUP_VAR
            merged_qs[IS_POPUP_VAR] = 1
        if to_field:
            from django.contrib.admin.options import TO_FIELD_VAR
            merged_qs[TO_FIELD_VAR] = to_field

        merged_qs.update(parsed_qs)

        parsed_url[4] = urlencode(merged_qs)
        return urlunparse(parsed_url) 
开发者ID:inueni,项目名称:django-subadmin,代码行数:37,代码来源:__init__.py

示例13: bitcoin_donation_url

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def bitcoin_donation_url(site_name, address):
    """Return a Bitcoin donation URL for DONATE_BITCOIN_ADDRESS or None."""
    if address:
        msg = 'Donate to {}'.format(site_name)
        url = 'bitcoin:{}?{}'.format(address, urlencode({'message': msg}))
        return url
    else:
        return None 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:10,代码来源:donate.py

示例14: ForbiddenResponse

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def ForbiddenResponse(request, errormsg=None, exception=None):
    error = mark_safe("You do not have permission to access this resource.")
    if not request.user.is_authenticated:
        login_url = settings.LOGIN_URL + '?' + urllib.parse.urlencode({'next': request.get_full_path()})
        error += mark_safe(' You are <strong>not logged in</strong>, so maybe <a href="%s">logging in</a> would help.' % (login_url))
    return HttpError(request, status=403, title="Forbidden", error=error, errormsg=errormsg) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:8,代码来源:auth.py

示例15: login_redirect

# 需要导入模块: from django.utils import http [as 别名]
# 或者: from django.utils.http import urlencode [as 别名]
def login_redirect(next_url):
    """
    Send the user to log in, and then to next_url
    """
    return HttpResponseRedirect(settings.LOGIN_URL + '?' + urlencode({'next': next_url})) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:7,代码来源:auth.py


注:本文中的django.utils.http.urlencode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。