django-orchestra/orchestra/contrib/vps/admin.py

48 lines
1.6 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
2014-05-08 16:59:35 +00:00
2015-09-21 13:57:15 +00:00
from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin
from orchestra.contrib.accounts.actions import list_accounts
2015-04-05 10:46:24 +00:00
from orchestra.contrib.accounts.admin import AccountAdminMixin
2016-04-06 19:00:16 +00:00
from orchestra.contrib.accounts.filters import IsActiveListFilter
2015-08-05 22:58:35 +00:00
from orchestra.forms import UserCreationForm, NonStoredUserChangeForm
2014-05-08 16:59:35 +00:00
from .models import VPS
@admin.register(VPS)
2015-09-21 13:57:15 +00:00
class VPSAdmin(ChangePasswordAdminMixin, AccountAdminMixin, ExtendedModelAdmin):
2016-04-06 19:00:16 +00:00
list_display = ('hostname', 'type', 'template', 'display_active', 'account_link')
list_filter = ('type', IsActiveListFilter, 'template')
2015-08-05 22:58:35 +00:00
form = NonStoredUserChangeForm
add_form = UserCreationForm
2014-05-08 16:59:35 +00:00
readonly_fields = ('account_link',)
2015-10-07 22:05:00 +00:00
search_fields = ('hostname', 'account__username', 'template')
2015-08-05 22:58:35 +00:00
change_readonly_fields = ('account', 'hostname', 'type', 'template')
2014-05-08 16:59:35 +00:00
fieldsets = (
(None, {
'classes': ('wide',),
2016-04-06 19:00:16 +00:00
'fields': ('account_link', 'hostname', 'type', 'template', 'is_active')
2014-05-08 16:59:35 +00:00
}),
(_("Login"), {
'classes': ('wide',),
'fields': ('password',)
})
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('account', 'hostname', 'type', 'template')
}),
(_("Login"), {
'classes': ('wide',),
'fields': ('password1', 'password2',)
}),
)
actions = (list_accounts,)
2014-05-08 16:59:35 +00:00
2015-09-21 13:57:15 +00:00
def get_change_password_username(self, obj):
return 'root@%s' % obj.hostname
2014-05-08 16:59:35 +00:00