Browse Source

reorganize settings.py and add basic theming support

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
2114a11374
  1. 2
      htdocs/themes/README.txt
  2. 7
      pyweb/processors.py
  3. 87
      pyweb/settings.py
  4. 28
      themes/README.txt

2
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.

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

87
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 <http://munin.projects.linpro.no/wiki/graph_category_list> 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' )

28
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/<name>/ Templates
/htdocs/themes/<name>/ 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/<name>/ 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 "/".
Loading…
Cancel
Save