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
Add support for django-jinja. #167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,22 +45,6 @@ | |
|
||
ROOT_URLCONF = 'test_app.urls' | ||
|
||
TEMPLATE_LOADERS = ( | ||
'jingo.Loader', | ||
'django.template.loaders.filesystem.Loader', | ||
'django.template.loaders.app_directories.Loader', | ||
) | ||
|
||
JINGO_EXCLUDE_APPS = ( | ||
'django', | ||
'waffle', | ||
) | ||
|
||
TEMPLATE_CONTEXT_PROCESSORS = ( | ||
'django.contrib.auth.context_processors.auth', | ||
'django.core.context_processors.request', | ||
) | ||
|
||
WAFFLE_FLAG_DEFAULT = False | ||
WAFFLE_SWITCH_DEFAULT = False | ||
WAFFLE_SAMPLE_DEFAULT = False | ||
|
@@ -73,3 +57,68 @@ | |
SOUTH_MIGRATION_MODULES = { | ||
'waffle': 'waffle.south_migrations' | ||
} | ||
|
||
if django.VERSION < (1,8): | ||
# Old style TEMPLATE_* settings. | ||
# Use jingo. | ||
|
||
TEMPLATE_LOADERS = ( | ||
'jingo.Loader', | ||
'django.template.loaders.filesystem.Loader', | ||
'django.template.loaders.app_directories.Loader', | ||
) | ||
|
||
TEMPLATE_CONTEXT_PROCESSORS = ( | ||
'django.contrib.auth.context_processors.auth', | ||
'django.core.context_processors.request', | ||
) | ||
|
||
JINGO_EXCLUDE_APPS = ( | ||
'django', | ||
'waffle', | ||
) | ||
|
||
else: | ||
# New style TEMPLATES setting. | ||
# Use django-jinja | ||
|
||
INSTALLED_APPS += ('django_jinja', ) | ||
|
||
TEMPLATES = [ | ||
# Configure the Jinja2 template engine | ||
{ | ||
'BACKEND': 'django_jinja.backend.Jinja2', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
"match_regex": r"jingo.*", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This uses " but should use '. |
||
'match_extension': '', | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need the |
||
], | ||
'extensions': [ | ||
'jinja2.ext.i18n', | ||
'jinja2.ext.autoescape', | ||
'jinja2.ext.with_', | ||
'jinja2.ext.do' | ||
] | ||
} | ||
}, | ||
# Configure the Django template engine | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ | |
# versions. | ||
mock==1.0.1 | ||
Jinja2>=2.7.1 | ||
jingo==0.7 | ||
South==0.8.3 | ||
django-discover-runner==1.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1 @@ | ||
import jingo | ||
import jinja2 | ||
|
||
from waffle import flag_is_active, sample_is_active, switch_is_active | ||
from waffle.views import _generate_waffle_js | ||
|
||
|
||
@jinja2.contextfunction | ||
def flag_helper(context, flag_name): | ||
return flag_is_active(context['request'], flag_name) | ||
|
||
|
||
@jinja2.contextfunction | ||
def inline_wafflejs_helper(context): | ||
return _generate_waffle_js(context['request']) | ||
|
||
|
||
jingo.env.globals['waffle'] = { | ||
'flag': flag_helper, | ||
'switch': switch_is_active, | ||
'sample': sample_is_active, | ||
'wafflejs': inline_wafflejs_helper | ||
} | ||
from waffle.templatetags import jinja_waffle_tags |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import jinja2 | ||
|
||
from waffle import flag_is_active, sample_is_active, switch_is_active | ||
from waffle.views import _generate_waffle_js | ||
|
||
|
||
@jinja2.contextfunction | ||
def flag_helper(context, flag_name): | ||
return flag_is_active(context['request'], flag_name) | ||
|
||
|
||
@jinja2.contextfunction | ||
def inline_wafflejs_helper(context): | ||
return _generate_waffle_js(context['request']) | ||
|
||
|
||
helpers = { | ||
'flag': flag_helper, | ||
'switch': switch_is_active, | ||
'sample': sample_is_active, | ||
'wafflejs': inline_wafflejs_helper | ||
} | ||
|
||
try: | ||
import jingo | ||
|
||
jingo.env.globals['waffle'] = helpers | ||
except ImportError: | ||
# jingo isn't being used. Move on. | ||
pass | ||
|
||
|
||
try: | ||
from django_jinja.library import global_function | ||
|
||
global_function('waffle', helpers) | ||
except ImportError: | ||
# django-jinja isn't being used. Move on. | ||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't think of a situation where both jingo and django-jinja would be available, but I think I'd change this to cascade. Something like this:
@jsocol Does that sound ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case here (running tests in travis), both jingo and django-jinja will be in the virtualenv. Unless I change things so they aren't. And even for sumo, we'd have to make sure the virtualenv gets destroyed once we change off of jingo. I don't think our deploys do that every time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmm... We should fix the test harness so we have separate "jingo" and "django-jinja" environments with different things installed. Otherwise we're mixing things and it's not clear what confidence of correctness our tests can give us. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SUMO problem should get solved in SUMO-land. There's a bug for this problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to make this more specific. Something like: