From: Stephen Finucane Date: Mon, 21 Mar 2016 14:07:01 +0000 (+0000) Subject: context: Add 'site' context processor X-Git-Tag: v2.0.0-rc1~406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85cf2b8d09480a7bdc88bc1ebb2954f862c0f8b8;p=thirdparty%2Fpatchwork.git context: Add 'site' context processor 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 Tested-by: Andy Doan --- diff --git a/patchwork/context_processors.py b/patchwork/context_processors.py new file mode 100644 index 00000000..8f1de9e0 --- /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 ee26b9ba..54307dba 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 ef2a9ee8..1bdcff99 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