2013-03-14 01:44:54 +04:00
from django . contrib import admin
from django . utils . translation import ugettext_lazy as _
from lib . main . models import *
2013-03-22 20:01:31 +04:00
from django . contrib . auth . models import User
from django . contrib . auth . admin import UserAdmin
class UserAdmin ( UserAdmin ) :
fieldsets = (
( None , { ' fields ' : ( ' username ' , ' password ' ) } ) ,
( _ ( ' Personal info ' ) , { ' fields ' : ( ' first_name ' , ' last_name ' , ' email ' ) } ) ,
( _ ( ' Permissions ' ) , { ' fields ' : ( ' is_active ' , ' is_staff ' , ' is_superuser ' ) } ) ,
( _ ( ' Important dates ' ) , { ' fields ' : ( ' last_login ' , ' date_joined ' ) } ) ,
)
readonly_fields = ( ' last_login ' , ' date_joined ' )
list_display = ( ' username ' , ' email ' , ' first_name ' , ' last_name ' , ' is_staff ' )
list_filter = ( ' is_staff ' , ' is_superuser ' , ' is_active ' , ' groups ' )
search_fields = ( ' username ' , ' first_name ' , ' last_name ' , ' email ' )
ordering = ( ' username ' , )
try :
admin . site . unregister ( User )
except admin . site . NotRegistered :
pass
admin . site . register ( User , UserAdmin )
# FIXME: Hide auth.Group admin
2013-03-14 01:44:54 +04:00
class OrganizationAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-04-01 07:23:40 +04:00
list_filter = ( ' active ' , ' tags ' )
fieldsets = (
( None , { ' fields ' : ( ' name ' , ' active ' , ' created_by ' , ' description ' , ) } ) ,
( _ ( ' Members ' ) , { ' fields ' : ( ' users ' , ' admins ' , ) } ) ,
( _ ( ' Projects ' ) , { ' fields ' : ( ' projects ' , ) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' audit_trail ' , ) } ) ,
)
readonly_fields = ( ' creation_date ' , ' audit_trail ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' users ' , ' admins ' , ' projects ' , ' tags ' )
2013-03-14 01:57:25 +04:00
2013-04-01 07:23:40 +04:00
class InventoryHostInline ( admin . StackedInline ) :
model = Host
extra = 0
fields = ( ' name ' , ' description ' , ' active ' , ' tags ' )
filter_horizontal = ( ' tags ' , )
class InventoryGroupInline ( admin . StackedInline ) :
model = Group
extra = 0
fields = ( ' name ' , ' description ' , ' active ' , ' parents ' , ' hosts ' , ' tags ' )
filter_horizontal = ( ' parents ' , ' hosts ' , ' tags ' )
2013-03-14 01:57:25 +04:00
class InventoryAdmin ( admin . ModelAdmin ) :
2013-03-23 02:55:10 +04:00
list_display = ( ' name ' , ' organization ' , ' description ' , ' active ' )
list_filter = ( ' organization ' , ' active ' )
2013-04-01 07:23:40 +04:00
fieldsets = (
( None , { ' fields ' : ( ' name ' , ' organization ' , ' active ' , ' created_by ' ,
' description ' , ) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' audit_trail ' , ) } ) ,
)
readonly_fields = ( ' creation_date ' , ' audit_trail ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-04-01 07:23:40 +04:00
inlines = [ InventoryHostInline , InventoryGroupInline ]
2013-03-14 01:57:25 +04:00
2013-03-15 18:21:56 +04:00
class TagAdmin ( admin . ModelAdmin ) :
2013-04-01 07:23:40 +04:00
list_display = ( ' name ' , )
2013-03-15 18:21:56 +04:00
2013-03-24 23:05:34 +04:00
#class AuditTrailAdmin(admin.ModelAdmin):
#
# list_display = ('name', 'description', 'active')
# not currently on model, so disabling for now.
# filter_horizontal = ('tags',)
2013-03-24 23:14:47 +04:00
2013-04-01 07:23:40 +04:00
class VariableDataInline ( admin . StackedInline ) :
model = VariableData
extra = 0
max_num = 1
# FIXME: Doesn't yet work as inline due to the way the OneToOne field is
# defined.
2013-03-15 18:21:56 +04:00
class HostAdmin ( admin . ModelAdmin ) :
2013-03-23 02:55:10 +04:00
list_display = ( ' name ' , ' inventory ' , ' description ' , ' active ' )
list_filter = ( ' inventory ' , ' active ' )
2013-04-01 07:23:40 +04:00
fields = ( ' name ' , ' inventory ' , ' description ' , ' active ' , ' tags ' ,
' created_by ' , ' audit_trail ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-23 02:55:10 +04:00
# FIXME: Edit reverse of many to many for groups.
2013-04-01 07:23:40 +04:00
#inlines = [VariableDataInline]
2013-03-15 18:21:56 +04:00
class GroupAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' parents ' , ' hosts ' , ' tags ' )
2013-04-01 07:23:40 +04:00
#inlines = [VariableDataInline]
2013-03-15 18:21:56 +04:00
class VariableDataAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
class CredentialAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
class TeamAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-24 23:14:47 +04:00
filter_horizontal = ( ' projects ' , ' users ' , ' organizations ' , ' tags ' )
2013-03-15 18:21:56 +04:00
class ProjectAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' inventories ' , ' tags ' )
2013-03-15 18:21:56 +04:00
class PermissionAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
class LaunchJobAdmin ( admin . ModelAdmin ) :
list_display = ( ' name ' , ' description ' , ' active ' )
2013-04-01 07:23:40 +04:00
fieldsets = (
( None , { ' fields ' : ( ' name ' , ' active ' , ' created_by ' , ' description ' ) } ) ,
( _ ( ' Job Parameters ' ) , { ' fields ' : ( ' inventory ' , ' project ' , ' credential ' ,
' user ' , ' job_type ' ) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' audit_trail ' , ) } ) ,
)
readonly_fields = ( ' creation_date ' , ' audit_trail ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
2013-04-01 07:23:40 +04:00
class LaunchJobStatusEventInline ( admin . StackedInline ) :
model = LaunchJobStatusEvent
extra = 0
can_delete = False
fields = ( ' created ' , ' event ' , ' event_data ' )
readonly_fields = ( ' created ' , ' event ' , ' event_data ' )
2013-03-15 18:21:56 +04:00
class LaunchJobStatusAdmin ( admin . ModelAdmin ) :
2013-04-01 07:23:40 +04:00
list_display = ( ' name ' , ' description ' , ' active ' , ' status ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-04-01 07:23:40 +04:00
inlines = [ LaunchJobStatusEventInline ]
2013-03-15 18:21:56 +04:00
2013-03-14 01:57:25 +04:00
# FIXME: Add the rest of the models...
2013-03-14 01:44:54 +04:00
admin . site . register ( Organization , OrganizationAdmin )
2013-03-14 01:57:25 +04:00
admin . site . register ( Inventory , InventoryAdmin )
2013-03-15 18:21:56 +04:00
admin . site . register ( Tag , TagAdmin )
2013-03-24 23:05:34 +04:00
#admin.site.register(AuditTrail, AuditTrailAdmin)
2013-03-15 18:21:56 +04:00
admin . site . register ( Host , HostAdmin )
admin . site . register ( Group , GroupAdmin )
admin . site . register ( VariableData , VariableDataAdmin )
admin . site . register ( Team , TeamAdmin )
admin . site . register ( Project , ProjectAdmin )
admin . site . register ( Credential , CredentialAdmin )
2013-04-01 07:23:40 +04:00
admin . site . register ( LaunchJob , LaunchJobAdmin )
2013-03-15 18:21:56 +04:00
admin . site . register ( LaunchJobStatus , LaunchJobStatusAdmin )