Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.6 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  4. *
  5. * Mumble-Django is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This package is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. """
  15. from StringIO import StringIO
  16. from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
  17. from django.template import RequestContext
  18. from django.http import Http404, HttpResponse, HttpResponseRedirect
  19. from django.core.urlresolvers import reverse
  20. from django.contrib.auth.decorators import login_required
  21. from models import Mumble, MumbleUser
  22. from forms import *
  23. from mmobjects import *
  24. def mumbles( request ):
  25. "Displays a list of all configured Mumble servers, or redirects if only one configured."
  26. mumbles = get_list_or_404( Mumble );
  27. if len(mumbles) == 1:
  28. return HttpResponseRedirect( '/mumble/%d' % mumbles[0].id );
  29. return render_to_response(
  30. 'mumble/list.htm',
  31. { 'MumbleObjects': mumbles,
  32. 'MumbleActive': True,
  33. },
  34. context_instance = RequestContext(request)
  35. );
  36. def show( request, server ):
  37. "Displays the channel list for the given Server ID."
  38. srv = get_object_or_404( Mumble, id=server );
  39. isAdmin = srv.isUserAdmin( request.user );
  40. # The tab to start on.
  41. displayTab = 0;
  42. if isAdmin:
  43. if request.method == 'POST' and "mode" in request.POST and request.POST['mode'] == 'admin':
  44. adminform = MumbleForm( request.POST, instance=srv );
  45. # In case we redisplay the page, it was displayed with errors on the admin form, so tell
  46. # Ext to show the admin form tab first.
  47. displayTab = 1;
  48. if adminform.is_valid():
  49. adminform.save();
  50. return HttpResponseRedirect( '/mumble/%d' % int(server) );
  51. else:
  52. adminform = MumbleForm( instance=srv );
  53. else:
  54. adminform = None;
  55. registered = False;
  56. user = None;
  57. if request.user.is_authenticated():
  58. if request.method == 'POST' and 'mode' in request.POST and request.POST['mode'] == 'reg':
  59. try:
  60. user = MumbleUser.objects.get( server=srv, owner=request.user );
  61. except MumbleUser.DoesNotExist:
  62. regform = MumbleUserForm( request.POST );
  63. if regform.is_valid():
  64. model = regform.save( commit=False );
  65. model.isAdmin = False;
  66. model.server = srv;
  67. model.owner = request.user;
  68. model.save();
  69. return HttpResponseRedirect( '/mumble/%d' % int(server) );
  70. else:
  71. regform = MumbleUserForm( request.POST, instance=user );
  72. if regform.is_valid():
  73. regform.save();
  74. return HttpResponseRedirect( '/mumble/%d' % int(server) );
  75. else:
  76. try:
  77. user = MumbleUser.objects.get( server=srv, owner=request.user );
  78. except MumbleUser.DoesNotExist:
  79. regform = MumbleUserForm();
  80. else:
  81. regform = MumbleUserForm( instance=user );
  82. registered = True;
  83. if request.method == 'POST' and 'mode' in request.POST and request.POST['mode'] == 'texture' and registered:
  84. textureform = MumbleTextureForm( request.POST, request.FILES );
  85. if textureform.is_valid():
  86. user.setTexture( request.FILES['texturefile'] );
  87. return HttpResponseRedirect( '/mumble/%d' % int(server) );
  88. else:
  89. textureform = MumbleTextureForm();
  90. else:
  91. regform = None;
  92. textureform = None;
  93. # ChannelTable is a somewhat misleading name, as it actually contains channels and players.
  94. channelTable = [];
  95. for id in srv.channels:
  96. if id != 0 and srv.channels[id].show:
  97. channelTable.append( srv.channels[id] );
  98. for id in srv.players:
  99. channelTable.append( srv.players[id] );
  100. return render_to_response(
  101. 'mumble/mumble.htm',
  102. {
  103. 'DBaseObject': srv,
  104. 'ChannelTable': channelTable,
  105. 'CurrentUserIsAdmin': isAdmin,
  106. 'AdminForm': adminform,
  107. 'RegForm': regform,
  108. 'TextureForm': textureform,
  109. 'Registered': registered,
  110. 'DisplayTab': displayTab,
  111. 'MumbleActive': True,
  112. 'MumbleAccount':user,
  113. },
  114. context_instance = RequestContext(request)
  115. );
  116. def showTexture( request, server ):
  117. if request.user.is_authenticated():
  118. srv = Mumble.objects.get( id=int(server) );
  119. user = MumbleUser.objects.get( server=srv, owner=request.user );
  120. try:
  121. img = user.getTexture();
  122. except ValueError:
  123. raise Http404();
  124. else:
  125. buffer = StringIO();
  126. img.save( buffer, "PNG" );
  127. return HttpResponse( buffer.getvalue(), "image/png" );
  128. raise Http404();