Commits

Carl Meyer committed 764caf7

Update for newer Django versions; drop support for Django 1.1 and 1.2.

Comments (2)

  1. Artur Barseghyan

    Hello Carl,

    It looks like this commit works quite well. Considering the fact, that locale stored in session is quite an important issue solved, is it not really a time for a (even a minor) version update on the PyPI?

    Best regards,

    Artur

Files changed (7)

 ---------
 
 Tip: (unreleased)
+  * Deprecate ``localeurl_future`` tag library, always use new url tag syntax.
+  * Try importing ``patterns, url`` first from ``django.conf.urls``; use
+    ``django.conf.urls.defaults`` only as Django 1.3 fallback. Fixes #36.
+  * Drop support for Django 1.1 and 1.2.
   * Don't try to parse referrer if not present. Fixes #33. Thanks Simon Luijk.
-  * Added support for a session-stored locale fallback. Thanks Sylvain
-    Fourmanoit for report and draft patch, and Alex Marandon for adding
-    tests. Fixes #23.
-  * Made language-code matching case-insensitive, per RFC. Thanks torgeilo for
+  * Add support for a session-stored locale fallback. Thanks Sylvain Fourmanoit
+    for report and draft patch, and Alex Marandon for adding tests. Fixes #23.
+  * Make language-code matching case-insensitive, per RFC. Thanks torgeilo for
     the report. Fixes #32.
-  * Dropped support for Django 1.0 and Python 2.4.
-  * Fixed issue with non-ASCII characters in URLs. Thanks Chris Adams.
+  * Drop support for Django 1.0 and Python 2.4.
+  * Fix issue with non-ASCII characters in URLs. Thanks Chris Adams.
 
 Release 1.5: (2011-08-24)
   * Added ``LOCALE_REDIRECT_PERMANENT`` setting; defaults to True, if set to

localeurl/templatetags/localeurl_future.py

+import warnings
+
+warnings.warn(
+    "The localeurl_future templatetag library is deprecated; "
+    "use localeurl_tags instead.",
+    DeprecationWarning
+    )
+
 from django import template
-from django.templatetags.future import url
-from django.utils.functional import wraps
 
 from localeurl_tags import locale_url
 
 register = template.Library()
 
 
-def locale_url_wrapper(parser, token):
-    return locale_url(parser, token, django_url_tag=url)
-
-
-locale_url_wrapper = wraps(locale_url)(locale_url_wrapper)
-
-
-
-register.tag('locale_url', locale_url_wrapper)
+register.tag('locale_url', locale_url)

localeurl/templatetags/localeurl_tags.py

 from django import template
 from django.template import Node, Token, TemplateSyntaxError
-from django.template import resolve_variable, defaulttags
+from django.template import resolve_variable
 from django.template.defaultfilters import stringfilter
-from django.utils.functional import wraps
+from django.templatetags import future
 
 from localeurl import utils
 
 
 
 
-def locale_url(parser, token, django_url_tag):
+def locale_url(parser, token):
     """
     Renders the url for the view with another locale prefix. The syntax is
     like the 'url' tag, only with a locale before the view.
         raise TemplateSyntaxError("'%s' takes at least two arguments:"
                 " the locale and a view" % bits[0])
     urltoken = Token(token.token_type, bits[0] + ' ' + ' '.join(bits[2:]))
-    urlnode = django_url_tag(parser, urltoken)
+    urlnode = future.url(parser, urltoken)
     return LocaleURLNode(bits[1], urlnode)
 
 
             return chlocale(path, locale)
 
 
-
-def locale_url_wrapper(parser, token):
-    return locale_url(parser, token, django_url_tag=defaulttags.url)
-
-
-locale_url_wrapper = wraps(locale_url)(locale_url_wrapper)
-
-
-
-register.tag('locale_url', locale_url_wrapper)
+register.tag('locale_url', locale_url)

localeurl/tests/test_urls.py

 """
 URLconf for testing.
 """
-
-from django.conf.urls.defaults import *
+try:
+    from django.conf.urls import patterns, url
+except ImportError:
+    from django.conf.urls.defaults import patterns, url
 
 urlpatterns = patterns('localeurl.tests.test_urls',
      url(r'^dummy/$', 'dummy', name='dummy0'),

localeurl/tests/tests.py

 
     def test_locale_url_tag(self):
         self.assertRaises(ValueError, self.render_template,
-                '{% locale_url "nl" dummy0 %}')
+                '{% locale_url "nl" "dummy0" %}')
 
         self.assertEqual('/en/dummy/', self.render_template(
-                '{% locale_url "en-us" dummy0 %}'))
+                '{% locale_url "en-us" "dummy0" %}'))
 
         self.assertEqual('/fr/dummy/4', self.render_template(
-            '{% locale_url "fr" dummy1 test=4 %}'))
+            '{% locale_url "fr" "dummy1" test=4 %}'))
 
         self.assertEqual('/en/dummy/4', self.render_template(
-            '{% locale_url "en" dummy1 test=4 as testvar %}{{ testvar }}'))
+            '{% locale_url "en" "dummy1" test=4 as testvar %}{{ testvar }}'))
 
 
     def test_chlocale_filter(self):
         reload(localeurl_settings)
 
         self.assertEqual('/dummy/', self.render_template(
-                '{% locale_url "en-us" dummy0 %}'))
+                '{% locale_url "en-us" "dummy0" %}'))
 
         self.assertEqual('/fr/dummy/', self.render_template(
-            '{% locale_url "fr" dummy0 %}'))
+            '{% locale_url "fr" "dummy0" %}'))
 
 
     def test_chlocale_filter_no_default_prefix(self):
         self.assertEqual('/fr/dummy/', self.render_template(
                 '{{"/nl-nl/dummy/"|chlocale:"fr"}}'))
 
-try:
-    from localeurl.templatetags import localeurl_future
-except ImportError:
-    localeurl_future = None
-
-
-# @@@ use proper test skipping once Django 1.2 is minimum version
-if localeurl_future is not None:
-    class FutureTagsTestCase(LocaleurlTestCase):
-        def render_template(self, text):
-            t = test_utils.TestTemplate(text, libraries=[localeurl_future.register])
-            c = template.Context()
-            return t.render(c)
-
-
-        def test_locale_url_tag(self):
-            self.assertRaises(ValueError, self.render_template,
-                    '{% locale_url "nl" "dummy0" %}')
-
-            self.assertEqual('/en/dummy/', self.render_template(
-                    '{% locale_url "en-us" "dummy0" %}'))
-
-            self.assertEqual('/fr/dummy/4', self.render_template(
-                '{% locale_url "fr" "dummy1" test=4 %}'))
-
-            self.assertEqual('/en/dummy/4', self.render_template(
-                '{% locale_url "en" "dummy1" test=4 as testvar %}{{ testvar }}'))
-
-
-        def test_locale_url_tag_no_default_prefix(self):
-            self.settings_manager.set(PREFIX_DEFAULT_LOCALE=False)
-            reload(localeurl_settings)
-
-            self.assertEqual('/dummy/', self.render_template(
-                    '{% locale_url "en-us" "dummy0" %}'))
-
-            self.assertEqual('/fr/dummy/', self.render_template(
-                '{% locale_url "fr" "dummy0" %}'))
-
 
 
 class DummyModel(object):

localeurl/urls.py

-from django.conf.urls.defaults import *
+try:
+    from django.conf.urls import patterns, url
+except ImportError:
+    from django.conf.urls.defaults import patterns, url
 from localeurl.views import change_locale
 
 urlpatterns = patterns('',
 [tox]
-envlist=py25-1.1,py25-1.2,py25,py25-trunk,py26-1.1,py26-1.2,py26,py26-trunk,py27-1.1,py27-1.2,py27,py27-trunk
+envlist=py25-1.3,py25-1.4,py26-1.3,py26-1.4,py26,py26-trunk,py27-1.3,py27-1.4,py27,py27-trunk
 
 [testenv]
 deps=
-  django==1.3.1
+  django==1.5.1
 commands=python setup.py test
 
 [testenv:py25-1.1]
 deps=
   django==1.2.7
 
-[testenv:py25-trunk]
+[testenv:py25-1.3]
 basepython=python2.5
 deps=
-  https://github.com/django/django/tarball/master
+  django==1.3.7
+
+[testenv:py25-1.4]
+basepython=python2.5
+deps=
+  django==1.4.5
 
 [testenv:py26-1.1]
 basepython=python2.6
 deps=
   django==1.2.7
 
+[testenv:py26-1.3]
+basepython=python2.6
+deps=
+  django==1.3.7
+
+[testenv:py26-1.4]
+basepython=python2.6
+deps=
+  django==1.4.5
+
 [testenv:py26-trunk]
 basepython=python2.6
 deps=
 deps=
   django==1.2.7
 
+[testenv:py27-1.3]
+basepython=python2.7
+deps=
+  django==1.3.7
+
+[testenv:py27-1.4]
+basepython=python2.7
+deps=
+  django==1.4.5
+
 [testenv:py27-trunk]
 basepython=python2.7
 deps=
   https://github.com/django/django/tarball/master
-