diff --git a/pyweb/mumble/templates/mumble/mumble.html b/pyweb/mumble/templates/mumble/mumble.html
index 1a03ff9..eaabf62 100644
--- a/pyweb/mumble/templates/mumble/mumble.html
+++ b/pyweb/mumble/templates/mumble/mumble.html
@@ -105,7 +105,13 @@
plugins: [ new Ext.ux.TabScrollerMenu() ],
items: [{
title: gettext("Server info"),
- html: renderserverinfos( {{ ServerDict|safe }} )
+ {% if QRAvailable %}
+ html: ('' +
+ renderserverinfos( {{ ServerDict|safe }} ))
+ {% else %}
+ html: renderserverinfos( {{ ServerDict|safe }} )
+ {% endif %}
}
{% if user.is_authenticated %},
{
diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py
index b86828e..cb1e314 100644
--- a/pyweb/mumble/urls.py
+++ b/pyweb/mumble/urls.py
@@ -37,7 +37,8 @@ urlpatterns = patterns(
( r'mobile/(?P\d+)/?$', 'mobile_show' ),
( r'mobile/?$', 'mobile_mumbles' ),
- ( r'embed/(?P\d+)/?$', 'embed' ),
+ ( r'embed/(?P\d+)/?$', 'embed' ),
+ ( r'qrcode/(?P\d+).png', 'qrcode' ),
( r'(?P\d+).json', 'cvp_json' ),
( r'(?P\d+).xml', 'cvp_xml' ),
diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py
index bf5ed51..efb65dc 100644
--- a/pyweb/mumble/views.py
+++ b/pyweb/mumble/views.py
@@ -168,12 +168,20 @@ def show( request, server ):
regformname = "MumbleUserForm"
EXT_FORMS_PROVIDER.register_form( MumbleUserForm )
+ try:
+ import qrencode
+ except ImportError:
+ qravail = False
+ else:
+ qravail = True
+
return render_to_response( 'mumble/mumble.html', {
'MumbleServer': srv,
'ServerDict': simplejson.dumps(serverinfo(request, server)),
'RegForm': regformname,
'MumbleActive': True,
'MumbleAccount':user,
+ 'QRAvailable': qravail,
'IsAdmin': isAdmin,
}, context_instance = RequestContext(request) )
@@ -230,6 +238,24 @@ def showTexture( request, server, userid ):
img.save( buf, "PNG" )
return HttpResponse( buf.getvalue(), "image/png" )
+def qrcode( request, server ):
+ """ Show a QR Coce image that links to the server's embedded page. """
+
+ try:
+ import qrencode
+ except ImportError:
+ return HttpResponse( "oh noez" )
+ else:
+ from django.contrib.sites.models import Site
+ version, size, img = qrencode.encode_scaled( "%s://%s%s" % (
+ { False: "http", True: "https" }[request.is_secure()],
+ Site.objects.get_current().domain,
+ reverse( embed, kwargs={ 'server': server } )
+ ), 100 )
+ buf = StringIO()
+ img.save( buf, "PNG" )
+ return HttpResponse( buf.getvalue(), "image/png" )
+
@EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def get_admin( request, server ):
srv = get_object_or_404( Mumble, id=int(server) )