[PATCH 01/15] context: Add 'site' context processor
Stephen Finucane
stephen.finucane at intel.com
Fri Mar 25 04:52:46 AEDT 2016
This allows us to use the current "site" value in all templates without
requiring PatchworkRequestContext. As a custom context processor is
being enabled, the 'TEMPLATE_CONTEXT_PROCESSORS' value must be
specified for versions of Django < 1.8 (it's already specified for
other versions).
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/context_processors.py | 24 ++++++++++++++++++++++++
patchwork/requestcontext.py | 2 --
patchwork/settings/base.py | 11 +++++++++++
3 files changed, 35 insertions(+), 2 deletions(-)
create mode 100644 patchwork/context_processors.py
diff --git a/patchwork/context_processors.py b/patchwork/context_processors.py
new file mode 100644
index 0000000..8f1de9e
--- /dev/null
+++ b/patchwork/context_processors.py
@@ -0,0 +1,24 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Intel Corporation
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from django.contrib.sites.models import Site
+
+
+def site(request):
+ return {'site': Site.objects.get_current()}
diff --git a/patchwork/requestcontext.py b/patchwork/requestcontext.py
index ee26b9b..54307db 100644
--- a/patchwork/requestcontext.py
+++ b/patchwork/requestcontext.py
@@ -20,7 +20,6 @@
from __future__ import absolute_import
from django.conf import settings
-from django.contrib.sites.models import Site
from django.template import RequestContext
from patchwork.filters import Filters
@@ -74,7 +73,6 @@ class PatchworkRequestContext(RequestContext):
self.update({
'project': self.project,
- 'site': Site.objects.get_current(),
'settings': settings,
'other_projects': len(self.projects) > 1
})
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index ef2a9ee..1bdcff9 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -80,12 +80,23 @@ if django.VERSION >= (1, 8):
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
+ 'patchwork.context_processors.site',
],
},
},
]
else:
TEMPLATE_DIRS = _TEMPLATE_DIRS
+ TEMPLATE_CONTEXT_PROCESSORS = [
+ 'django.contrib.auth.context_processors.auth',
+ 'django.core.context_processors.debug',
+ 'django.core.context_processors.i18n',
+ 'django.core.context_processors.media',
+ 'django.core.context_processors.static',
+ 'django.core.context_processors.tz',
+ 'django.contrib.messages.context_processors.messages',
+ 'patchwork.context_processors.site',
+ ]
# Email
--
2.0.0
More information about the Patchwork
mailing list