Commits

Carl Meyer committed 871bcbc

Allowed LOCALE_INDEPENDENT_PATHS to be regex strings, not only compiled regex objects. Fixes #9.

Comments (0)

Files changed (4)

 ---------
 
 Tip: (unreleased)
+  * ``LOCALE_INDEPENDENT_PATHS`` can now be plain string regular expressions,
+    they don't have to be compiled regex objects. Fixes #9.
   * Added import of ``localeurl.models`` to ``localeurl.middleware``, to ensure
     that ``reverse`` is monkeypatched before any requests are
     served. Fixes #5. Thanks Antti Kaihola for the report, Andrey Shipilov and
 file.
 
 ``LOCALE_INDEPENDENT_PATHS``
-  A tuple of regular expression objects matching paths that will not be
-  redirected to add the language prefix. For example, a site with a language
-  selection splash page would add ``'^/$'`` as a locale independent path match.
-  Note that for performance reasons you must use ``re`` objects, not strings.
+  A tuple of regular expressions matching paths that will not be redirected to
+  add the language prefix. For example, a site with a language selection splash
+  page would add ``'^/$'`` as a locale independent path match.
 
-Example::
+  Example::
 
-  import re
-  LOCALE_INDEPENDENT_PATHS = (
-      re.compile('^/$'),
-      re.compile('^/games/'),
-      re.compile('^/ajax/'),
-  )
+    LOCALE_INDEPENDENT_PATHS = (
+        r'^/$',
+        r'^/games/',
+        r'^/ajax/',
+    )
 
 ``LOCALE_INDEPENDENT_MEDIA_URL`` (default: ``True``)
   Whether paths starting with ``settings.MEDIA_URL`` (if it is a path, i.e. not

localeurl/settings.py

     sorted(SUPPORTED_LOCALES.keys(), key=lambda i: len(i), reverse=True))
 PATH_RE = re.compile(r'^/(?P<locale>%s)(?P<path>.*)$' % LOCALES_RE)
 
-LOCALE_INDEPENDENT_PATHS = getattr(settings, 'LOCALE_INDEPENDENT_PATHS', ())
+LOCALE_INDEPENDENT_PATHS = [re.compile(p) for p in
+                            getattr(settings, 'LOCALE_INDEPENDENT_PATHS', [])]
 
 LOCALE_INDEPENDENT_MEDIA_URL = getattr(settings,
         'LOCALE_INDEPENDENT_MEDIA_URL', True)

localeurl/tests/tests.py

         LANGUAGE_CODE = 'en-gb',
         LOCALE_INDEPENDENT_PATHS = (
             re.compile('^/$'),
-            re.compile('^/test/independent/'),
+            '^/test/independent/',
         ),
         LOCALE_INDEPENDENT_MEDIA_URL = True,
         MEDIA_URL = '/media/',