add app settings
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 30 Nov 2012 11:44:55 +0000 (12:44 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 30 Nov 2012 11:44:55 +0000 (12:44 +0100)
fnpdjango/__init__.py
fnpdjango/deploy/templates/localsettings.py.template
fnpdjango/middleware.py
fnpdjango/utils/views.py
setup.py

index e69de29..17d547d 100644 (file)
@@ -0,0 +1,8 @@
+from .utils.app import AppSettings
+
+class Settings(AppSettings):
+    REALIP = False
+    XACCEL = False
+
+
+app_settings = Settings('FNPDJANGO')
index 551e00f..9e087fe 100644 (file)
@@ -22,3 +22,6 @@ PIWIK_TOKEN = ''
 
 MEDIA_ROOT = '%(app_path)s/media/'
 STATIC_ROOT = '%(app_path)s/static/'
+
+FNPDJANGO_REALIP = False
+FNPDJANGO_XACCEL = False
index 21de872..fcf4c36 100644 (file)
@@ -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):
index f2270cc..07f3905 100644 (file)
@@ -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
index 8e4f3bc..3dfd2e1 100755 (executable)
--- 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 = '',