1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

Merge pull request #324 from Real-Gecko/master

Some improvements for appsettings app
This commit is contained in:
Anatoliy Guskov 2020-06-18 12:22:45 +03:00 committed by GitHub
commit ecaf11e02a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 4 deletions

View file

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View file

@ -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}

10
appsettings/middleware.py Normal file
View file

@ -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)

18
appsettings/settings.py Normal file
View file

@ -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.value)

View file

@ -1704,7 +1704,7 @@
</div>
</div>
{% if bottom_bar %}
{% if app_settings.VIEW_INSTANCE_DETAIL_BOTTOM_BAR == 'True' %}
{% include 'bottom_bar.html' %}
{% endif %}

View file

@ -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',