From 2b365a0496edca63c9097d447f6df05ea846f673 Mon Sep 17 00:00:00 2001 From: Arne Schauf Date: Sat, 28 Sep 2013 23:31:33 +0200 Subject: [PATCH] moved create_context to context_processor --- nsupdate/main/templates/main/overview.html | 4 ++-- nsupdate/main/views.py | 9 +-------- nsupdate/nsupdate/context_processors.py | 9 +++++++++ nsupdate/nsupdate/settings.py | 2 ++ 4 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 nsupdate/nsupdate/context_processors.py diff --git a/nsupdate/main/templates/main/overview.html b/nsupdate/main/templates/main/overview.html index 0ce4882..3bbe25f 100644 --- a/nsupdate/main/templates/main/overview.html +++ b/nsupdate/main/templates/main/overview.html @@ -31,8 +31,8 @@

Information

- your IPv4: {{session.ipv4}}
- your IPv6: {{session.ipv6}} + your IPv4: {{ request.session.ipv4 }}
+ your IPv6: {{ request.session.ipv6 }}
diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index 62afcb9..74b7b36 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -12,13 +12,6 @@ from django.core.urlresolvers import reverse from main.forms import HostForm from main.models import Host -def create_context(request): - context = {} - context['WWW_IPV4_HOST'] = settings.WWW_IPV4_HOST - context['WWW_IPV6_HOST'] = settings.WWW_IPV6_HOST - context['session'] = request.session - return context - class HomeView(TemplateView): template_name = "base.html" @@ -57,7 +50,7 @@ class OverviewView(CreateView): @login_required def HostView(request,pk=None): - context = create_context(request) + context = {} context['nav_overview'] = True context['HostForm'] = HostForm(request.user,instance=get_object_or_404(Host, pk=pk, created_by=request.user)) if request.method == "POST": diff --git a/nsupdate/nsupdate/context_processors.py b/nsupdate/nsupdate/context_processors.py new file mode 100644 index 0000000..ae06266 --- /dev/null +++ b/nsupdate/nsupdate/context_processors.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from django.conf import settings + +def add_settings(request): + context = {} + context['WWW_IPV4_HOST'] = settings.WWW_IPV4_HOST + context['WWW_IPV6_HOST'] = settings.WWW_IPV6_HOST + return context + diff --git a/nsupdate/nsupdate/settings.py b/nsupdate/nsupdate/settings.py index ac599a8..d49452a 100644 --- a/nsupdate/nsupdate/settings.py +++ b/nsupdate/nsupdate/settings.py @@ -121,6 +121,7 @@ MIDDLEWARE_CLASSES = ( TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( 'django.core.context_processors.request', + 'nsupdate.context_processors.add_settings', ) ROOT_URLCONF = 'nsupdate.urls' @@ -203,3 +204,4 @@ try: from .local_settings import * except ImportError: pass +