我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用django.utils.http.urlunquote()。
def _test_index_paginated(self, marker, sort_dir, volumes, url, has_more, has_prev): backup_supported = True vol_snaps = self.cinder_volume_snapshots.list() api.cinder.volume_backup_supported(IsA(http.HttpRequest)).\ MultipleTimes().AndReturn(backup_supported) api.cinder.volume_list_paged(IsA(http.HttpRequest), marker=marker, sort_dir=sort_dir, search_opts=None, paginate=True).\ AndReturn([volumes, has_more, has_prev]) api.cinder.volume_snapshot_list( IsA(http.HttpRequest), search_opts=None).AndReturn(vol_snaps) api.nova.server_list(IsA(http.HttpRequest), search_opts=None).\ AndReturn([self.servers.list(), False]) api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)).MultipleTimes().\ AndReturn(self.cinder_limits['absolute']) self.mox.ReplayAll() res = self.client.get(urlunquote(url)) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'project/volumes/index.html') self.mox.UnsetStubs() return res
def _test_snapshots_index_paginated(self, marker, sort_dir, snapshots, url, has_more, has_prev): backup_supported = True api.cinder.volume_backup_supported(IsA(http.HttpRequest)).\ MultipleTimes().AndReturn(backup_supported) api.cinder.volume_snapshot_list_paged( IsA(http.HttpRequest), marker=marker, sort_dir=sort_dir, paginate=True).AndReturn([snapshots, has_more, has_prev]) api.cinder.volume_list(IsA(http.HttpRequest)).AndReturn( self.cinder_volumes.list()) self.mox.ReplayAll() res = self.client.get(urlunquote(url)) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'project/volumes/index.html') self.mox.UnsetStubs() return res
def _test_backups_index_paginated(self, marker, sort_dir, backups, url, has_more, has_prev): backup_supported = True api.cinder.volume_backup_supported(IsA(http.HttpRequest)).\ MultipleTimes().AndReturn(backup_supported) api.cinder.volume_backup_list_paged( IsA(http.HttpRequest), marker=marker, sort_dir=sort_dir, paginate=True).AndReturn([backups, has_more, has_prev]) api.cinder.volume_list(IsA(http.HttpRequest)).AndReturn( self.cinder_volumes.list()) self.mox.ReplayAll() res = self.client.get(urlunquote(url)) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'project/volumes/index.html') self.mox.UnsetStubs() return res
def _test_index_paginated(self, marker, sort_dir, volumes, url, has_more, has_prev): vol_snaps = self.cinder_volume_snapshots.list() cinder.volume_list_paged(IsA(http.HttpRequest), sort_dir=sort_dir, marker=marker, paginate=True, search_opts={'all_tenants': True}) \ .AndReturn([volumes, has_more, has_prev]) api.cinder.volume_snapshot_list( IsA(http.HttpRequest), search_opts=None).AndReturn(vol_snaps) api.nova.server_list(IsA(http.HttpRequest), search_opts={ 'all_tenants': True}) \ .AndReturn([self.servers.list(), False]) keystone.tenant_list(IsA(http.HttpRequest)) \ .AndReturn([self.tenants.list(), False]) self.mox.ReplayAll() res = self.client.get(urlunquote(url)) self.assertTemplateUsed(res, 'admin/volumes/index.html') self.assertEqual(res.status_code, 200) self.mox.UnsetStubs() return res
def test_snapshots_tab(self): cinder.volume_snapshot_list_paged( IsA(http.HttpRequest), paginate=True, marker=None, sort_dir='desc', search_opts={'all_tenants': True},).AndReturn( [self.cinder_volume_snapshots.list(), False, False]) cinder.volume_list(IsA(http.HttpRequest), search_opts={ 'all_tenants': True}).\ AndReturn(self.cinder_volumes.list()) keystone.tenant_list(IsA(http.HttpRequest)). \ AndReturn([self.tenants.list(), False]) self.mox.ReplayAll() url = reverse('horizon:admin:volumes:snapshots_tab') res = self.client.get(urlunquote(url)) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'admin/volumes/index.html') snapshots = res.context['volume_snapshots_table'].data self.assertItemsEqual(snapshots, self.cinder_volume_snapshots.list())
def _test_snapshots_index_paginated(self, marker, sort_dir, snapshots, url, has_more, has_prev): cinder.volume_snapshot_list_paged( IsA(http.HttpRequest), paginate=True, marker=marker, sort_dir=sort_dir, search_opts={'all_tenants': True}) \ .AndReturn([snapshots, has_more, has_prev]) cinder.volume_list(IsA(http.HttpRequest), search_opts={ 'all_tenants': True}).\ AndReturn(self.cinder_volumes.list()) keystone.tenant_list(IsA(http.HttpRequest)) \ .AndReturn([self.tenants.list(), False]) self.mox.ReplayAll() res = self.client.get(urlunquote(url)) self.assertTemplateUsed(res, 'admin/volumes/index.html') self.assertEqual(res.status_code, 200) self.mox.UnsetStubs() return res
def assertRedirectsNoFollow(self, response, expected_url): """Check for redirect. Asserts that the given response issued a 302 redirect without processing the view which is redirected to. """ if django.VERSION >= (1, 9): loc = six.text_type(response._headers.get('location', None)[1]) loc = http.urlunquote(loc) expected_url = http.urlunquote(expected_url) self.assertEqual(loc, expected_url) else: self.assertEqual(response._headers.get('location', None), ('Location', settings.TESTSERVER + expected_url)) self.assertEqual(response.status_code, 302)
def article_type(request,article_type): cur_art_type = urlunquote(article_type) article_list = Article.objects.filter(art_type=cur_art_type) art_type_list = findtype() context = {'latest_art_list':article_list, 'art_type_list':art_type_list,'art_type':cur_art_type} return render(request, 'article/article_type.html', context)
def set_language(request): """ Redirect to a given url while setting the chosen language in the session or cookie. The url and the language code need to be specified in the request parameters. Since this view changes how the user will see the rest of the site, it must only be accessed as a POST request. If called as a GET request, it will redirect to the page in the request (the 'next' parameter) without changing any state. """ next = request.POST.get('next', request.GET.get('next')) if ((next or not request.is_ajax()) and not is_safe_url(url=next, allowed_hosts={request.get_host()}, require_https=request.is_secure())): next = request.META.get('HTTP_REFERER') if next: next = urlunquote(next) # HTTP_REFERER may be encoded. if not is_safe_url(url=next, allowed_hosts={request.get_host()}, require_https=request.is_secure()): next = '/' response = http.HttpResponseRedirect(next) if next else http.HttpResponse(status=204) if request.method == 'POST': lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER) if lang_code and check_for_language(lang_code): if next: next_trans = translate_url(next, lang_code) if next_trans != next: response = http.HttpResponseRedirect(next_trans) if hasattr(request, 'session'): request.session[LANGUAGE_SESSION_KEY] = lang_code else: response.set_cookie( settings.LANGUAGE_COOKIE_NAME, lang_code, max_age=settings.LANGUAGE_COOKIE_AGE, path=settings.LANGUAGE_COOKIE_PATH, domain=settings.LANGUAGE_COOKIE_DOMAIN, ) return response