示例#1
0
 def test_with_query_params_in_url_unicode(self):
     # FIXME: This breaks. See issue #4
     # https://bitbucket.org/monwara/django-url-tools/issue/4/
     u = UrlHelper('/foo')
     u.update_query_data(redir='/foo/bar/?q=два+слова')
     self.assertEqual(u.get_query_string(safe='/'),
                      'redir=/foo/bar/%3Fq%3D%D0%B4%D0%B2%D0%B0%2B%D1%81%D0%BB%D0')
示例#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
 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_with_query_params_in_url_unicode(self):
     # FIXME: This breaks. See issue #4
     # https://bitbucket.org/monwara/django-url-tools/issue/4/
     u = UrlHelper('/foo')
     u.update_query_data(redir='/foo/bar/?q=два+слова')
     self.assertEqual(u.get_query_string(safe='/'),
                      'redir=/foo/bar/%3Fq%3D%D0%B4%D0%B2%D0%B0%2B%D1%81%D0%BB%D0')
 def test_update_query_data_with_correct_escaping_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='два слова!')
     self.assertEqual(
         u.query_string,
         'foo=%D0%B4%D0%B2%D0%B0+%D1%81%D0%BB%D0%BE%D0%B2%D0%B'
         '0%21&bar=2')
示例#6
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 ''
示例#7
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_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_update_query_data(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo=2)
     self.assertEqual(u.get_query_data()['foo'], 2)
 def test_update_query_data_with_correct_escaping(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='space here!')
     self.assertEqual(u.query_string, u'foo=space+here%21&bar=2')
 def test_get_query_with_multiple_values(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=[1, 2, 3])
     self.assertEqual(u.get_query_string(), 'foo=1&foo=2&foo=3')
 def test_get_query_string_after_modification(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo=2)
     self.assertEqual(u.get_query_string(), 'foo=2&bar=2')
 def test_update_query_data_with_correct_escaping(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='space here!')
     self.assertEqual(u.query_string, 'foo=space+here%21&bar=2')
 def test_update_query_data_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='слово')
     self.assertEqual(u.get_query_data()['foo'], 'слово')
 def test_safe_slash_argument(self):
     u = UrlHelper('/foo')
     u.update_query_data(redir='/foo/bar/')
     self.assertEqual(u.get_query_string(safe='/'), 'redir=/foo/bar/')
 def test_get_query_with_multiple_values_unicode(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=[1, 2, 'слово'])
     self.assertEqual(u.get_query_string(),
                      'foo=1&foo=2&foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_get_query_with_multiple_values(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=[1, 2, 3])
     self.assertEqual(u.get_query_string(), 'foo=1&foo=2&foo=3')
 def test_get_query_string_after_modification_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='слово')
     self.assertEqual(u.get_query_string(),
                      'foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE&bar=2')
 def test_get_query_string_after_modification(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo=2)
     self.assertEqual(u.get_query_string(), 'foo=2&bar=2')
 def test_update_query_data_with_correct_escaping_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='два слова!')
     self.assertEqual(u.query_string,
                      'foo=%D0%B4%D0%B2%D0%B0+%D1%81%D0%BB%D0%BE%D0%B2%D0%B'
                      '0%21&bar=2')
 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_update_query_data(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo=2)
     self.assertEqual(u.get_query_data()['foo'], 2)
 def test_with_query_params_in_url(self):
     u = UrlHelper('/foo')
     u.update_query_data(redir='/foo/bar/?q=Mickey+Mouse')
     self.assertEqual(u.get_query_string(safe='/'),
                      'redir=/foo/bar/%3Fq%3DMickey%2BMouse')
 def test_update_query_data_with_multiple_values_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo=[1, 2, 'слово'])
     self.assertEqual(u.get_query_data()['foo'], 'слово')
     self.assertEqual(u.get_query_data().getlist('foo'), [1, 2, 'слово'])
 def test_update_query_data_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='слово')
     self.assertEqual(u.get_query_data()['foo'], 'слово')
 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_safe_slash_argument(self):
     u = UrlHelper('/foo')
     u.update_query_data(redir='/foo/bar/')
     self.assertEqual(u.get_query_string(safe='/'), 'redir=/foo/bar/')
 def test_get_query_string_after_modification_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo='слово')
     self.assertEqual(u.get_query_string(),
                      'foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE&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_get_query_with_multiple_values_unicode(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=[1, 2, 'слово'])
     self.assertEqual(u.get_query_string(),
                      'foo=1&foo=2&foo=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE')
 def test_update_query_data_with_multiple_values_unicode(self):
     u = UrlHelper('/foo?foo=1&bar=2')
     u.update_query_data(foo=[1, 2, 'слово'])
     self.assertEqual(u.get_query_data()['foo'], 'слово')
     self.assertEqual(u.get_query_data().getlist('foo'), [1, 2, 'слово'])
 def test_with_query_params_in_url(self):
     u = UrlHelper('/foo')
     u.update_query_data(redir='/foo/bar/?q=Mickey+Mouse')
     self.assertEqual(u.get_query_string(safe='/'),
                      'redir=/foo/bar/%3Fq%3DMickey%2BMouse')
 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(self):
     u = UrlHelper('/foo')
     u.update_query_data(foo=1)
     self.assertEqual(u.get_full_path(), '/foo?foo=1')
 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')