def test_full_path_with_unicode_query_param_2(self):
     u = UrlHelper('/foo?foo=слово')
     u.update_query_data(bar='слово')
     self.assertEqual(
         u.get_full_path(),
         '/foo?foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE&bar=%D1%81'
         '%D0%BB%D0%BE%D0%B2%D0%BE')
示例#2
0
def get_comment_url(comment_pk=None, comment=None, request=None, include_anchor=True):
    if comment_pk:
        import comments
        comment = get_object_or_404(comments.get_model(), pk=comment_pk, site__pk=settings.SITE_ID)

    if comment is None:
        raise Exception('No comment supplied')

    top_level = get_top_level_comment(comment)
    target = top_level.content_object
    page = get_comment_page(target=target, comment=top_level, request=request)

    if target and isinstance(page, int):
        url = UrlHelper(target.get_absolute_url())

        if page <= 1:
            # Remove pager parameter as we want to go to the first page.
            url.del_params('page')
        else:
            # Update pager parameter
            url.update_query_data(page=page)

        full_url = url.get_full_path()
        if include_anchor:
            full_url += '#comment-%s' % comment._get_pk_val()

        return full_url
示例#3
0
def logout_url(url):
    url = UrlHelper(url)
    logout_kwarg = {LOGOUT: ''}
    try:
        url.update_query_data(**logout_kwarg)
        return url.get_full_path()
    except:
        return ''
示例#4
0
def pagination_link(page_obj, page, **kwargs):
    request_copy = copy(page_obj.request)
    if hasattr(request_copy, 'original_path'):
        request_copy.path = request_copy.original_path
    url = UrlHelper(request_copy.get_full_path())
    try:
        page = int(page)
        if page == 1:
            url.del_params('page', **kwargs)
        else:
            url.update_query_data(page=page, **kwargs)
        full_url = url.get_full_path()
        if page_obj.anchor:
            full_url += '#%s' % page_obj.anchor
        return full_url
    except:
        return ''
def pagination_link(page_obj, page, **kwargs):
    request_copy = copy(page_obj.request)
    if hasattr(request_copy, 'original_path'):
        request_copy.path = request_copy.original_path
    url = UrlHelper(request_copy.get_full_path())
    try:
        page = int(page)
        if page == 1:
            url.del_params('page', **kwargs)
        else:
            url.update_query_data(page=page, **kwargs)
        full_url = url.get_full_path()
        if page_obj.anchor:
            full_url += '#%s' % page_obj.anchor
        return full_url
    except:
        return ''
 def test_toggle_params_disable_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово')
     u.toggle_params(foo='слово')
     self.assertEqual(u.get_full_path(), '/foo/bar')
 def test_overload_param_unicode(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.overload_params(foo='слово')
     self.assertEqual(
         u.get_full_path(), '/foo/bar?foo=1&foo=%D1%81%D0%BB'
         '%D0%BE%D0%B2%D0%BE')
 def test_delete_multiple_without_arguments(self):
     u = UrlHelper('/foo/bar?foo=1&bar=2')
     u.del_params()
     self.assertEqual(u.get_full_path(), '/foo/bar')
 def test_delete_multiple_keys_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово&bar=2')
     u.del_params('foo', 'bar')
     self.assertEqual(u.get_full_path(), '/foo/bar')
 def test_use_with_URL_as_param_value_unicode(self):
     u = UrlHelper('/foo/bar/')
     u.query = {'redir': '/foo/bar/baz?test=слово'}
     self.assertEqual(
         u.get_full_path(), '/foo/bar/?redir=%2Ffoo%2Fbar%2Fbaz%3Ftest%3D'
         '%D1%81%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_retains_fragment_unicode(self):
     u = UrlHelper('/foo#bar')
     u.update_query_data(foo='слово')
     self.assertEqual(u.get_full_path(),
                      '/foo?foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE#bar')
 def test_retains_fragment_unicode(self):
     u = UrlHelper('/foo#bar')
     u.update_query_data(foo='слово')
     self.assertEqual(u.get_full_path(),
                      '/foo?foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE#bar')
 def test_overload_param(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.overload_params(foo=2)
     self.assertEqual(u.get_full_path(), '/foo/bar?foo=1&foo=2')
 def test_delete_multiple_without_arguments(self):
     u = UrlHelper('/foo/bar?foo=1&bar=2')
     u.del_params()
     self.assertEqual(u.get_full_path(), '/foo/bar')
 def test_delete_fails_silently_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово&bar=2')
     u.del_params('foo', 'baz')  # baz doesn't exist
     self.assertEqual(u.get_full_path(), '/foo/bar?bar=2')
 def test_delete_multiple_keys_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово&bar=2')
     u.del_params('foo', 'bar')
     self.assertEqual(u.get_full_path(), '/foo/bar')
 def test_delete_key(self):
     u = UrlHelper('/foo/bar?foo=1&bar=2')
     u.del_param('foo')
     self.assertEqual(u.get_full_path(), '/foo/bar?bar=2')
 def test_use_with_URL_as_param_value_unicode(self):
     u = UrlHelper('/foo/bar/')
     u.query = {'redir': '/foo/bar/baz?test=слово'}
     self.assertEqual(u.get_full_path(),
                      '/foo/bar/?redir=%2Ffoo%2Fbar%2Fbaz%3Ftest%3D'
                      '%D1%81%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_use_with_URL_as_param_value(self):
     u = UrlHelper('/foo/bar/')
     u.query = {'redir': '/foo/bar/baz?test=1'}
     self.assertEqual(u.get_full_path(),
                      '/foo/bar/?redir=%2Ffoo%2Fbar%2Fbaz%3Ftest%3D1')
 def test_toggle_params_enable_unicode(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.toggle_params(bar='слово')
     self.assertEqual(
         u.get_full_path(), '/foo/bar?foo=1&bar='
         '%D1%81%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_overload_param_unicode(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.overload_params(foo='слово')
     self.assertEqual(u.get_full_path(), '/foo/bar?foo=1&foo=%D1%81%D0%BB'
                      '%D0%BE%D0%B2%D0%BE')
 def test_url_helper_instance_as_argument(self):
     u1 = UrlHelper('/foo/bar?foo=1&bar=2')
     u2 = UrlHelper(u1)
     self.assertEqual(u2.get_full_path(), '/foo/bar?foo=1&bar=2')
 def test_retains_fragment(self):
     u = UrlHelper('/foo#bar')
     u.update_query_data(foo=1)
     self.assertEqual(u.get_full_path(), '/foo?foo=1#bar')
 def test_toggle_params_disable_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово')
     u.toggle_params(foo='слово')
     self.assertEqual(u.get_full_path(), '/foo/bar')
 def test_use_with_URL_as_param_value(self):
     u = UrlHelper('/foo/bar/')
     u.query = {'redir': '/foo/bar/baz?test=1'}
     self.assertEqual(u.get_full_path(),
                      '/foo/bar/?redir=%2Ffoo%2Fbar%2Fbaz%3Ftest%3D1')
 def test_toggle_params_enable(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.toggle_params(bar=1)
     self.assertEqual(u.get_full_path(), '/foo/bar?foo=1&bar=1')
 def test_delete_key(self):
     u = UrlHelper('/foo/bar?foo=1&bar=2')
     u.del_param('foo')
     self.assertEqual(u.get_full_path(), '/foo/bar?bar=2')
 def test_toggle_params_enable_unicode(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.toggle_params(bar='слово')
     self.assertEqual(u.get_full_path(), '/foo/bar?foo=1&bar='
                      '%D1%81%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_delete_fails_silently_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово&bar=2')
     u.del_params('foo', 'baz')  # baz doesn't exist
     self.assertEqual(u.get_full_path(), '/foo/bar?bar=2')
 def test_toggle_params_toggle_multiple_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово')
     u.toggle_params(foo='слово', bar=1)
     self.assertEqual(u.get_full_path(), '/foo/bar?bar=1')
 def test_overload_param(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.overload_params(foo=2)
     self.assertEqual(u.get_full_path(), '/foo/bar?foo=1&foo=2')
 def test_full_path_with_unicode_query_param_2(self):
     u = UrlHelper('/foo?foo=слово')
     u.update_query_data(bar='слово')
     self.assertEqual(u.get_full_path(),
                      '/foo?foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE&bar=%D1%81'
                      '%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_url_helper_instance_as_argument(self):
     u1 = UrlHelper('/foo/bar?foo=1&bar=2')
     u2 = UrlHelper(u1)
     self.assertEqual(u2.get_full_path(), '/foo/bar?foo=1&bar=2')
 def test_get_full_path_with_no_querystring(self):
     u = UrlHelper('/foo')
     self.assertEqual(u.get_full_path(), '/foo')
 def test_toggle_params_enable(self):
     u = UrlHelper('/foo/bar?foo=1')
     u.toggle_params(bar=1)
     self.assertEqual(u.get_full_path(), '/foo/bar?foo=1&bar=1')
 def test_get_full_path(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=1)
     self.assertEqual(u.get_full_path(), '/foo?foo=1')
 def test_toggle_params_toggle_multiple_unicode(self):
     u = UrlHelper('/foo/bar?foo=слово')
     u.toggle_params(foo='слово', bar=1)
     self.assertEqual(u.get_full_path(), '/foo/bar?bar=1')
 def test_get_full_path(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=1)
     self.assertEqual(u.get_full_path(), '/foo?foo=1')
 def test_get_full_path_with_no_querystring(self):
     u = UrlHelper('/foo')
     self.assertEqual(u.get_full_path(), '/foo')
 def test_retains_fragment(self):
     u = UrlHelper('/foo#bar')
     u.update_query_data(foo=1)
     self.assertEqual(u.get_full_path(), '/foo?foo=1#bar')