From 432f97e654559ca459846eb464ea59c6efaf4f5e Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 15 Jan 2010 09:17:09 +0100 Subject: [PATCH] use context processors for MEDIA_URL and ROSETTA_ISNTALLED variables --- pyweb/mumble/views.py | 4 ---- pyweb/processors.py | 23 +++++++++++++++++++++++ pyweb/settings.py | 9 +++++++++ pyweb/templates/index.html | 4 +++- pyweb/views.py | 2 -- 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 pyweb/processors.py diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 3b02b91..11c3c0b 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -70,7 +70,6 @@ def mumbles( request ): 'mumble/list.html', { 'MumbleObjects': mumbles, 'MumbleActive': True, - 'MEDIA_URL': settings.MEDIA_URL, }, context_instance = RequestContext(request) ); @@ -86,7 +85,6 @@ def mobile_mumbles( request ): 'mumble/mobile_list.html', { 'MumbleObjects': mumbles, 'MumbleActive': True, - 'MEDIA_URL': settings.MEDIA_URL, }, context_instance = RequestContext(request) ); @@ -191,7 +189,6 @@ def show( request, server ): return render_to_response( 'mumble/mumble.html', { - 'MEDIA_URL': settings.MEDIA_URL, 'login_url': "%s?next=%s" % ( login_url, show_url ), 'DBaseObject': srv, 'ChannelTable': channelTable, @@ -222,7 +219,6 @@ def mobile_show( request, server ): return render_to_response( 'mumble/mobile_mumble.html', { - 'MEDIA_URL': settings.MEDIA_URL, 'DBaseObject': srv, 'MumbleActive': True, 'MumbleAccount':user, diff --git a/pyweb/processors.py b/pyweb/processors.py new file mode 100644 index 0000000..711cd53 --- /dev/null +++ b/pyweb/processors.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2009, Michael "Svedrin" Ziegler + * + * Mumble-Django is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. +""" + +def media_url(request): + from django.conf import settings + return { 'MEDIA_URL': settings.MEDIA_URL } + +def installed_apps(request): + from django.conf import settings + return { 'ROSETTA_INSTALLED': "rosetta" in settings.INSTALLED_APPS } diff --git a/pyweb/settings.py b/pyweb/settings.py index a366eeb..6886f23 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -178,6 +178,15 @@ TEMPLATE_DIRS = ( join( MUMBLE_DJANGO_ROOT, 'pyweb', 'templates' ), ) +TEMPLATE_CONTEXT_PROCESSORS = ( + "django.core.context_processors.auth", + "django.core.context_processors.debug", + "django.core.context_processors.i18n", + "django.core.context_processors.media", + 'processors.media_url', + 'processors.installed_apps', + ); + TEST_RUNNER = 'mumble.testrunner.run_tests' TEST_MURMUR_LAB_DIR = join( dirname(MUMBLE_DJANGO_ROOT), 'murmur' ); TEST_MURMUR_FILES_DIR = join( MUMBLE_DJANGO_ROOT, 'testdata' ); diff --git a/pyweb/templates/index.html b/pyweb/templates/index.html index 49f6ade..5e0cfe1 100644 --- a/pyweb/templates/index.html +++ b/pyweb/templates/index.html @@ -30,7 +30,9 @@ {% endif %} {% if user.is_staff %} {% trans "Administration" %} | - {% trans "Edit translations" %} | + {% if ROSETTA_INSTALLED %} + {% trans "Edit translations" %} | + {% endif %} {% endif %} {% trans "Imprint" %} diff --git a/pyweb/views.py b/pyweb/views.py index 9615f89..bf90928 100644 --- a/pyweb/views.py +++ b/pyweb/views.py @@ -30,7 +30,6 @@ from mumble.models import Mumble, MumbleUser def profile( request ): userdata = { "ProfileActive": True, - 'MEDIA_URL': settings.MEDIA_URL, "mumbleaccs": MumbleUser.objects.filter( owner = request.user ), # "gbposts": Entry.objects.filter( author = request.user ).count(), # "gbcomments": Comment.objects.filter( author = request.user ).count(), @@ -47,5 +46,4 @@ def profile( request ): def imprint( request ): return render_to_response( 'registration/imprint.html', - { 'MEDIA_URL': settings.MEDIA_URL, }, context_instance = RequestContext(request) );