Skip to content

Commit

Permalink
3.4: context_processors.settings_constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilhem Saurel committed Mar 31, 2018
1 parent 8df5c8a commit 83a5ae5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ndh/context_processors.py
@@ -0,0 +1,7 @@
from django.conf import settings


def settings_constants(request):
if hasattr(settings, 'NDH_TEMPLATES_SETTINGS'):
return {key: getattr(settings, key) for key in settings.NDH_TEMPLATES_SETTINGS}
return {}
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -16,7 +16,7 @@

setup(
name='ndh',
version='3.3.0',
version='3.4.0',
packages=['ndh'],
install_requires=REQUIREMENTS,
include_package_data=True,
Expand Down
1 change: 1 addition & 0 deletions testapp/templates/testapp/settings.html
@@ -0,0 +1 @@
{{ TIME_ZONE }}
5 changes: 5 additions & 0 deletions testapp/tests.py
Expand Up @@ -123,3 +123,8 @@ def test_utils(self):
lines = f.readlines()
with open(env_file, 'w') as f:
f.write('\n'.join(line for line in lines if not line.startswith(key) and not line.startswith(no_key)))

def test_context_processors(self):
self.assertNotIn('UTC', self.client.get(reverse('testapp:settings')).content.decode())
with self.settings(NDH_TEMPLATES_SETTINGS=['TIME_ZONE']):
self.assertIn('UTC', self.client.get(reverse('testapp:settings')).content.decode())
7 changes: 4 additions & 3 deletions testapp/urls.py
@@ -1,5 +1,5 @@
from django.urls import path
from django.views.generic import DetailView, ListView
from django.views.generic import DetailView, ListView, TemplateView

from . import views
from .models import TestModel, TestModelList, TestModelPK
Expand All @@ -10,8 +10,9 @@
urlpatterns = [
path('', ListView.as_view(model=TestModel), name='testmodels'),
path('create', views.TestCreateView.as_view(), name='testmodel-add'),
path('<slug:slug>', DetailView.as_view(model=TestModel), name='testmodel'),
path('<slug:slug>/delete', views.TestDeleteView.as_view(), name='testmodel-del'),
path('list', ListView.as_view(model=TestModelList), name='testmodellists'),
path('pk/<int:pk>', DetailView.as_view(model=TestModelPK), name='testmodelpk'),
path('settings', TemplateView.as_view(template_name='testapp/settings.html'), name='settings'),
path('<slug:slug>', DetailView.as_view(model=TestModel), name='testmodel'),
path('<slug:slug>/delete', views.TestDeleteView.as_view(), name='testmodel-del'),
]
1 change: 1 addition & 0 deletions testproject/settings.py
Expand Up @@ -67,6 +67,7 @@
'django.template.context_processors.i18n',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'ndh.context_processors.settings_constants',
],
},
},
Expand Down

0 comments on commit 83a5ae5

Please sign in to comment.