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.

115 lines
3.1 KiB

16 years ago
  1. from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
  2. from django.template import RequestContext
  3. from django.http import HttpResponseRedirect
  4. from django.core.urlresolvers import reverse
  5. from django.contrib.auth.decorators import login_required
  6. from models import Mumble, MumbleUser
  7. from mmobjects import mmServer, mmChannel
  8. import dingenskirchen;
  9. class Storage( object ):
  10. s = list();
  11. r = None;
  12. def show( request, server ):
  13. "Displays the channel list for the given Server ID."
  14. srv, o = createChannelList( server );
  15. return render_to_response(
  16. 'mumble/mumble.htm',
  17. { 'DBaseObject': srv, 'ServerObject': o, 'ChannelTable': Storage.s },
  18. context_instance = RequestContext(request)
  19. );
  20. def showContent( server, user = None ):
  21. "Renders and returns the channel list for the given Server ID."
  22. from django.template import Context, loader
  23. srv, o = createChannelList( server );
  24. mumbleAcc = None;
  25. if user is not None:
  26. mmUsers = MumbleUser.objects.filter( owner = user );
  27. if mmUsers:
  28. mumbleAcc = mmUsers[0];
  29. t_content = loader.get_template( 'mumble/content.htm' );
  30. c_content = Context( { 'DBaseObject': srv, 'ServerObject': o, 'ChannelTable': Storage.s, 'user': user, 'mumbleAccount': mumbleAcc } );
  31. r_content = t_content.render( c_content );
  32. return r_content;
  33. def createChannelList( server ):
  34. "Renders the channel list."
  35. srv = get_object_or_404( Mumble, id=server );
  36. o = srv.getServerObject();
  37. Storage.s = list();
  38. Storage.r = o.channels[0];
  39. o.channels[0].visit( renderListItem, 0 );
  40. return srv, o;
  41. def renderListItem( item, level ):
  42. "Stores a line in the channel list."
  43. if item == Storage.r:
  44. return;
  45. # Filter channels that don't have players in them and are not a subchannel of root
  46. if level > 1 and item.playerCount == 0:
  47. # I used to test if item is an instance of mmChannel here. For some reason, that doesn't work. Dunno why.
  48. return;
  49. if isinstance( item, mmChannel ):
  50. Storage.s.append( ( level, item, item.parentChannels() ) );
  51. else:
  52. Storage.s.append( ( level, item ) );
  53. @login_required
  54. def register( request, server ):
  55. # Register the current user with this mumble server, or give them a form to change their registration data.
  56. srv = Mumble.objects.get( id=server );
  57. if request.user.is_authenticated():
  58. reg = MumbleUser.objects.get( server=srv, owner=request.user );
  59. else:
  60. reg = None;
  61. return render_to_response(
  62. 'mumble/reg.htm',
  63. { 'Mumble': srv, 'Reg': reg },
  64. context_instance = RequestContext(request)
  65. );
  66. @login_required
  67. def savereg( request ):
  68. #if not request.user.is_authenticated():
  69. # raise Exception, "You need to be logged in to register yourself with Mumble.";
  70. srv = Mumble.objects.get( id=request.POST['id'] );
  71. reg = MumbleUser.objects.get( server=srv, owner=request.user );
  72. if reg is None:
  73. reg = MumbleUser( name=request.POST['username'], password=request.POST['password'], server=srv, owner=request.user );
  74. else:
  75. reg.name = request.POST['username'];
  76. reg.password = request.POST['password'];
  77. reg.save();
  78. return HttpResponseRedirect( "/mumble/%d" % srv.id );