From bc85e76ed17d691906222cf93a4c4a53b82e8a0e Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Mon, 31 Aug 2009 19:26:46 +0200 Subject: [PATCH] changed hardcoded urls to reverse resolved ones, finally allowing m-d to run in a shared apache vhost. --- pyweb/mumble/templatetags/mumble_extras.py | 9 ++++--- pyweb/mumble/views.py | 21 +++++++++++---- pyweb/settings.py | 5 ++-- pyweb/urls.py | 9 ++++--- pyweb/views.py | 7 ++++- template/index.htm | 31 +++++++++++----------- template/mumble/channel.htm | 6 ++--- template/mumble/list.htm | 2 +- template/mumble/mumble.htm | 28 ++++++++++--------- template/mumble/player.htm | 14 +++++----- template/mumble/server.htm | 2 +- 11 files changed, 79 insertions(+), 55 deletions(-) diff --git a/pyweb/mumble/templatetags/mumble_extras.py b/pyweb/mumble/templatetags/mumble_extras.py index 2a098b8..8b0ac24 100644 --- a/pyweb/mumble/templatetags/mumble_extras.py +++ b/pyweb/mumble/templatetags/mumble_extras.py @@ -16,9 +16,12 @@ from django import template from django.template.loader import render_to_string +from django.conf import settings + register = template.Library(); + ### FILTER: trunc -- converts "a very very extaordinary long text" to "a very very extra..." def trunc( string, maxlen = 50 ): if len(string) < maxlen: @@ -31,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 } ); + 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 } ); + 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 } ); + 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 9765104..91bdc26 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -16,6 +16,7 @@ import simplejson from StringIO import StringIO +from os.path import join from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 from django.template import RequestContext @@ -23,24 +24,30 @@ from django.http import Http404, HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.conf import settings +from django.core.urlresolvers import reverse + +from django.contrib.auth import views as auth_views from models import Mumble, MumbleUser from forms import * from mmobjects import * +def redir( request ): + return HttpResponseRedirect( reverse( mumbles ) ); def mumbles( request ): """Display a list of all configured Mumble servers, or redirects if only one configured.""" mumbles = get_list_or_404( Mumble ); if len(mumbles) == 1: - return HttpResponseRedirect( '/mumble/%d' % mumbles[0].id ); + return HttpResponseRedirect( reverse( show, kwargs={ 'server': mumbles[0].id, } ) ); return render_to_response( 'mumble/list.htm', { 'MumbleObjects': mumbles, 'MumbleActive': True, + 'media_url': settings.MEDIA_URL, }, context_instance = RequestContext(request) ); @@ -65,7 +72,7 @@ def show( request, server ): adminform = MumbleForm( request.POST, instance=srv ); if adminform.is_valid(): adminform.save(); - return HttpResponseRedirect( '/mumble/%d' % int(server) ); + return HttpResponseRedirect( reverse( show, kwargs={ 'server': int(server), } ) ); else: displayTab = 2; else: @@ -95,14 +102,14 @@ def show( request, server ): model.server = srv; model.owner = request.user; model.save(); - return HttpResponseRedirect( '/mumble/%d' % int(server) ); + return HttpResponseRedirect( reverse( show, kwargs={ 'server': int(server), } ) ); else: displayTab = 1; else: regform = MumbleUserForm( request.POST, instance=user ); if regform.is_valid(): regform.save(); - return HttpResponseRedirect( '/mumble/%d' % int(server) ); + return HttpResponseRedirect( reverse( show, kwargs={ 'server': int(server), } ) ); else: displayTab = 1; else: @@ -118,7 +125,7 @@ def show( request, server ): textureform = MumbleTextureForm( request.POST, request.FILES ); if textureform.is_valid(): user.setTexture( request.FILES['texturefile'] ); - return HttpResponseRedirect( '/mumble/%d' % int(server) ); + return HttpResponseRedirect( reverse( show, kwargs={ 'server': int(server), } ) ); else: textureform = MumbleTextureForm(); @@ -134,10 +141,14 @@ def show( request, server ): for id in srv.players: channelTable.append( srv.players[id] ); + show_url = reverse( show, kwargs={ 'server': srv.id } ); + login_url = reverse( auth_views.login ); return render_to_response( 'mumble/mumble.htm', { + 'media_url': settings.MEDIA_URL, + 'login_url': "%s?next=%s" % ( login_url, show_url ), 'DBaseObject': srv, 'ChannelTable': channelTable, 'CurrentUserIsAdmin': isAdmin, diff --git a/pyweb/settings.py b/pyweb/settings.py index 7d6a0e1..8fe2d35 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -36,6 +36,7 @@ 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__))); @@ -119,12 +120,12 @@ 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 = '' +MEDIA_URL = join( get_script_prefix(), 'static' ); # 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 = '/media/' +ADMIN_MEDIA_PREFIX = join( get_script_prefix(), '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 ce705cd..bfa7b2a 100644 --- a/pyweb/urls.py +++ b/pyweb/urls.py @@ -22,8 +22,9 @@ admin.autodiscover() from django.conf import settings + urlpatterns = patterns('', - (r'^/?$', 'django.views.generic.simple.redirect_to', { 'url': '/mumble/' } ), + (r'^/?$', 'mumble.views.redir' ), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: @@ -36,12 +37,14 @@ urlpatterns = patterns('', (r'^mumble/', include('mumble.urls')), # Uncomment the next line to enable the admin: - (r'^admin/(.*)', admin.site.root), + (r'^admin/', admin.site.urls), ) # Development stuff if settings.DEBUG: urlpatterns += patterns('', - (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True} ), + (r'^%s/(?P.*)$' % settings.MEDIA_URL[1:], + 'django.views.static.serve', + {'document_root': settings.MEDIA_ROOT, 'show_indexes': True} ), ) diff --git a/pyweb/views.py b/pyweb/views.py index 3a98b76..9d80eb5 100644 --- a/pyweb/views.py +++ b/pyweb/views.py @@ -20,6 +20,7 @@ from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User +from django.conf import settings from mumble.models import Mumble, MumbleUser #from guestbook.models import Entry, Comment @@ -29,6 +30,7 @@ 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(), @@ -43,4 +45,7 @@ def profile( request ): def imprint( request ): - return render_to_response( 'registration/imprint.html', {}, context_instance = RequestContext(request) ); + return render_to_response( + 'registration/imprint.html', + { 'media_url': settings.MEDIA_URL, }, + context_instance = RequestContext(request) ); diff --git a/template/index.htm b/template/index.htm index 5f82dcd..47a61d6 100644 --- a/template/index.htm +++ b/template/index.htm @@ -3,15 +3,15 @@ Mumble Administration - - - - - + + + + + - - - + + + {% block HeadTag %} {% endblock %} @@ -22,28 +22,28 @@

{% block Headline %}{% endblock %}

@@ -66,4 +66,3 @@ - diff --git a/template/mumble/channel.htm b/template/mumble/channel.htm index 4d4c91b..b3733e3 100644 --- a/template/mumble/channel.htm +++ b/template/mumble/channel.htm @@ -1,10 +1,10 @@ {% load mumble_extras %}
- + {% if Channel.linked %} - linked channel + linked channel {% else %} - channel + channel {% endif %} {{ Channel.name|trunc:30 }} diff --git a/template/mumble/list.htm b/template/mumble/list.htm index ad76e47..eb548fa 100644 --- a/template/mumble/list.htm +++ b/template/mumble/list.htm @@ -7,7 +7,7 @@ Configured Mumble Servers diff --git a/template/mumble/mumble.htm b/template/mumble/mumble.htm index 4f99d71..d8ee7e5 100644 --- a/template/mumble/mumble.htm +++ b/template/mumble/mumble.htm @@ -10,12 +10,12 @@ {% block Content %}
@@ -35,7 +35,7 @@
{% if user.is_authenticated %}

{% trans "Server registration" %}

-
+ {% if Registered %} {% trans "You are registered on this server" %}.
{% else %} @@ -48,9 +48,9 @@
{% else %} - {% blocktrans with DBaseObject.id as serverid %} -

You need to be logged in to be able to register an account on this Mumble server.

- {% endblocktrans %} + {% blocktrans %} +

You need to be logged in to be able to register an account on this Mumble server.

+ {% endblocktrans %} {% endif %}
@@ -58,15 +58,17 @@

{% trans "User Texture" %}

- {% blocktrans with DBaseObject.id as serverid %} + {% blocktrans with DBaseObject.id as serverid %} You can upload an image that you would like to use as your user texture here.
Your current texture is:
- user texture
+ {% endblocktrans %} + user texture
+ {% blocktrans with DBaseObject.id as serverid %} Hint: The texture image needs to be 600x60 in size. If you upload an image with a different size, it will be resized accordingly.
- {% endblocktrans %} + {% endblocktrans %}

-
+ {{ TextureForm }}
@@ -79,7 +81,7 @@ {% if CurrentUserIsAdmin %}

{% trans "Server administration" %}

- + {{ AdminForm }}
@@ -113,7 +115,7 @@ {% endif %}

{% trans "User Texture" %}

- user texture + user texture
{% else %}
@@ -184,7 +186,7 @@ valueField: 'uid', displayField: 'uname', store: new Ext.data.Store({ - url: '/mumble/djangousers', + url: '{% url mumble.views.users DBaseObject.id %}', reader: new Ext.data.JsonReader({ fields: [ 'uid', 'uname' ], root: 'objects', diff --git a/template/mumble/player.htm b/template/mumble/player.htm index f393125..675d628 100644 --- a/template/mumble/player.htm +++ b/template/mumble/player.htm @@ -2,24 +2,24 @@
{% if Player.isAuthed %} - authed + authed {% endif %} {% if Player.muted or Player.suppressed %} - muted + muted {% endif %} {% if Player.deafened %} - deafened + deafened {% endif %} {% if Player.selfmuted %} - self-muted + self-muted {% endif %} {% if Player.selfdeafened %} - self-deafened + self-deafened {% endif %} - - Player + + Player {{ Player.name|trunc:30 }}
diff --git a/template/mumble/server.htm b/template/mumble/server.htm index 8f5b019..1ce4e49 100644 --- a/template/mumble/server.htm +++ b/template/mumble/server.htm @@ -1,6 +1,6 @@ {% load mumble_extras %} {% for sub in Server.rootchan.subchans %}