blob: f525e696980a25acf7f25f1d893a9062dc83000a [file] [log] [blame]
# admin.py - ActiveTest Django Admin
from core.admin import ReadOnlyAwareAdmin, SliceInline
from core.middleware import get_request
from core.models import User
from django import forms
from django.contrib import admin
from services.activetest.models import *
class ActiveTestForm(forms.ModelForm):
class Meta:
model = ActiveTestService
fields = '__all__'
class ActiveTestAdmin(ReadOnlyAwareAdmin):
model = ActiveTestService
verbose_name = ACTIVETEST_SERVICE_NAME_VERBOSE
verbose_name_plural = ACTIVETEST_SERVICE_NAME_VERBOSE_PLURAL
form = ActiveTestForm
inlines = [SliceInline]
list_display = ('backend_status_icon', 'name', 'enabled')
list_display_links = ('backend_status_icon', 'name' )
fieldsets = [(None, {
'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'description',],
'classes':['suit-tab suit-tab-general',],
})]
readonly_fields = ('backend_status_text', )
user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
extracontext_registered_admins = True
suit_form_tabs = (
('general', 'ActiveTest Details', ),
('slices', 'Slices',),
)
suit_form_includes = ((
'top',
'administration'),
)
def get_queryset(self, request):
return ActiveTestService.get_service_objects_by_user(request.user)
admin.site.register(ActiveTestService, ActiveTestAdmin)
class ActiveTestTenantForm(forms.ModelForm):
class Meta:
model = ActiveTestTenant
fields = '__all__'
creator = forms.ModelChoiceField(queryset=User.objects.all())
def __init__(self, *args, **kwargs):
super(ActiveTestTenantForm, self).__init__(*args, **kwargs)
self.fields['kind'].widget.attrs['readonly'] = True
self.fields['kind'].initial = ACTIVETEST_KIND
self.fields['provider_service'].queryset = ActiveTestService.get_service_objects().all()
if self.instance:
self.fields['creator'].initial = self.instance.creator
if (not self.instance) or (not self.instance.pk):
self.fields['creator'].initial = get_request().user
if ActiveTestService.get_service_objects().exists():
self.fields['provider_service'].initial = ActiveTestService.get_service_objects().all()[0]
def save(self, commit=True):
self.instance.creator = self.cleaned_data.get('creator')
return super(ActiveTestTenantForm, self).save(commit=commit)
class ActiveTestTenantAdmin(ReadOnlyAwareAdmin):
verbose_name = ACTIVETEST_TENANT_NAME_VERBOSE
verbose_name_plural = ACTIVETEST_TENANT_NAME_VERBOSE_PLURAL
list_display = ('id', 'backend_status_icon', 'instance')
list_display_links = ('backend_status_icon', 'instance', 'id')
fieldsets = [(None, {
'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator'],
'classes': ['suit-tab suit-tab-general'],
})]
readonly_fields = ('backend_status_text', 'instance',)
form = ActiveTestTenantForm
suit_form_tabs = (('general', 'Details'),)
def get_queryset(self, request):
return ActiveTestTenant.get_tenant_objects_by_user(request.user)
admin.site.register(ActiveTestTenant, ActiveTestTenantAdmin)
########################################################################################
"""
class VpmaForm(forms.ModelForm):
class Meta:
model = VpmaService
fields = '__all__'
class VpmaAdmin(ReadOnlyAwareAdmin):
model = VpmaService
verbose_name = VPMA_SERVICE_NAME_VERBOSE
verbose_name_plural = VPMA_SERVICE_NAME_VERBOSE_PLURAL
form = VpmaForm
inlines = [SliceInline]
list_display = ('backend_status_icon', 'name', 'enabled')
list_display_links = ('backend_status_icon', 'name' )
fieldsets = [(None, {
'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'description',],
'classes':['suit-tab suit-tab-general',],
})]
readonly_fields = ('backend_status_text', )
user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
extracontext_registered_admins = True
suit_form_tabs = (
('general', 'Vpma Details', ),
('slices', 'Slices',),
)
suit_form_includes = ((
'top',
'administration'),
)
def get_queryset(self, request):
return VpmaService.get_service_objects_by_user(request.user)
admin.site.register(VpmaService, VpmaAdmin)
"""
class Qt600TenantForm(forms.ModelForm):
class Meta:
model = Qt600Tenant
fields = '__all__'
creator = forms.ModelChoiceField(queryset=User.objects.all())
def __init__(self, *args, **kwargs):
super(Qt600TenantForm, self).__init__(*args, **kwargs)
self.fields['kind'].widget.attrs['readonly'] = True
self.fields['kind'].initial = ACTIVETEST_KIND
self.fields['provider_service'].queryset = Qt600Service.get_service_objects().all()
if self.instance:
self.fields['creator'].initial = self.instance.creator
self.fields['is_reflector'].initial = self.instance.is_reflector
self.fields['is_initiator'].initial = self.instance.is_initiator
self.fields['reflector'].initial = self.instance.reflector
if (not self.instance) or (not self.instance.pk):
self.fields['creator'].initial = get_request().user
if Qt600Service.get_service_objects().exists():
self.fields['provider_service'].initial = Qt600Service.get_service_objects().all()[0]
def save(self, commit=True):
self.instance.creator = self.cleaned_data.get('creator')
self.instance.is_reflector = self.cleaned_data.get('is_reflector')
self.instance.is_initiator = self.cleaned_data.get('is_initiator')
self.instance.reflector = self.cleaned_data.get('reflector')
return super(Qt600TenantForm, self).save(commit=commit)
class Qt600TenantAdmin(ReadOnlyAwareAdmin):
verbose_name = QT600_TENANT_NAME_VERBOSE
verbose_name_plural = QT600_TENANT_NAME_VERBOSE_PLURAL
list_display = ('id', 'backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector')
list_display_links = ('backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector', 'id')
fieldsets = [(None, {
'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'is_reflector', 'is_initiator', 'reflector'],
'classes': ['suit-tab suit-tab-general'],
})]
readonly_fields = ('backend_status_text', 'instance',)
form = Qt600TenantForm
suit_form_tabs = (('general', 'Details'),)
def get_queryset(self, request):
return Qt600Tenant.get_tenant_objects_by_user(request.user)
admin.site.register(Qt600Tenant, Qt600TenantAdmin)
class VpmaTenantForm(forms.ModelForm):
class Meta:
model = VpmaTenant
fields = '__all__'
creator = forms.ModelChoiceField(queryset=User.objects.all())
def __init__(self, *args, **kwargs):
super(VpmaTenantForm, self).__init__(*args, **kwargs)
self.fields['kind'].widget.attrs['readonly'] = True
self.fields['kind'].initial = ACTIVETEST_KIND
self.fields['provider_service'].queryset = VpmaService.get_service_objects().all()
if self.instance:
self.fields['creator'].initial = self.instance.creator
self.fields['is_reflector'].initial = self.instance.is_reflector
self.fields['is_initiator'].initial = self.instance.is_initiator
self.fields['reflector'].initial = self.instance.reflector
if (not self.instance) or (not self.instance.pk):
self.fields['creator'].initial = get_request().user
if VpmaService.get_service_objects().exists():
self.fields['provider_service'].initial = VpmaService.get_service_objects().all()[0]
def save(self, commit=True):
self.instance.creator = self.cleaned_data.get('creator')
self.instance.is_reflector = self.cleaned_data.get('is_reflector')
self.instance.is_initiator = self.cleaned_data.get('is_initiator')
self.instance.reflector = self.cleaned_data.get('reflector')
return super(VpmaTenantForm, self).save(commit=commit)
class VpmaTenantAdmin(ReadOnlyAwareAdmin):
verbose_name = VPMA_TENANT_NAME_VERBOSE
verbose_name_plural = VPMA_TENANT_NAME_VERBOSE_PLURAL
list_display = ('id', 'backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector')
list_display_links = ('backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector', 'id')
fieldsets = [(None, {
'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'is_reflector', 'is_initiator', 'reflector'],
'classes': ['suit-tab suit-tab-general'],
})]
readonly_fields = ('backend_status_text', 'instance',)
form = VpmaTenantForm
suit_form_tabs = (('general', 'Details'),)
def get_queryset(self, request):
return VpmaTenant.get_tenant_objects_by_user(request.user)
admin.site.register(VpmaTenant, VpmaTenantAdmin)