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. 6
      pyweb/mumble/templates/mumble/mumble.html
  2. 1
      pyweb/mumble/urls.py
  3. 26
      pyweb/mumble/views.py

6
pyweb/mumble/templates/mumble/mumble.html

@ -105,7 +105,13 @@
plugins: [ new Ext.ux.TabScrollerMenu() ],
items: [{
title: gettext("Server info"),
{% 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 %},
{

1
pyweb/mumble/urls.py

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

26
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) )

Loading…
Cancel
Save