2013-04-02 00:04:27 +04:00
# Copyright (c) 2013 AnsibleWorks, Inc.
#
2013-04-09 09:05:55 +04:00
# This file is part of Ansible Commander.
#
2013-04-02 00:04:27 +04:00
# Ansible Commander is free software: you can redistribute it and/or modify
2013-04-09 09:05:55 +04:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
2013-04-02 00:04:27 +04:00
#
2013-04-09 09:05:55 +04:00
# Ansible Commander is distributed in the hope that it will be useful,
2013-04-02 00:04:27 +04:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2013-04-09 09:05:55 +04:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible Commander. If not, see <http://www.gnu.org/licenses/>.
2013-04-02 00:04:27 +04:00
2013-04-05 00:53:20 +04:00
2013-04-16 03:22:57 +04:00
import json
2013-04-18 02:59:21 +04:00
import urllib
2013-04-16 03:22:57 +04:00
2013-04-05 00:53:20 +04:00
from django . conf . urls import *
2013-03-14 01:44:54 +04:00
from django . contrib import admin
2013-04-05 00:53:20 +04:00
from django . contrib . admin . util import unquote
from django . contrib import messages
from django . core . urlresolvers import reverse
from django . http import HttpResponseRedirect
2013-04-20 02:11:31 +04:00
from django . utils . timezone import now
2013-03-14 01:44:54 +04:00
from django . utils . translation import ugettext_lazy as _
2013-04-16 03:22:57 +04:00
from django . utils . html import format_html
2013-03-14 01:44:54 +04:00
from lib . main . models import *
2013-04-19 18:12:45 +04:00
from lib . main . forms import *
2013-03-14 01:44:54 +04:00
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-04-18 02:59:21 +04:00
class BaseModelAdmin ( admin . ModelAdmin ) :
def save_model ( self , request , obj , form , change ) :
# Automatically set created_by when saved from the admin.
# FIXME: Doesn't handle inline model instances yet.
if hasattr ( obj , ' created_by ' ) and obj . created_by is None :
obj . created_by = request . user
return super ( BaseModelAdmin , self ) . save_model ( request , obj , form , change )
class OrganizationAdmin ( BaseModelAdmin ) :
2013-03-14 01:44:54 +04:00
list_display = ( ' name ' , ' description ' , ' active ' )
2013-04-01 07:23:40 +04:00
list_filter = ( ' active ' , ' tags ' )
fieldsets = (
2013-04-19 18:12:45 +04:00
( None , { ' fields ' : ( ( ' name ' , ' active ' ) , ' description ' , ) } ) ,
2013-04-01 07:23:40 +04:00
( _ ( ' Members ' ) , { ' fields ' : ( ' users ' , ' admins ' , ) } ) ,
( _ ( ' Projects ' ) , { ' fields ' : ( ' projects ' , ) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
2013-04-19 18:12:45 +04:00
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' ,
' audit_trail ' , ) } ) ,
2013-04-01 07:23:40 +04:00
)
2013-04-18 02:59:21 +04:00
readonly_fields = ( ' creation_date ' , ' created_by ' , ' 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-04-18 02:59:21 +04:00
class InventoryAdmin ( BaseModelAdmin ) :
2013-03-14 01:57:25 +04:00
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 = (
2013-04-19 18:12:45 +04:00
( None , { ' fields ' : ( ( ' name ' , ' active ' ) , ' organization ' , ' description ' , ) } ) ,
2013-04-01 07:23:40 +04:00
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
2013-04-19 18:12:45 +04:00
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' , ' audit_trail ' , ) } ) ,
2013-04-01 07:23:40 +04:00
)
2013-04-18 02:59:21 +04:00
readonly_fields = ( ' creation_date ' , ' created_by ' , ' 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-04-18 02:59:21 +04:00
class TagAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
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-04-18 02:59:21 +04:00
class JobHostSummaryInline ( admin . TabularInline ) :
2013-04-16 03:22:57 +04:00
2013-04-18 02:59:21 +04:00
model = JobHostSummary
2013-04-16 03:22:57 +04:00
extra = 0
can_delete = False
def has_add_permission ( self , request ) :
return False
2013-04-18 02:59:21 +04:00
class JobEventInline ( admin . StackedInline ) :
2013-04-16 03:22:57 +04:00
2013-04-18 02:59:21 +04:00
model = JobEvent
2013-04-16 03:22:57 +04:00
extra = 0
can_delete = False
def has_add_permission ( self , request ) :
return False
def get_event_data_display ( self , obj ) :
2013-04-18 02:59:21 +04:00
return format_html ( ' <pre class= " json-display " > {0} </pre> ' ,
json . dumps ( obj . event_data , indent = 4 ) )
2013-04-16 03:22:57 +04:00
get_event_data_display . short_description = _ ( ' Event data ' )
get_event_data_display . allow_tags = True
2013-04-18 02:59:21 +04:00
class JobHostSummaryInlineForHost ( JobHostSummaryInline ) :
2013-04-16 03:22:57 +04:00
2013-04-18 02:59:21 +04:00
fields = ( ' job ' , ' changed ' , ' dark ' , ' failures ' , ' ok ' , ' processed ' ,
' skipped ' )
readonly_fields = ( ' job ' , ' changed ' , ' dark ' , ' failures ' , ' ok ' , ' processed ' ,
' skipped ' )
2013-04-16 03:22:57 +04:00
2013-04-18 02:59:21 +04:00
class JobEventInlineForHost ( JobEventInline ) :
2013-04-16 03:22:57 +04:00
2013-04-18 02:59:21 +04:00
fields = ( ' job ' , ' created ' , ' event ' , ' get_event_data_display ' )
readonly_fields = ( ' job ' , ' created ' , ' event ' , ' get_event_data_display ' )
2013-04-16 03:22:57 +04:00
2013-04-18 02:59:21 +04:00
class HostAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
2013-03-23 02:55:10 +04:00
list_display = ( ' name ' , ' inventory ' , ' description ' , ' active ' )
list_filter = ( ' inventory ' , ' active ' )
2013-04-19 18:12:45 +04:00
#form = HostAdminForm
fieldsets = (
( None , { ' fields ' : ( ( ' name ' , ' active ' ) , ' inventory ' , ' description ' , #'vdata'
) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' , ' audit_trail ' , ) } ) ,
)
2013-04-18 02:59:21 +04:00
readonly_fields = ( ' creation_date ' , ' 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-04-18 02:59:21 +04:00
inlines = [ JobHostSummaryInlineForHost , JobEventInlineForHost ]
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
class GroupAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
list_display = ( ' name ' , ' description ' , ' active ' )
2013-04-19 18:12:45 +04:00
fieldsets = (
( None , { ' fields ' : ( ( ' name ' , ' active ' ) , ' inventory ' , ' description ' ,
' parents ' ) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' , ' audit_trail ' , ) } ) ,
)
readonly_fields = ( ' creation_date ' , ' created_by ' , ' audit_trail ' )
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
2013-04-18 02:59:21 +04:00
class VariableDataAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
class CredentialAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
2013-04-20 02:11:31 +04:00
fieldsets = (
( None , { ' fields ' : ( ( ' name ' , ' active ' ) , ( ' user ' , ' team ' ) , ' description ' ) } ) ,
2013-04-24 00:21:29 +04:00
( _ ( ' Auth Info ' ) , { ' fields ' : ( ( ' ssh_username ' , ' ssh_password ' ) ,
' ssh_key_data ' , ' ssh_key_unlock ' ,
( ' sudo_username ' , ' sudo_password ' ) ) } ) ,
2013-04-20 02:11:31 +04:00
#(_('Tags'), {'fields': ('tags',)}),
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' , ' audit_trail ' , ) } ) ,
)
readonly_fields = ( ' creation_date ' , ' created_by ' , ' audit_trail ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
class TeamAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
list_display = ( ' name ' , ' description ' , ' active ' )
2013-04-04 21:59:32 +04:00
filter_horizontal = ( ' projects ' , ' users ' , ' tags ' )
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
class ProjectAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
list_display = ( ' name ' , ' description ' , ' active ' )
2013-04-19 23:40:08 +04:00
fieldsets = (
( None , { ' fields ' : ( ( ' name ' , ' active ' ) , ' description ' , ' local_path ' ,
' get_available_playbooks_display ' ) } ) ,
( _ ( ' Tags ' ) , { ' fields ' : ( ' tags ' , ) } ) ,
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' , ' audit_trail ' , ) } ) ,
)
readonly_fields = ( ' creation_date ' , ' created_by ' , ' audit_trail ' ,
' get_available_playbooks_display ' )
2013-04-15 19:31:54 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
2013-04-19 23:40:08 +04:00
def get_available_playbooks_display ( self , obj ) :
return ' <br/> ' . join ( [ format_html ( ' {0} ' , x ) for x in
obj . available_playbooks ] )
get_available_playbooks_display . short_description = _ ( ' Available playbooks ' )
get_available_playbooks_display . allow_tags = True
2013-04-18 02:59:21 +04:00
class PermissionAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
list_display = ( ' name ' , ' description ' , ' active ' )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
class JobTemplateAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
list_display = ( ' name ' , ' description ' , ' active ' , ' get_create_link_display ' ,
' get_jobs_link_display ' )
2013-04-01 07:23:40 +04:00
fieldsets = (
2013-04-18 02:59:21 +04:00
( None , { ' fields ' : ( ' name ' , ' active ' , ' description ' ,
' get_create_link_display ' , ' get_jobs_link_display ' ) } ) ,
2013-04-19 23:40:08 +04:00
( _ ( ' Job Parameters ' ) , { ' fields ' : ( ' inventory ' , ' project ' , ' playbook ' ,
' credential ' , ' job_type ' ) } ) ,
2013-04-24 00:21:29 +04:00
( _ ( ' More Options ' ) , { ' fields ' : ( ' use_sudo ' , ' forks ' , ' limit ' ,
' verbosity ' , ' extra_vars ' ) ,
' classes ' : ( ' collapse ' , ) } ) ,
2013-04-18 02:59:21 +04:00
#(_('Tags'), {'fields': ('tags',)}),
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' ,
' audit_trail ' , ) } ) ,
2013-04-01 07:23:40 +04:00
)
2013-04-18 02:59:21 +04:00
readonly_fields = ( ' creation_date ' , ' created_by ' , ' audit_trail ' ,
' get_create_link_display ' , ' get_jobs_link_display ' )
2013-04-19 23:40:08 +04:00
form = JobTemplateAdminForm
2013-04-18 02:59:21 +04:00
#filter_horizontal = ('tags',)
2013-03-15 18:21:56 +04:00
2013-04-18 02:59:21 +04:00
def get_create_link_display ( self , obj ) :
2013-04-20 02:11:31 +04:00
if not obj or not obj . pk :
return ' '
2013-04-18 02:59:21 +04:00
info = Job . _meta . app_label , Job . _meta . module_name
create_url = reverse ( ' admin: %s _ %s _add ' % info ,
2013-04-05 00:53:20 +04:00
current_app = self . admin_site . name )
2013-04-18 02:59:21 +04:00
create_opts = {
' job_template ' : obj . pk ,
' job_type ' : obj . job_type ,
2013-04-20 02:11:31 +04:00
' description ' : obj . description ,
' name ' : ' %s %s ' % ( obj . name , now ( ) . isoformat ( ) ) ,
2013-04-18 02:59:21 +04:00
}
if obj . inventory :
create_opts [ ' inventory ' ] = obj . inventory . pk
if obj . project :
create_opts [ ' project ' ] = obj . project . pk
2013-04-19 23:40:08 +04:00
if obj . playbook :
create_opts [ ' playbook ' ] = obj . playbook
2013-04-18 02:59:21 +04:00
if obj . credential :
create_opts [ ' credential ' ] = obj . credential . pk
2013-04-24 00:21:29 +04:00
if obj . use_sudo is not None :
# Assume these are the defaults for a null boolean field select.
create_opts [ ' use_sudo ' ] = 2 if obj . use_sudo else 3
if obj . forks :
create_opts [ ' forks ' ] = obj . forks
if obj . limit :
create_opts [ ' limit ' ] = obj . limit
if obj . verbosity :
create_opts [ ' verbosity ' ] = obj . verbosity
if obj . extra_vars :
create_opts [ ' extra_vars ' ] = json . dumps ( obj . extra_vars )
2013-04-18 02:59:21 +04:00
create_url + = ' ? %s ' % urllib . urlencode ( create_opts )
return format_html ( ' <a href= " {0} " > {1} </a> ' , create_url , ' Create Job ' )
get_create_link_display . short_description = _ ( ' Create Job ' )
get_create_link_display . allow_tags = True
def get_jobs_link_display ( self , obj ) :
2013-04-20 02:11:31 +04:00
if not obj or not obj . pk :
return ' '
2013-04-18 02:59:21 +04:00
info = Job . _meta . app_label , Job . _meta . module_name
jobs_url = reverse ( ' admin: %s _ %s _changelist ' % info ,
current_app = self . admin_site . name )
jobs_url + = ' ?job_template__id__exact= %d ' % obj . pk
return format_html ( ' <a href= " {0} " > {1} </a> ' , jobs_url , ' View Jobs ' )
get_jobs_link_display . short_description = _ ( ' View Jobs ' )
get_jobs_link_display . allow_tags = True
class JobHostSummaryInlineForJob ( JobHostSummaryInline ) :
fields = ( ' host ' , ' changed ' , ' dark ' , ' failures ' , ' ok ' , ' processed ' ,
' skipped ' )
readonly_fields = ( ' host ' , ' changed ' , ' dark ' , ' failures ' , ' ok ' ,
' processed ' , ' skipped ' )
class JobEventInlineForJob ( JobEventInline ) :
2013-04-16 03:22:57 +04:00
fields = ( ' created ' , ' event ' , ' get_event_data_display ' , ' host ' )
readonly_fields = ( ' created ' , ' event ' , ' get_event_data_display ' , ' host ' )
2013-04-05 00:53:20 +04:00
2013-04-18 02:59:21 +04:00
class JobAdmin ( BaseModelAdmin ) :
2013-03-15 18:21:56 +04:00
2013-04-19 23:40:08 +04:00
list_display = ( ' name ' , ' job_template ' , ' project ' , ' playbook ' , ' status ' )
2013-04-24 19:35:30 +04:00
list_filter = ( ' status ' , )
2013-04-18 02:59:21 +04:00
fieldsets = (
( None , { ' fields ' : ( ' name ' , ' job_template ' , ' description ' ) } ) ,
2013-04-19 23:40:08 +04:00
( _ ( ' Job Parameters ' ) , { ' fields ' : ( ' inventory ' , ' project ' , ' playbook ' ,
2013-04-24 00:21:29 +04:00
' credential ' , ' job_type ' ) } ) ,
( _ ( ' More Options ' ) , { ' fields ' : ( ' use_sudo ' , ' forks ' , ' limit ' ,
' verbosity ' , ' extra_vars ' ) ,
' classes ' : ( ' collapse ' , ) } ) ,
2013-04-25 09:11:55 +04:00
( _ ( ' Start Job ' ) , { ' fields ' : ( ' start_job ' , ' ssh_password ' ,
' sudo_password ' , ' ssh_key_unlock ' ) } ) ,
2013-04-18 02:59:21 +04:00
#(_('Tags'), {'fields': ('tags',)}),
( _ ( ' Audit Trail ' ) , { ' fields ' : ( ' creation_date ' , ' created_by ' ,
' audit_trail ' , ) } ) ,
2013-04-25 09:11:55 +04:00
( _ ( ' Job Status ' ) , { ' fields ' : ( ( ' status ' , ' cancel_job ' ) ,
' get_result_stdout_display ' ,
2013-04-18 02:59:21 +04:00
' get_result_stderr_display ' ,
' get_result_traceback_display ' ,
' celery_task_id ' ) } ) ,
)
readonly_fields = ( ' status ' , ' get_job_template_display ' ,
2013-04-16 03:22:57 +04:00
' get_result_stdout_display ' , ' get_result_stderr_display ' ,
' get_result_traceback_display ' , ' celery_task_id ' ,
2013-04-18 02:59:21 +04:00
' creation_date ' , ' created_by ' , ' audit_trail ' , )
2013-03-15 19:45:14 +04:00
filter_horizontal = ( ' tags ' , )
2013-04-19 23:40:08 +04:00
form = JobAdminForm
2013-04-18 02:59:21 +04:00
inlines = [ JobHostSummaryInlineForJob , JobEventInlineForJob ]
def get_readonly_fields ( self , request , obj = None ) :
ro_fields = list ( super ( JobAdmin , self ) . get_readonly_fields ( request , obj ) )
2013-04-20 02:11:31 +04:00
if obj and obj . pk and obj . status != ' new ' :
2013-04-18 02:59:21 +04:00
ro_fields . extend ( [ ' name ' , ' description ' , ' job_template ' ,
2013-04-19 23:40:08 +04:00
' inventory ' , ' project ' , ' playbook ' , ' credential ' ,
2013-04-24 00:21:29 +04:00
' job_type ' , ' use_sudo ' , ' forks ' , ' limit ' ,
' verbosity ' , ' extra_vars ' ] )
2013-04-18 02:59:21 +04:00
return ro_fields
def get_fieldsets ( self , request , obj = None ) :
fsets = list ( super ( JobAdmin , self ) . get_fieldsets ( request , obj ) )
2013-04-20 02:11:31 +04:00
if not obj or not obj . pk or obj . status == ' new ' :
2013-04-18 02:59:21 +04:00
fsets = [ fs for fs in fsets if
' creation_date ' not in fs [ 1 ] [ ' fields ' ] and
2013-04-25 09:11:55 +04:00
' celery_task_id ' not in fs [ 1 ] [ ' fields ' ] ]
if not obj or ( obj and obj . pk and obj . status != ' new ' ) :
2013-04-24 00:21:29 +04:00
fsets = [ fs for fs in fsets if ' start_job ' not in fs [ 1 ] [ ' fields ' ] ]
2013-04-25 09:11:55 +04:00
if not obj or ( obj and obj . pk and obj . status not in ( ' pending ' , ' running ' ) ) :
for fs in fsets :
if ' celery_task_id ' in fs [ 1 ] [ ' fields ' ] :
fs [ 1 ] [ ' fields ' ] = ( ' status ' , ' get_result_stdout_display ' ,
' get_result_stderr_display ' ,
' get_result_traceback_display ' ,
' celery_task_id ' )
2013-04-18 02:59:21 +04:00
return fsets
def get_inline_instances ( self , request , obj = None ) :
2013-04-20 02:11:31 +04:00
if obj and obj . pk and obj . status != ' new ' :
2013-04-18 02:59:21 +04:00
return super ( JobAdmin , self ) . get_inline_instances ( request , obj )
else :
return [ ]
def get_job_template_display ( self , obj ) :
if obj . job_template :
info = JobTemplate . _meta . app_label , JobTemplate . _meta . module_name
job_template_url = reverse ( ' admin: %s _ %s _change ' % info ,
args = ( obj . job_template . pk , ) ,
current_app = self . admin_site . name )
return format_html ( ' <a href= " {0} " > {1} </a> ' , job_template_url ,
obj . job_template )
else :
return _ ( ' (None) ' )
get_job_template_display . short_description = _ ( ' Job template ' )
get_job_template_display . allow_tags = True
2013-04-16 03:22:57 +04:00
def get_result_stdout_display ( self , obj ) :
2013-04-18 02:59:21 +04:00
return format_html ( ' <pre class= " result-display " > {0} </pre> ' ,
obj . result_stdout or ' ' )
2013-04-16 03:22:57 +04:00
get_result_stdout_display . short_description = _ ( ' Stdout ' )
get_result_stdout_display . allow_tags = True
def get_result_stderr_display ( self , obj ) :
2013-04-18 02:59:21 +04:00
return format_html ( ' <pre class= " result-display " > {0} </pre> ' ,
obj . result_stderr or ' ' )
2013-04-16 03:22:57 +04:00
get_result_stderr_display . short_description = _ ( ' Stderr ' )
get_result_stderr_display . allow_tags = True
def get_result_traceback_display ( self , obj ) :
2013-04-18 02:59:21 +04:00
return format_html ( ' <pre class= " result-display " > {0} </pre> ' ,
obj . result_traceback or ' ' )
2013-04-16 03:22:57 +04:00
get_result_traceback_display . short_description = _ ( ' Traceback ' )
get_result_traceback_display . allow_tags = True
2013-04-25 09:11:55 +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-18 02:59:21 +04:00
admin . site . register ( JobTemplate , JobTemplateAdmin )
admin . site . register ( Job , JobAdmin )