Browse Source

change case of MEDIA_URL in templates, defer resolving in settings.py until after the WSGI daemon had a chance of setting the script prefix

Natenom/support-murmur-13-1446181288462
Michael Ziegler 16 years ago
parent
commit
e668504a36
  1. 41
      pyweb/deferred_resolver.py
  2. 6
      pyweb/mumble/templatetags/mumble_extras.py
  3. 4
      pyweb/mumble/views.py
  4. 18
      pyweb/settings.py
  5. 6
      pyweb/urls.py
  6. 4
      pyweb/views.py
  7. 16
      template/index.htm
  8. 6
      template/mumble/channel.htm
  9. 14
      template/mumble/player.htm
  10. 2
      template/mumble/server.htm

41
pyweb/deferred_resolver.py

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
"""
* Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
*
* 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;

6
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. ### FILTER: chanview -- renders an mmChannel / mmPlayer object with the correct template.
def chanview( obj, user = None ): def chanview( obj, user = None ):
if obj.is_server: 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: 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: 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 ); register.filter( 'chanview', chanview );

4
pyweb/mumble/views.py

@ -47,7 +47,7 @@ def mumbles( request ):
'mumble/list.htm', 'mumble/list.htm',
{ 'MumbleObjects': mumbles, { 'MumbleObjects': mumbles,
'MumbleActive': True, 'MumbleActive': True,
'media_url': settings.MEDIA_URL,
'MEDIA_URL': settings.MEDIA_URL,
}, },
context_instance = RequestContext(request) context_instance = RequestContext(request)
); );
@ -147,7 +147,7 @@ def show( request, server ):
return render_to_response( return render_to_response(
'mumble/mumble.htm', 'mumble/mumble.htm',
{ {
'media_url': settings.MEDIA_URL,
'MEDIA_URL': settings.MEDIA_URL,
'login_url': "%s?next=%s" % ( login_url, show_url ), 'login_url': "%s?next=%s" % ( login_url, show_url ),
'DBaseObject': srv, 'DBaseObject': srv,
'ChannelTable': channelTable, 'ChannelTable': channelTable,

18
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 from os.path import join, dirname, abspath, exists
if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ):
MUMBLE_DJANGO_ROOT = dirname(dirname(abspath(__file__))); MUMBLE_DJANGO_ROOT = dirname(dirname(abspath(__file__)));
@ -113,19 +112,18 @@ SITE_ID = 1
# to load the internationalization machinery. # to load the internationalization machinery.
USE_I18N = True USE_I18N = True
from deferred_resolver import *
# Absolute path to the directory that holds media. # Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = join( MUMBLE_DJANGO_ROOT, 'htdocs' ) 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. # Make this unique, and don't share it with anybody.
SECRET_KEY = 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v' SECRET_KEY = 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v'

6
pyweb/urls.py

@ -32,7 +32,7 @@ urlpatterns = patterns('',
(r'^accounts/profile/', 'views.profile' ), (r'^accounts/profile/', 'views.profile' ),
(r'^accounts/imprint/', 'views.imprint' ), (r'^accounts/imprint/', 'views.imprint' ),
(r'^accounts/', include('registration.urls')),
(r'^accounts/', include('registration.urls') ),
(r'^mumble/', include('mumble.urls')), (r'^mumble/', include('mumble.urls')),
@ -43,8 +43,6 @@ urlpatterns = patterns('',
# Development stuff # Development stuff
if settings.DEBUG: if settings.DEBUG:
urlpatterns += patterns('', urlpatterns += patterns('',
(r'^%s/(?P<path>.*)$' % settings.MEDIA_URL[1:],
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True} ),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True} ),
) )

4
pyweb/views.py

@ -30,7 +30,7 @@ from mumble.models import Mumble, MumbleUser
def profile( request ): def profile( request ):
userdata = { userdata = {
"ProfileActive": True, "ProfileActive": True,
'media_url': settings.MEDIA_URL,
'MEDIA_URL': settings.MEDIA_URL,
"mumbleaccs": MumbleUser.objects.filter( owner = request.user ), "mumbleaccs": MumbleUser.objects.filter( owner = request.user ),
# "gbposts": Entry.objects.filter( author = request.user ).count(), # "gbposts": Entry.objects.filter( author = request.user ).count(),
# "gbcomments": Comment.objects.filter( author = request.user ).count(), # "gbcomments": Comment.objects.filter( author = request.user ).count(),
@ -47,5 +47,5 @@ def profile( request ):
def imprint( request ): def imprint( request ):
return render_to_response( return render_to_response(
'registration/imprint.html', 'registration/imprint.html',
{ 'media_url': settings.MEDIA_URL, },
{ 'MEDIA_URL': settings.MEDIA_URL, },
context_instance = RequestContext(request) ); context_instance = RequestContext(request) );

16
template/index.htm

@ -3,15 +3,15 @@
<title>Mumble Administration</title> <title>Mumble Administration</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="{{ media_url }}/ext-2.2/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="{{ media_url }}/style.css" />
<link rel="stylesheet" type="text/css" href="{{ media_url }}/templatestyle.css" />
<link rel="stylesheet" type="text/css" href="{{ media_url }}/mumble/style.css" />
<link rel="shortcut icon" type="image/png" href="{{ media_url }}/mumble/mumble.16x16.png" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/ext-2.2/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/style.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/templatestyle.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/mumble/style.css" />
<link rel="shortcut icon" type="image/png" href="{{ MEDIA_URL }}/mumble/mumble.16x16.png" />
<script type="text/javascript" src="{{ media_url }}/ext-2.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="{{ media_url }}/ext-2.2/ext-all.js"></script>
<script type="text/javascript" src="{{ media_url }}/checkcolumn.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/ext-2.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/ext-2.2/ext-all.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/checkcolumn.js"></script>
{% block HeadTag %} {% block HeadTag %}
{% endblock %} {% endblock %}

6
template/mumble/channel.htm

@ -1,10 +1,10 @@
{% load mumble_extras %} {% load mumble_extras %}
<div class="mumble"> <div class="mumble">
<img src="{{ media_url }}/mumble/knoten_v.png" />
<img src="{{ MEDIA_URL }}/mumble/knoten_v.png" />
{% if Channel.linked %} {% if Channel.linked %}
<img src="{{ media_url }}/mumble/channel_linked.png" alt="linked channel" />
<img src="{{ MEDIA_URL }}/mumble/channel_linked.png" alt="linked channel" />
{% else %} {% else %}
<img src="{{ media_url }}/mumble/channel.png" alt="channel" />
<img src="{{ MEDIA_URL }}/mumble/channel.png" alt="channel" />
{% endif %} {% endif %}
<a href="{{ Channel|chanurl:MumbleAccount }}" class="mumble" id="link_{{ Channel.id }}" title="{{ Channel.name }}"> <a href="{{ Channel|chanurl:MumbleAccount }}" class="mumble" id="link_{{ Channel.id }}" title="{{ Channel.name }}">
{{ Channel.name|trunc:30 }} {{ Channel.name|trunc:30 }}

14
template/mumble/player.htm

@ -2,24 +2,24 @@
<div class="mumble"> <div class="mumble">
<span class="mumble"> <span class="mumble">
{% if Player.isAuthed %} {% if Player.isAuthed %}
<img src="{{ media_url }}/mumble/authenticated.png" alt="authed" title="Authenticated" />
<img src="{{ MEDIA_URL }}/mumble/authenticated.png" alt="authed" title="Authenticated" />
{% endif %} {% endif %}
{% if Player.muted or Player.suppressed %} {% if Player.muted or Player.suppressed %}
<img src="{{ media_url }}/mumble/muted_server.png" alt="muted" title="Muted by server" />
<img src="{{ MEDIA_URL }}/mumble/muted_server.png" alt="muted" title="Muted by server" />
{% endif %} {% endif %}
{% if Player.deafened %} {% if Player.deafened %}
<img src="{{ media_url }}/mumble/deafened_server.png" alt="deafened" title="Deafened by server" />
<img src="{{ MEDIA_URL }}/mumble/deafened_server.png" alt="deafened" title="Deafened by server" />
{% endif %} {% endif %}
{% if Player.selfmuted %} {% if Player.selfmuted %}
<img src="{{ media_url }}/mumble/muted_self.png" alt="self-muted" title="Muted by themselves" />
<img src="{{ MEDIA_URL }}/mumble/muted_self.png" alt="self-muted" title="Muted by themselves" />
{% endif %} {% endif %}
{% if Player.selfdeafened %} {% if Player.selfdeafened %}
<img src="{{ media_url }}/mumble/deafened_self.png" alt="self-deafened" title="Deafened by themselves" />
<img src="{{ MEDIA_URL }}/mumble/deafened_self.png" alt="self-deafened" title="Deafened by themselves" />
{% endif %} {% endif %}
</span> </span>
<span> <span>
<img src="{{ media_url }}/mumble/knoten_v.png" />
<img src="{{ media_url }}/mumble/talking_off.png" alt="Player" />
<img src="{{ MEDIA_URL }}/mumble/knoten_v.png" />
<img src="{{ MEDIA_URL }}/mumble/talking_off.png" alt="Player" />
<a id="link_{{ Player.id }}" class="mumble" href="#" title="{{ Player.name }}">{{ Player.name|trunc:30 }}</a> <a id="link_{{ Player.id }}" class="mumble" href="#" title="{{ Player.name }}">{{ Player.name|trunc:30 }}</a>
</span> </span>
</div> </div>

2
template/mumble/server.htm

@ -1,6 +1,6 @@
{% load mumble_extras %} {% load mumble_extras %}
<div style="margin-left: 20px"> <div style="margin-left: 20px">
<img src="{{ media_url }}/mumble/mumble.16x16.png" alt="server" />
<img src="{{ MEDIA_URL }}/mumble/mumble.16x16.png" alt="server" />
<a class="mumble" id="link_server" href="{{ Server|chanurl:MumbleAccount }}">{{ Server.name|trunc:30 }}</a> <a class="mumble" id="link_server" href="{{ Server|chanurl:MumbleAccount }}">{{ Server.name|trunc:30 }}</a>
</div> </div>
{% for sub in Server.rootchan.subchans %} {% for sub in Server.rootchan.subchans %}

Loading…
Cancel
Save