Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Django 1.10 #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
228 changes: 228 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
##################################################################
# Original .gitignore file
.idea/

##################################################################
# https://github.com/github/gitignore/blob/master/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
fabfile/*.pyc

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
nikkei/local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
env.d/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/


############################################################################
# https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties


########################################################################
# https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


##########################################################################
# https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
10 changes: 5 additions & 5 deletions localeurl/templatetags/localeurl_tags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django import template
from django.template import Node, Token, TemplateSyntaxError
from django.template import resolve_variable
from django.template.base import Node, Token, TemplateSyntaxError
from django.template import Variable
from django.template.defaultfilters import stringfilter
from django.templatetags import future
from django.template.defaulttags import url

from localeurl import utils

Expand Down Expand Up @@ -52,7 +52,7 @@ def locale_url(parser, token):
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 = future.url(parser, urltoken)
urlnode = url(parser, urltoken)
return LocaleURLNode(bits[1], urlnode)


Expand All @@ -62,7 +62,7 @@ def __init__(self, locale, urlnode):
self.urlnode = urlnode

def render(self, context):
locale = resolve_variable(self.locale, context)
locale = Variable(self.locale).resolve(context)
if utils.supported_language(locale) is None:
raise ValueError("locale not in settings.LANGUAGES: %s" % locale)
path = self.urlnode.render(context)
Expand Down
17 changes: 9 additions & 8 deletions localeurl/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
URLconf for testing.
"""
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'),
url(r'^dummy/(?P<test>.+)$', 'dummy', name='dummy1'),
)
from django.conf.urls import url


def dummy(request, test='test'):
pass


urlpatterns = [
url(r'^dummy/$', dummy, name='dummy0'),
url(r'^dummy/(?P<test>.+)$', dummy, name='dummy1'),
]

10 changes: 6 additions & 4 deletions localeurl/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django import template
from django.test import Client
from django.utils import encoding
from django.template.base import Lexer, Parser
from django.template.engine import Engine


NO_SETTING = object()
Expand Down Expand Up @@ -131,8 +133,7 @@ class TestTemplate(template.Template):
Based on the work by Alexander Khodyrev:
http://www.djangosnippets.org/snippets/1641/
"""
def __init__(self, template_string, name='<Unknown Template>',
libraries=[]):
def __init__(self, template_string, name='<Unknown Template>', libraries=[]):
try:
template_string = encoding.smart_unicode(template_string)
except UnicodeDecodeError:
Expand All @@ -141,12 +142,13 @@ def __init__(self, template_string, name='<Unknown Template>',
origin = template.StringOrigin(template_string)
self.nodelist = self.my_compile_string(template_string, origin,
libraries)
self.engine = Engine()
self.name = name

def my_compile_string(self, template_string, origin, libraries=[]):
"Compiles template_string into NodeList ready for rendering"
lexer = template.Lexer(template_string, origin)
parser = template.Parser(lexer.tokenize())
lexer = Lexer(template_string)
parser = Parser(lexer.tokenize())
for lib in libraries:
parser.add_library(lib)
return parser.parse()
11 changes: 11 additions & 0 deletions localeurl/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ class ViewsTestCase(LocaleurlTestCase):
def setUp(self):
super(LocaleurlTestCase, self).setUp()
self.settings_manager = test_utils.TestSettingsManager()
self.settings_manager.set(ROOT_URLCONF=self.urls)
self.settings_manager.set(MIDDLEWARE=(
'django.contrib.sessions.middleware.SessionMiddleware',
)
)

def test_change_locale_check_session_enabled(self):
self.settings_manager.set(LOCALEURL_USE_SESSION=True)
Expand All @@ -469,3 +474,9 @@ def test_change_locale_check_session_disabled(self):
def test_change_without_next(self):
response = self.client.post('/change/', data={'locale': 'de'})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/de/')

def test_change_with_next(self):
response = self.client.post('/change/', data={'locale': 'de', 'next': '/foo'})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/de/foo')
11 changes: 5 additions & 6 deletions localeurl/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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('',
url(r'^change/', change_locale, name='localeurl_change_locale'),

from django.conf.urls import url

urlpatterns = (
url(r'^change/', change_locale, name='localeurl_change_locale'),
)
2 changes: 1 addition & 1 deletion localeurl/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def change_locale(request):
The url and the locale code need to be specified in the
request parameters.
"""
next = request.REQUEST.get('next', None)
next = request.POST.get('next', None)
if not next:
referrer = request.META.get('HTTP_REFERER', None)
if referrer:
Expand Down