Browse Source

if qrencode is available, display a QR code for the channel viewer

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
e49990f300
  1. 8
      pyweb/mumble/templates/mumble/mumble.html
  2. 3
      pyweb/mumble/urls.py
  3. 26
      pyweb/mumble/views.py

8
pyweb/mumble/templates/mumble/mumble.html

@ -105,7 +105,13 @@
plugins: [ new Ext.ux.TabScrollerMenu() ], plugins: [ new Ext.ux.TabScrollerMenu() ],
items: [{ items: [{
title: gettext("Server info"), title: gettext("Server info"),
html: renderserverinfos( {{ ServerDict|safe }} )
{% if QRAvailable %}
html: ('<img src="{% url mumble.views.qrcode MumbleServer.id %}" ' +
'style="float: right" alt="QR Code for embedded view"/>' +
renderserverinfos( {{ ServerDict|safe }} ))
{% else %}
html: renderserverinfos( {{ ServerDict|safe }} )
{% endif %}
} }
{% if user.is_authenticated %}, {% if user.is_authenticated %},
{ {

3
pyweb/mumble/urls.py

@ -37,7 +37,8 @@ urlpatterns = patterns(
( r'mobile/(?P<server>\d+)/?$', 'mobile_show' ), ( r'mobile/(?P<server>\d+)/?$', 'mobile_show' ),
( r'mobile/?$', 'mobile_mumbles' ), ( r'mobile/?$', 'mobile_mumbles' ),
( r'embed/(?P<server>\d+)/?$', 'embed' ),
( r'embed/(?P<server>\d+)/?$', 'embed' ),
( r'qrcode/(?P<server>\d+).png', 'qrcode' ),
( r'(?P<server>\d+).json', 'cvp_json' ), ( r'(?P<server>\d+).json', 'cvp_json' ),
( r'(?P<server>\d+).xml', 'cvp_xml' ), ( r'(?P<server>\d+).xml', 'cvp_xml' ),

26
pyweb/mumble/views.py

@ -168,12 +168,20 @@ def show( request, server ):
regformname = "MumbleUserForm" regformname = "MumbleUserForm"
EXT_FORMS_PROVIDER.register_form( MumbleUserForm ) EXT_FORMS_PROVIDER.register_form( MumbleUserForm )
try:
import qrencode
except ImportError:
qravail = False
else:
qravail = True
return render_to_response( 'mumble/mumble.html', { return render_to_response( 'mumble/mumble.html', {
'MumbleServer': srv, 'MumbleServer': srv,
'ServerDict': simplejson.dumps(serverinfo(request, server)), 'ServerDict': simplejson.dumps(serverinfo(request, server)),
'RegForm': regformname, 'RegForm': regformname,
'MumbleActive': True, 'MumbleActive': True,
'MumbleAccount':user, 'MumbleAccount':user,
'QRAvailable': qravail,
'IsAdmin': isAdmin, 'IsAdmin': isAdmin,
}, context_instance = RequestContext(request) ) }, context_instance = RequestContext(request) )
@ -230,6 +238,24 @@ def showTexture( request, server, userid ):
img.save( buf, "PNG" ) img.save( buf, "PNG" )
return HttpResponse( buf.getvalue(), "image/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" ) @EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def get_admin( request, server ): def get_admin( request, server ):
srv = get_object_or_404( Mumble, id=int(server) ) srv = get_object_or_404( Mumble, id=int(server) )

Loading…
Cancel
Save