From 44580b161a3222fcfad422458771ce239faf9ead Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sat, 29 Aug 2009 11:19:08 +0200 Subject: [PATCH] show user textures in the detail pages --- pyweb/mumble/urls.py | 7 ++++--- pyweb/mumble/views.py | 30 ++++++++++++++++++------------ template/mumble/mumble.htm | 2 ++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py index a2f4b19..3ca550e 100644 --- a/pyweb/mumble/urls.py +++ b/pyweb/mumble/urls.py @@ -18,7 +18,8 @@ from django.conf.urls.defaults import * urlpatterns = patterns( 'mumble.views', - ( r'(?P\d+)/texture.png', 'showTexture' ), - ( r'(?P\d+)', 'show' ), - ( r'$', 'mumbles' ), + ( r'(?P\d+)/(?P\d+)texture.png', 'showTexture' ), + ( r'(?P\d+)/texture.png', 'showTexture' ), + ( r'(?P\d+)', 'show' ), + ( r'$', 'mumbles' ), ) diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 6fb8d21..27091b5 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -152,20 +152,26 @@ def show( request, server ): ); -def showTexture( request, server ): +def showTexture( request, server, userid = None ): """Pack the currently logged in user's texture (if any) into an HttpResponse.""" - if request.user.is_authenticated(): - srv = Mumble.objects.get( id=int(server) ); - user = MumbleUser.objects.get( server=srv, owner=request.user ); - try: - img = user.getTexture(); - except ValueError: - raise Http404(); + srv = get_object_or_404( Mumble, id=int(server) ); + + if userid is None: + if request.user.is_authenticated(): + user = get_object_or_404( MumbleUser, server=srv, owner=request.user ); else: - buffer = StringIO(); - img.save( buffer, "PNG" ); - return HttpResponse( buffer.getvalue(), "image/png" ); - raise Http404(); + raise Http404(); + else: + user = get_object_or_404( MumbleUser, server=srv, id=int(userid) ); + + try: + img = user.getTexture(); + except ValueError: + raise Http404(); + else: + buffer = StringIO(); + img.save( buffer, "PNG" ); + return HttpResponse( buffer.getvalue(), "image/png" ); diff --git a/template/mumble/mumble.htm b/template/mumble/mumble.htm index 2358456..02a47f6 100644 --- a/template/mumble/mumble.htm +++ b/template/mumble/mumble.htm @@ -112,6 +112,8 @@
  • {% trans "Sign-up date" %}: {{ item.mumbleuser.owner.date_joined }}
  • {% endif %} +

    {% trans "User Texture" %}

    + user texture {% else %}