diff --git a/pyweb/deferred_resolver.py b/pyweb/deferred_resolver.py new file mode 100644 index 0000000..e2abc07 --- /dev/null +++ b/pyweb/deferred_resolver.py @@ -0,0 +1,41 @@ +# -*- 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. +""" + +from django.core.urlresolvers import get_script_prefix, reverse +from os.path import join + +class StaticResolver( object ): + def __init__( self, string ): + self._string = string; + + def __str__( self ): + return join( get_script_prefix(), self._string ); + + def __add__( self, other ): + return str( self ) + other; + +class ViewResolver( object ): + def __init__( self, string, *args, **kwargs ): + self._string = string; + self._args = args; + self._kwargs = kwargs; + + def __str__( self ): + return reverse( self._string, *self._args, **self._kwargs ); + + def __add__( self, other ): + return str( self ) + other; + diff --git a/pyweb/mumble/templatetags/mumble_extras.py b/pyweb/mumble/templatetags/mumble_extras.py index 8b0ac24..9a58d23 100644 --- a/pyweb/mumble/templatetags/mumble_extras.py +++ b/pyweb/mumble/templatetags/mumble_extras.py @@ -34,11 +34,11 @@ register.filter( 'trunc', trunc ); ### FILTER: chanview -- renders an mmChannel / mmPlayer object with the correct template. def chanview( obj, user = None ): if obj.is_server: - return render_to_string( 'mumble/server.htm', { 'Server': obj, 'MumbleAccount': user, 'media_url': settings.MEDIA_URL } ); + return render_to_string( 'mumble/server.htm', { 'Server': obj, 'MumbleAccount': user, 'MEDIA_URL': settings.MEDIA_URL } ); elif obj.is_channel: - return render_to_string( 'mumble/channel.htm', { 'Channel': obj, 'MumbleAccount': user, 'media_url': settings.MEDIA_URL } ); + return render_to_string( 'mumble/channel.htm', { 'Channel': obj, 'MumbleAccount': user, 'MEDIA_URL': settings.MEDIA_URL } ); elif obj.is_player: - return render_to_string( 'mumble/player.htm', { 'Player': obj, 'MumbleAccount': user, 'media_url': settings.MEDIA_URL } ); + return render_to_string( 'mumble/player.htm', { 'Player': obj, 'MumbleAccount': user, 'MEDIA_URL': settings.MEDIA_URL } ); register.filter( 'chanview', chanview ); diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 91bdc26..b53d0d0 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -47,7 +47,7 @@ def mumbles( request ): 'mumble/list.htm', { 'MumbleObjects': mumbles, 'MumbleActive': True, - 'media_url': settings.MEDIA_URL, + 'MEDIA_URL': settings.MEDIA_URL, }, context_instance = RequestContext(request) ); @@ -147,7 +147,7 @@ def show( request, server ): return render_to_response( 'mumble/mumble.htm', { - 'media_url': settings.MEDIA_URL, + 'MEDIA_URL': settings.MEDIA_URL, 'login_url': "%s?next=%s" % ( login_url, show_url ), 'DBaseObject': srv, 'ChannelTable': channelTable, diff --git a/pyweb/settings.py b/pyweb/settings.py index 8fe2d35..eedb6ee 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -36,7 +36,6 @@ MUMBLE_DJANGO_ROOT = None; ## ################################################################# -from django.core.urlresolvers import get_script_prefix 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__))); @@ -113,19 +112,18 @@ SITE_ID = 1 # to load the internationalization machinery. USE_I18N = True +from deferred_resolver import * + # Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = join( MUMBLE_DJANGO_ROOT, 'htdocs' ) -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash if there is a path component (optional in other cases). -# Examples: "http://media.lawrence.com", "http://example.com/media/" -MEDIA_URL = join( get_script_prefix(), 'static' ); +# URL that handles the media served from MEDIA_ROOT. +MEDIA_URL = StaticResolver( 'static' ); + +LOGIN_URL = ViewResolver( "django.contrib.auth.views.login" ); -# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a -# trailing slash. -# Examples: "http://foo.com/media/", "/media/". -ADMIN_MEDIA_PREFIX = join( get_script_prefix(), 'media' ); +# URL prefix for admin media -- CSS, JavaScript and images. +ADMIN_MEDIA_PREFIX = StaticResolver( 'media/' ); # Make this unique, and don't share it with anybody. SECRET_KEY = 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v' diff --git a/pyweb/urls.py b/pyweb/urls.py index bfa7b2a..c1237d2 100644 --- a/pyweb/urls.py +++ b/pyweb/urls.py @@ -32,7 +32,7 @@ urlpatterns = patterns('', (r'^accounts/profile/', 'views.profile' ), (r'^accounts/imprint/', 'views.imprint' ), - (r'^accounts/', include('registration.urls')), + (r'^accounts/', include('registration.urls') ), (r'^mumble/', include('mumble.urls')), @@ -43,8 +43,6 @@ urlpatterns = patterns('', # Development stuff if settings.DEBUG: urlpatterns += patterns('', - (r'^%s/(?P.*)$' % settings.MEDIA_URL[1:], - 'django.views.static.serve', - {'document_root': settings.MEDIA_ROOT, 'show_indexes': True} ), + (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True} ), ) diff --git a/pyweb/views.py b/pyweb/views.py index 9d80eb5..9615f89 100644 --- a/pyweb/views.py +++ b/pyweb/views.py @@ -30,7 +30,7 @@ from mumble.models import Mumble, MumbleUser def profile( request ): userdata = { "ProfileActive": True, - 'media_url': settings.MEDIA_URL, + '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 +47,5 @@ def profile( request ): def imprint( request ): return render_to_response( 'registration/imprint.html', - { 'media_url': settings.MEDIA_URL, }, + { 'MEDIA_URL': settings.MEDIA_URL, }, context_instance = RequestContext(request) ); diff --git a/template/index.htm b/template/index.htm index 47a61d6..e907c39 100644 --- a/template/index.htm +++ b/template/index.htm @@ -3,15 +3,15 @@ Mumble Administration - - - - - + + + + + - - - + + + {% block HeadTag %} {% endblock %} diff --git a/template/mumble/channel.htm b/template/mumble/channel.htm index b3733e3..8422d2b 100644 --- a/template/mumble/channel.htm +++ b/template/mumble/channel.htm @@ -1,10 +1,10 @@ {% load mumble_extras %}