From 2114a11374ac39c57cc74da1d0fe726e277d5e91 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Wed, 19 May 2010 12:46:27 +0200 Subject: [PATCH] reorganize settings.py and add basic theming support --- htdocs/themes/README.txt | 2 + pyweb/processors.py | 7 ++++ pyweb/settings.py | 87 ++++++++++++++++++++++++++-------------- themes/README.txt | 28 +++++++++++++ 4 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 htdocs/themes/README.txt create mode 100644 themes/README.txt diff --git a/htdocs/themes/README.txt b/htdocs/themes/README.txt new file mode 100644 index 0000000..4679686 --- /dev/null +++ b/htdocs/themes/README.txt @@ -0,0 +1,2 @@ +This file basically only exists to have HG keep the "themes" directory. For +documentation on themes, see themes/README.txt in the root directory of MD. diff --git a/pyweb/processors.py b/pyweb/processors.py index 1ba706f..44a95cf 100644 --- a/pyweb/processors.py +++ b/pyweb/processors.py @@ -22,3 +22,10 @@ def installed_apps(request): def mumble_version(request): from mumble import version_str return { 'CURRENTVERSION': version_str } + +def theme_url(request): + from django.conf import settings + if settings.THEME: + return { 'THEME_URL': settings.THEME_URL } + else: + return {} diff --git a/pyweb/settings.py b/pyweb/settings.py index aabb0d8..19c3372 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -54,10 +54,28 @@ MUMBLE_DJANGO_ROOT = None ## ################################################################# ################################################################# +# Who will receive emails on errors? +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) -from os.path import join, dirname, abspath, exists -if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): - MUMBLE_DJANGO_ROOT = dirname(dirname(abspath(__file__))) +# Show debug information on errors? +# If you want to file a bug report, please enable this option. +DEBUG = True + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'Europe/Berlin' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +# The Theme to use. None for the builtin theme. +THEME = None # URL Template for constructing Gravatars. GRAVATAR_URL = 'http://www.gravatar.com/avatar/%(hash)s.jpg?d=monsterid&s=%(size)d' @@ -108,8 +126,25 @@ MUNIN_TITLE = 'Mumble Users' # see for a list of valid categories. MUNIN_CATEGORY = 'network' -# Database settings for Mumble-Django's database. These do NOT need to point to Murmur's database, -# Mumble-Django should use its own! + +################################################################### +## ## +## The following settings normally do not require changes, and ## +## you should only change them if you know what you're doing. ## +## ## +################################################################### + +from os.path import join, dirname, abspath, exists +if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): + MUMBLE_DJANGO_ROOT = dirname(dirname(abspath(__file__))) + +if not MUMBLE_DJANGO_URL: + MUMBLE_DJANGO_URL = '/' +elif MUMBLE_DJANGO_URL[-1] != '/': + MUMBLE_DJANGO_URL = MUMBLE_DJANGO_URL + '/' + +# Database settings for Mumble-Django's database. These do NOT need to point +# to Murmur's database, Mumble-Django should use its own! DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = join( MUMBLE_DJANGO_ROOT, 'db', 'mumble-django.db3' ) DATABASE_USER = '' @@ -117,43 +152,27 @@ DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = '' - -# Show debug information on errors? -DEBUG = True TEMPLATE_DEBUG = DEBUG -ADMINS = ( - # ('Your Name', 'your_email@domain.com'), -) - MANAGERS = ADMINS -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = 'Europe/Berlin' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'en-us' - SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True - # Absolute path to the directory that holds media. MEDIA_ROOT = join( MUMBLE_DJANGO_ROOT, 'htdocs' ) # URL that handles the media served from MEDIA_ROOT. -MEDIA_URL = MUMBLE_DJANGO_URL+'static/' +MEDIA_URL = MUMBLE_DJANGO_URL + 'static/' + +## URL to static files of the currently active theme +THEME_URL = '%sstatic/themes/%s/' % ( MUMBLE_DJANGO_URL, THEME ) # URL prefix for admin media -- CSS, JavaScript and images. -ADMIN_MEDIA_PREFIX = MUMBLE_DJANGO_URL+'media/' +ADMIN_MEDIA_PREFIX = MUMBLE_DJANGO_URL + 'media/' # URL to the login view LOGIN_URL = MUMBLE_DJANGO_URL + 'accounts/login' @@ -194,21 +213,29 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'pyweb.urls' -TEMPLATE_DIRS = ( +if THEME: + TEMPLATE_DIRS = [ join( MUMBLE_DJANGO_ROOT, 'themes', THEME, 'templates' ) ] +else: + TEMPLATE_DIRS = [] + +TEMPLATE_DIRS.extend(( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. join( MUMBLE_DJANGO_ROOT, 'pyweb', 'templates' ), -) +)) -TEMPLATE_CONTEXT_PROCESSORS = ( +TEMPLATE_CONTEXT_PROCESSORS = [ "django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", 'processors.installed_apps', 'processors.mumble_version', -) +] + +if THEME: + TEMPLATE_CONTEXT_PROCESSORS.append('processors.theme_url') TEST_RUNNER = 'mumble.testrunner.run_tests' TEST_MURMUR_LAB_DIR = join( dirname(MUMBLE_DJANGO_ROOT), 'murmur' ) diff --git a/themes/README.txt b/themes/README.txt new file mode 100644 index 0000000..2ea3e64 --- /dev/null +++ b/themes/README.txt @@ -0,0 +1,28 @@ += Themes = + +Themes in Mumble-Django consist of two parts: A template directory and static +content. The template directory for each theme should //not// be accessible +from the browser and therefore cannot go into the same directory where the +static files (like css files and images) are in. + +== Directory structure == + / Mumble-Django installation directory + /themes// Templates + /htdocs/themes// Static content + +To use a theme, set the THEME variable in settings.py to the name of the theme. +This will adjust the settings so that Django first tries to load templates from +the theme's template directory, and if it does not find a template there, +proceeds to use the default (built-in) templates instead. + +This means a theme should only include those templates that it actually +modifies! + +== THEME_URL == + +When the THEME setting is set, Mumble-Django will automatically enable a +context processor that sets the THEME_URL template variable to the URL under +which the /htdocs/themes// directory is served, so in order to reference +files in the static directory, template authors should always use the THEME_URL +variable as this is the most accurate way to build these URLs. THEME_URL will +always contain a trailing "/".