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.

146 lines
4.3 KiB

16 years ago
16 years ago
16 years ago
16 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. form = MumbleAdminForm
  43. def get_murmur_online( self, obj ):
  44. return obj.server.online
  45. get_murmur_online.short_description = _('Master is running')
  46. get_murmur_online.boolean = True
  47. def get_addr( self, obj ):
  48. if not obj.addr:
  49. return "*"
  50. return obj.addr
  51. get_addr.short_description = _('Server Address')
  52. def get_port( self, obj ):
  53. if not obj.port:
  54. return '< %d >' % (obj.server.defaultPort + obj.srvid - 1)
  55. return obj.port
  56. get_port.short_description = _('Server Port')
  57. def get_booted( self, obj ):
  58. return obj.booted
  59. get_booted.short_description = _('Instance is running')
  60. get_booted.boolean = True
  61. def get_users_regged( self, obj ):
  62. """ Populates the "Registered users" column. """
  63. if obj.booted:
  64. return obj.users_regged
  65. else:
  66. return '-'
  67. get_users_regged.short_description = _( 'Registered users' )
  68. def get_users_online( self, obj ):
  69. """ Populates the "Online users" column. """
  70. if obj.booted:
  71. return obj.users_online
  72. else:
  73. return '-'
  74. get_users_online.short_description = _( 'Online users' )
  75. def get_channel_count( self, obj ):
  76. """ Populates the "Channel Count" column. """
  77. if obj.booted:
  78. return obj.channel_cnt
  79. else:
  80. return '-'
  81. get_channel_count.short_description = _( 'Channel count' )
  82. def get_is_public( self, obj ):
  83. """ Populates the "Public" column. """
  84. if obj.booted:
  85. if obj.is_public:
  86. return _( 'Yes' )
  87. else:
  88. return _( 'No' )
  89. else:
  90. return '-'
  91. get_is_public.short_description = _( 'Public' )
  92. class MumbleUserAdmin(admin.ModelAdmin):
  93. """ Specification for the "Registered users" admin section. """
  94. list_display = [ 'owner', 'server', 'name', 'mumbleid', 'get_acl_admin' ]
  95. list_filter = [ 'server' ]
  96. search_fields = [ 'owner__username', 'name' ]
  97. ordering = [ 'owner__username' ]
  98. form = MumbleUserAdminForm
  99. def get_acl_admin( self, obj ):
  100. if obj.server.booted:
  101. return obj.aclAdmin
  102. return None
  103. get_acl_admin.short_description = _('Admin on root channel')
  104. get_acl_admin.boolean = True
  105. admin.site.register( MumbleServer, MumbleServerAdmin )
  106. admin.site.register( Mumble, MumbleAdmin )
  107. admin.site.register( MumbleUser, MumbleUserAdmin )