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.

145 lines
4.0 KiB

16 years ago
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 © 2009-2010, 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 django.conf import settings
  16. from django.contrib import admin
  17. from django.utils.translation import ugettext_lazy as _
  18. from mumble.forms import MumbleServerForm, MumbleAdminForm, MumbleUserAdminForm
  19. from mumble.models import MumbleServer, Mumble, MumbleUser
  20. class MumbleServerAdmin(admin.ModelAdmin):
  21. list_display = [ 'dbus', 'get_murmur_online', 'get_murmur_version' ]
  22. search_fields = [ 'dbus' ]
  23. ordering = [ 'dbus' ]
  24. form = MumbleServerForm
  25. def get_murmur_online( self, obj ):
  26. return obj.online
  27. get_murmur_online.short_description = _('Master is running')
  28. get_murmur_online.boolean = True
  29. def get_murmur_version( self, obj ):
  30. if obj.online:
  31. return obj.prettyversion
  32. return "?"
  33. get_murmur_version.short_description = _("Server version")
  34. class MumbleAdmin(admin.ModelAdmin):
  35. """ Specification for the "Server administration" admin section. """
  36. list_display = [ 'name', 'srvid', 'get_addr', 'get_port', 'get_murmur_online', 'get_booted',
  37. 'get_is_public', 'get_users_regged', 'get_users_online', 'get_channel_count' ];
  38. list_filter = [ 'addr', 'server' ];
  39. search_fields = [ 'name', 'addr', 'port' ];
  40. ordering = [ 'name' ];
  41. form = MumbleAdminForm;
  42. def get_murmur_online( self, obj ):
  43. return obj.server.online
  44. get_murmur_online.short_description = _('Master is running')
  45. get_murmur_online.boolean = True
  46. def get_addr( self, obj ):
  47. if not obj.addr:
  48. return "*"
  49. return obj.addr
  50. get_addr.short_description = _('Server Address')
  51. def get_port( self, obj ):
  52. if not obj.port:
  53. return "< %d >" % (settings.MUMBLE_DEFAULT_PORT + obj.srvid - 1)
  54. return obj.port
  55. get_port.short_description = _('Server Port')
  56. def get_booted( self, obj ):
  57. return obj.booted
  58. get_booted.short_description = _('Instance is running')
  59. get_booted.boolean = True
  60. def get_users_regged( self, obj ):
  61. """ Populates the "Registered users" column. """
  62. if obj.booted:
  63. return obj.users_regged;
  64. else:
  65. return '-';
  66. get_users_regged.short_description = _( 'Registered users' );
  67. def get_users_online( self, obj ):
  68. """ Populates the "Online users" column. """
  69. if obj.booted:
  70. return obj.users_online;
  71. else:
  72. return '-';
  73. get_users_online.short_description = _( 'Online users' );
  74. def get_channel_count( self, obj ):
  75. """ Populates the "Channel Count" column. """
  76. if obj.booted:
  77. return obj.channel_cnt;
  78. else:
  79. return '-';
  80. get_channel_count.short_description = _( 'Channel count' );
  81. def get_is_public( self, obj ):
  82. """ Populates the "Public" column. """
  83. if obj.booted:
  84. if obj.is_public:
  85. return _( 'Yes' );
  86. else:
  87. return _( 'No' );
  88. else:
  89. return '-';
  90. get_is_public.short_description = _( 'Public' );
  91. class MumbleUserAdmin(admin.ModelAdmin):
  92. """ Specification for the "Registered users" admin section. """
  93. list_display = [ 'owner', 'server', 'name', 'get_acl_admin' ];
  94. list_filter = [ 'server' ];
  95. search_fields = [ 'owner__username', 'name' ];
  96. ordering = [ 'owner__username' ];
  97. form = MumbleUserAdminForm
  98. def get_acl_admin( self, obj ):
  99. if obj.server.booted:
  100. return obj.aclAdmin
  101. return None
  102. get_acl_admin.short_description = _('Admin on root channel')
  103. get_acl_admin.boolean = True
  104. admin.site.register( MumbleServer, MumbleServerAdmin );
  105. admin.site.register( Mumble, MumbleAdmin );
  106. admin.site.register( MumbleUser, MumbleUserAdmin );