Python django.utils.http.urlencode() Examples
The following are 30
code examples of django.utils.http.urlencode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.http
, or try the search function
.
Example #1
Source File: helpers.py From sugardough with Apache License 2.0 | 7 votes |
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()
Example #2
Source File: list.py From django-idcops with Apache License 2.0 | 6 votes |
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 ''
Example #3
Source File: base.py From weibo-analysis-system with MIT License | 6 votes |
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)
Example #4
Source File: options.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
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 ''
Example #5
Source File: main.py From bioforum with MIT License | 6 votes |
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()))
Example #6
Source File: options.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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 ''
Example #7
Source File: main.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
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()))
Example #8
Source File: main.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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()))
Example #9
Source File: views.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()))
Example #10
Source File: base.py From myblog with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #11
Source File: utils.py From django-idcops with Apache License 2.0 | 6 votes |
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 ''
Example #12
Source File: options.py From bioforum with MIT License | 6 votes |
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 ''
Example #13
Source File: main.py From python with Apache License 2.0 | 6 votes |
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()))
Example #14
Source File: wagtailadmin_tags.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #15
Source File: base.py From StormOnline with Apache License 2.0 | 6 votes |
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)
Example #16
Source File: options.py From python with Apache License 2.0 | 6 votes |
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 ''
Example #17
Source File: base.py From CTF_AWD_Platform with MIT License | 6 votes |
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)
Example #18
Source File: helpers.py From feedthefox with Mozilla Public License 2.0 | 6 votes |
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()
Example #19
Source File: mixins.py From website with GNU General Public License v3.0 | 6 votes |
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.
Example #20
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #21
Source File: base.py From django_OA with GNU General Public License v3.0 | 6 votes |
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)
Example #22
Source File: views.py From website with GNU General Public License v3.0 | 5 votes |
def get_success_url(self, user): # Ugh, we need to chain together TWO next-page URLs so we can # confirm that the person who posesses this activation token # also knows the corresponding password, then make a stop at the # ComradeUpdate form, before finally going where the user # actually wanted to go. Sorry folks. if self.next_url: query = '?' + urlencode({'next': self.next_url}) else: query = '' query = '?' + urlencode({'next': reverse('account') + query}) return reverse('registration_activation_complete') + query
Example #23
Source File: admin_urls.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def add_preserved_filters(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 = {} if opts and preserved_filters: preserved_filters = dict(parse_qsl(preserved_filters)) match_url = '/%s' % unquote(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_%s_changelist' % (opts.app_label, opts.model_name) 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)
Example #24
Source File: client.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def head(self, path, data=None, secure=False, **extra): """Construct a HEAD request.""" data = {} if data is None else data return self.generic('HEAD', path, secure=secure, **{ 'QUERY_STRING': urlencode(data, doseq=True), **extra, })
Example #25
Source File: client.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def get(self, path, data=None, secure=False, **extra): """Construct a GET request.""" data = {} if data is None else data return self.generic('GET', path, secure=secure, **{ 'QUERY_STRING': urlencode(data, doseq=True), **extra, })
Example #26
Source File: test_page_chooser.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def post(self, post_data={}, url_params={}): url = reverse('wagtailadmin_choose_page_external_link') if url_params: url += '?' + urlencode(url_params) return self.client.post(url, post_data)
Example #27
Source File: widgets.py From ishare with MIT License | 5 votes |
def render(self, name, value, attrs=None, renderer=None): if value is None: value = '' # 传入模板的参数 editor_id = "id_%s" % name.replace("-", "_") uSettings = { "name": name, "id": editor_id, "value": value } if isinstance(self.command, list): cmdjs = "" if isinstance(self.command, list): for cmd in self.command: cmdjs = cmdjs + cmd.render(editor_id) else: cmdjs = self.command.render(editor_id) uSettings["commands"] = cmdjs uSettings["settings"] = self.ueditor_settings.copy() uSettings["settings"].update({ "serverUrl": "/ueditor/controller/?%s" % urlencode(self._upload_settings) }) # 生成事件侦听 if self.event_handler: uSettings["bindEvents"] = self.event_handler.render(editor_id) context = { 'UEditor': uSettings, 'STATIC_URL': settings.STATIC_URL, 'STATIC_ROOT': settings.STATIC_ROOT, 'MEDIA_URL': settings.MEDIA_URL, 'MEDIA_ROOT': settings.MEDIA_ROOT } return mark_safe(render_to_string('ueditor.html', context))
Example #28
Source File: mixins.py From website with GNU General Public License v3.0 | 5 votes |
def dispatch(self, request, *args, **kwargs): current_round = get_object_or_404(RoundPage, slug=self.kwargs['round_slug']) role = Role(request.user, current_round) if not role.is_applicant: return HttpResponseRedirect( '{url}?{query_string}'.format( url=reverse('eligibility'), query_string=urlencode({'next': request.path}))) if not role.is_approved_applicant: return redirect('eligibility-results') return super(EligibleApplicantRequiredMixin, self).dispatch(request, *args, **kwargs)
Example #29
Source File: wagtailadmin_tags.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def page_listing_buttons(context, page, page_perms, is_parent=False): next_url = urlencode({"next": context.request.path}) button_hooks = hooks.get_hooks('register_page_listing_buttons') buttons = sorted(itertools.chain.from_iterable( hook(page, page_perms, is_parent, next_url) for hook in button_hooks)) for hook in hooks.get_hooks('construct_page_listing_buttons'): hook(buttons, page, page_perms, is_parent, context) return {'page': page, 'buttons': buttons}
Example #30
Source File: __init__.py From Spirit with MIT License | 5 votes |
def get_url(url, obj_number, per_page, page_var): page = get_page_number(obj_number, per_page) data = urlencode({page_var: page, }) if page == 1: return "".join((url, '#c', str(obj_number))) return "".join((url, '?', data, '#c', str(obj_number)))