diff --git a/appsettings/admin.py b/appsettings/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/appsettings/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/appsettings/context_processors.py b/appsettings/context_processors.py new file mode 100644 index 0000000..5991630 --- /dev/null +++ b/appsettings/context_processors.py @@ -0,0 +1,13 @@ +from .settings import app_settings as settings + + +def app_settings(request): + """ + Simple context processor that puts the config into every\ + RequestContext. Just make sure you have a setting like this:: + TEMPLATE_CONTEXT_PROCESSORS = ( + # ... + 'appsettings.context_processors.app_settings', + ) + """ + return {"app_settings": settings} diff --git a/appsettings/middleware.py b/appsettings/middleware.py new file mode 100644 index 0000000..737477d --- /dev/null +++ b/appsettings/middleware.py @@ -0,0 +1,10 @@ +from .settings import app_settings, get_settings + + +class AppSettingsMiddleware(object): + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + get_settings() + return self.get_response(request) diff --git a/appsettings/settings.py b/appsettings/settings.py new file mode 100644 index 0000000..2c8a7f5 --- /dev/null +++ b/appsettings/settings.py @@ -0,0 +1,18 @@ +from .models import AppSettings + + +class Settings(object): + pass + + +app_settings = Settings() + + +def get_settings(): + try: + entries = AppSettings.objects.all() + except: + pass + + for entry in entries: + setattr(app_settings, entry.key, entry.val) diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index 44eabc8..f12e57b 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -50,6 +50,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.RemoteUserMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'appsettings.middleware.AppSettingsMiddleware', ] ROOT_URLCONF = 'webvirtcloud.urls' @@ -67,6 +68,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'appsettings.context_processors.app_settings', ], 'libraries': { 'common_tags': 'webvirtcloud.common_tags',