From: Radek Czajka Date: Fri, 30 Nov 2012 11:44:55 +0000 (+0100) Subject: add app settings X-Git-Tag: 0.1.5~8 X-Git-Url: https://git.mdrn.pl/fnpdjango.git/commitdiff_plain/3db2da0f3aecda70b20c05bcde42e30353dceb05?ds=sidebyside add app settings --- diff --git a/fnpdjango/__init__.py b/fnpdjango/__init__.py index e69de29..17d547d 100644 --- a/fnpdjango/__init__.py +++ b/fnpdjango/__init__.py @@ -0,0 +1,8 @@ +from .utils.app import AppSettings + +class Settings(AppSettings): + REALIP = False + XACCEL = False + + +app_settings = Settings('FNPDJANGO') diff --git a/fnpdjango/deploy/templates/localsettings.py.template b/fnpdjango/deploy/templates/localsettings.py.template index 551e00f..9e087fe 100644 --- a/fnpdjango/deploy/templates/localsettings.py.template +++ b/fnpdjango/deploy/templates/localsettings.py.template @@ -22,3 +22,6 @@ PIWIK_TOKEN = '' MEDIA_ROOT = '%(app_path)s/media/' STATIC_ROOT = '%(app_path)s/static/' + +FNPDJANGO_REALIP = False +FNPDJANGO_XACCEL = False diff --git a/fnpdjango/middleware.py b/fnpdjango/middleware.py index 21de872..fcf4c36 100644 --- a/fnpdjango/middleware.py +++ b/fnpdjango/middleware.py @@ -1,15 +1,18 @@ from django.utils import translation from django.conf import settings from django.http import Http404 +from . import app_settings class SetRemoteAddrFromXRealIP(object): """Sets REMOTE_ADDR from the X-Real-IP header, as set by Nginx.""" def process_request(self, request): - try: - request.META['REMOTE_ADDR'] = request.META['HTTP_X_REAL_IP'] - except KeyError: - return None + if app_settings.REALIP: + try: + request.META['REMOTE_ADDR'] = request.META['HTTP_X_REAL_IP'] + except KeyError: + pass + return None class URLLocaleMiddleware(object): diff --git a/fnpdjango/utils/views.py b/fnpdjango/utils/views.py index f2270cc..07f3905 100644 --- a/fnpdjango/utils/views.py +++ b/fnpdjango/utils/views.py @@ -2,13 +2,13 @@ View-specific utilities. """ -from django.conf import settings +from .. import app_settings from django.http import HttpResponse, HttpResponseRedirect def serve_file(url): """Serves an URL either though Nginx's X-accel, or by redirection.""" - if settings.X_ACCEL_REDIRECT: + if app_settings.XACCEL: response = HttpResponse() response['Content-Type'] = "" response['X-Accel-Redirect'] = url diff --git a/setup.py b/setup.py index 8e4f3bc..3dfd2e1 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def whole_trees(package_dir, paths): setup( name='fnpdjango', - version='0.1.1', + version='0.1.2', author='Radek Czajka', author_email='radoslaw.czajka@nowoczesnapolska.org.pl', url = '',