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.

188 lines
5.5 KiB

16 years ago
16 years ago
16 years ago
16 years ago
13 years ago
  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. from django.conf import settings
  17. from django.contrib import admin
  18. from django.utils.translation import ugettext_lazy as _
  19. from mumble.forms import MumbleServerForm, MumbleAdminForm, MumbleUserAdminForm
  20. from mumble.models import MumbleServer, Mumble, MumbleUser
  21. class MumbleServerAdmin(admin.ModelAdmin):
  22. list_display = [ 'dbus', 'get_murmur_online', 'get_murmur_version' ]
  23. search_fields = [ 'dbus' ]
  24. ordering = [ 'dbus' ]
  25. form = MumbleServerForm
  26. def get_murmur_online( self, obj ):
  27. return obj.online
  28. get_murmur_online.short_description = _('Master is running')
  29. get_murmur_online.boolean = True
  30. def get_murmur_version( self, obj ):
  31. if obj.online:
  32. return obj.prettyversion
  33. return "?"
  34. get_murmur_version.short_description = _("Server version")
  35. class MumbleAdmin(admin.ModelAdmin):
  36. """ Specification for the "Server administration" admin section. """
  37. list_display = [ 'name', 'srvid', 'get_addr', 'get_port', 'get_murmur_online', 'get_booted',
  38. 'get_is_public', 'get_users_online' ]
  39. list_filter = [ 'addr', 'server' ]
  40. search_fields = [ 'name', 'addr', 'port' ]
  41. ordering = [ 'name' ]
  42. actions = [ 'start', 'stop', 'restart', 'enable_autoboot', 'disable_autoboot' ]
  43. form = MumbleAdminForm
  44. def get_murmur_online( self, obj ):
  45. return obj.server.online
  46. get_murmur_online.short_description = _('Master is running')
  47. get_murmur_online.boolean = True
  48. def get_addr( self, obj ):
  49. if not obj.addr:
  50. return "*"
  51. return obj.addr
  52. get_addr.short_description = _('Server Address')
  53. def get_port( self, obj ):
  54. if not obj.port:
  55. return '< %d >' % (obj.server.defaultPort + obj.srvid - 1)
  56. return obj.port
  57. get_port.short_description = _('Server Port')
  58. def get_booted( self, obj ):
  59. return obj.booted
  60. get_booted.short_description = _('Instance is running')
  61. get_booted.boolean = True
  62. def get_users_regged( self, obj ):
  63. """ Populates the "Registered users" column. """
  64. if obj.booted:
  65. return obj.users_regged
  66. else:
  67. return '-'
  68. get_users_regged.short_description = _( 'Registered users' )
  69. def get_users_online( self, obj ):
  70. """ Populates the "Online users" column. """
  71. if obj.booted:
  72. return obj.users_online
  73. else:
  74. return '-'
  75. get_users_online.short_description = _( 'Online users' )
  76. def get_channel_count( self, obj ):
  77. """ Populates the "Channel Count" column. """
  78. if obj.booted:
  79. return obj.channel_cnt
  80. else:
  81. return '-'
  82. get_channel_count.short_description = _( 'Channel count' )
  83. def get_is_public( self, obj ):
  84. """ Populates the "Public" column. """
  85. if obj.booted:
  86. if obj.is_public:
  87. return _( 'Yes' )
  88. else:
  89. return _( 'No' )
  90. else:
  91. return '-'
  92. get_is_public.short_description = _( 'Public' )
  93. def start(self, request, queryset):
  94. for mm in queryset:
  95. mm.setBooted(True)
  96. start.short_description = _( "Start server instance" )
  97. def stop(self, request, queryset):
  98. for mm in queryset:
  99. mm.setBooted(False)
  100. stop.short_description = _( "Stop server instance" )
  101. def restart(self, request, queryset):
  102. for mm in queryset:
  103. mm.setBooted(False)
  104. mm.setBooted(True)
  105. restart.short_description = _( "Restart server instance" )
  106. def enable_autoboot(self, request, queryset):
  107. for mm in queryset:
  108. mm.autoboot = True
  109. enable_autoboot.short_description = _( "Enable autoboot" )
  110. def disable_autoboot(self, request, queryset):
  111. for mm in queryset:
  112. mm.autoboot = False
  113. disable_autoboot.short_description = _( "Disable autoboot" )
  114. class MumbleUserAdmin(admin.ModelAdmin):
  115. """ Specification for the "Registered users" admin section. """
  116. list_display = [ 'name', 'server', 'owner', 'mumbleid', 'get_acl_admin' ]
  117. list_filter = [ 'server' ]
  118. search_fields = [ 'owner__username', 'name' ]
  119. actions = [ 'set_texture_from_gravatar' ]
  120. ordering = [ 'owner__username' ]
  121. form = MumbleUserAdminForm
  122. def get_acl_admin( self, obj ):
  123. if obj.server.booted:
  124. return obj.aclAdmin
  125. return None
  126. get_acl_admin.short_description = _('Admin on root channel')
  127. get_acl_admin.boolean = True
  128. def set_texture_from_gravatar( self, request, queryset ):
  129. for mu in queryset:
  130. mu.setTextureFromGravatar()
  131. set_texture_from_gravatar.short_description = _( "Set Gravatar as Texture" )
  132. admin.site.register( MumbleServer, MumbleServerAdmin )
  133. admin.site.register( Mumble, MumbleAdmin )
  134. admin.site.register( MumbleUser, MumbleUserAdmin )