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.

119 lines
3.3 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. form = MumbleServerForm
  22. class MumbleAdmin(admin.ModelAdmin):
  23. """ Specification for the "Server administration" admin section. """
  24. list_display = [ 'name', 'srvid', 'get_addr', 'get_port', 'get_booted', 'get_is_public',
  25. 'get_users_regged', 'get_users_online', 'get_channel_count' ];
  26. list_filter = [ 'addr', 'server' ];
  27. search_fields = [ 'name', 'addr', 'port' ];
  28. ordering = [ 'name' ];
  29. form = MumbleAdminForm;
  30. def get_addr( self, obj ):
  31. if not obj.addr:
  32. return "*"
  33. get_addr.short_description = _('Server Address')
  34. def get_port( self, obj ):
  35. if not obj.port:
  36. return "< %d >" % (settings.MUMBLE_DEFAULT_PORT + obj.srvid - 1)
  37. return obj.port
  38. get_port.short_description = _('Server Port')
  39. def get_booted( self, obj ):
  40. return obj.booted
  41. get_booted.short_description = _('Boot Server')
  42. get_booted.boolean = True
  43. def get_users_regged( self, obj ):
  44. """ Populates the "Registered users" column. """
  45. if obj.booted:
  46. return obj.users_regged;
  47. else:
  48. return '-';
  49. get_users_regged.short_description = _( 'Registered users' );
  50. def get_users_online( self, obj ):
  51. """ Populates the "Online users" column. """
  52. if obj.booted:
  53. return obj.users_online;
  54. else:
  55. return '-';
  56. get_users_online.short_description = _( 'Online users' );
  57. def get_channel_count( self, obj ):
  58. """ Populates the "Channel Count" column. """
  59. if obj.booted:
  60. return obj.channel_cnt;
  61. else:
  62. return '-';
  63. get_channel_count.short_description = _( 'Channel count' );
  64. def get_is_public( self, obj ):
  65. """ Populates the "Public" column. """
  66. if obj.booted:
  67. if obj.is_public:
  68. return _( 'Yes' );
  69. else:
  70. return _( 'No' );
  71. else:
  72. return '-';
  73. get_is_public.short_description = _( 'Public' );
  74. class MumbleUserAdmin(admin.ModelAdmin):
  75. """ Specification for the "Registered users" admin section. """
  76. list_display = [ 'owner', 'server', 'name', 'get_acl_admin' ];
  77. list_filter = [ 'server' ];
  78. search_fields = [ 'owner__username', 'name' ];
  79. ordering = [ 'owner__username' ];
  80. form = MumbleUserAdminForm
  81. def get_acl_admin( self, obj ):
  82. return obj.aclAdmin
  83. get_acl_admin.short_description = _('Admin on root channel')
  84. get_acl_admin.boolean = True
  85. admin.site.register( MumbleServer, MumbleServerAdmin );
  86. admin.site.register( Mumble, MumbleAdmin );
  87. admin.site.register( MumbleUser, MumbleUserAdmin );