<s> from django . contrib import admin <EOL> from services . onos . models import * <EOL> from django import forms <EOL> from django . utils . safestring import mark_safe <EOL> from django . contrib . auth . admin import UserAdmin <EOL> from django . contrib . admin . widgets import FilteredSelectMultiple <EOL> from django . contrib . auth . forms import ReadOnlyPasswordHashField <EOL> from django . contrib . auth . signals import user_logged_in <EOL> from django . utils import timezone <EOL> from django . contrib . contenttypes import generic <EOL> from suit . widgets import LinkedSelect <EOL> from core . admin import ServiceAppAdmin , SliceInline , ServiceAttrAsTabInline , ReadOnlyAwareAdmin , XOSTabularInline , ServicePrivilegeInline , TenantRootTenantInline , TenantRootPrivilegeInline , TenantAttrAsTabInline <EOL> from core . middleware import get_request <EOL> from functools import update_wrapper <EOL> from django . contrib . admin . views . main import ChangeList <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . admin . utils import quote <EOL> class ONOSServiceForm ( forms . ModelForm ) : <EOL> rest_hostname = forms . CharField ( required = False ) <EOL> rest_port = forms . CharField ( required = False ) <EOL> no_container = forms . BooleanField ( required = False ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ONOSServiceForm , self ) . __init__ ( * args , ** kwargs ) <EOL> if self . instance : <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . rest_hostname <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . rest_port <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . no_container <EOL> def save ( self , commit = True ) : <EOL> self . instance . rest_hostname = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> self . instance . rest_port = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> self . instance . no_container = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> return super ( ONOSServiceForm , self ) . save ( commit = commit ) <EOL> class Meta : <EOL> model = ONOSService <EOL> class ONOSServiceAdmin ( ReadOnlyAwareAdmin ) : <EOL> model = ONOSService <EOL> verbose_name = "<STR_LIT>" <EOL> verbose_name_plural = "<STR_LIT>" <EOL> list_display = ( "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT>" ) <EOL> list_display_links = ( '<STR_LIT>' , '<STR_LIT:name>' , ) <EOL> fieldsets = [ ( None , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , '<STR_LIT>' : [ '<STR_LIT>' ] } ) ] <EOL> readonly_fields = ( '<STR_LIT>' , ) <EOL> inlines = [ SliceInline , ServiceAttrAsTabInline , ServicePrivilegeInline ] <EOL> form = ONOSServiceForm <EOL> extracontext_registered_admins = True <EOL> user_readonly_fields = [ "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:description>" ] <EOL> suit_form_tabs = ( ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> suit_form_includes = ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> def queryset ( self , request ) : <EOL> return ONOSService . get_service_objects_by_user ( request . user ) <EOL> class ONOSAppForm ( forms . ModelForm ) : <EOL> creator = forms . ModelChoiceField ( queryset = User . objects . all ( ) ) <EOL> name = forms . CharField ( ) <EOL> dependencies = forms . CharField ( required = False ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ONOSAppForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> self . fields [ '<STR_LIT>' ] . queryset = ONOSService . get_service_objects ( ) . all ( ) <EOL> if self . instance : <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . creator <EOL> self . fields [ '<STR_LIT:name>' ] . initial = self . instance . name <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . dependencies <EOL> if ( not self . instance ) or ( not self . instance . pk ) : <EOL> self . fields [ '<STR_LIT>' ] . initial = ONOS_KIND <EOL> self . fields [ '<STR_LIT>' ] . initial = get_request ( ) . user <EOL> if ONOSService . get_service_objects ( ) . exists ( ) : <EOL> self . fields [ "<STR_LIT>" ] . initial = ONOSService . get_service_objects ( ) . all ( ) [ <NUM_LIT:0> ] <EOL> def save ( self , commit = True ) : <EOL> self . instance . creator = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> self . instance . name = self . cleaned_data . get ( "<STR_LIT:name>" ) <EOL> self . instance . dependencies = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> return super ( ONOSAppForm , self ) . save ( commit = commit ) <EOL> class Meta : <EOL> model = ONOSApp <EOL> class ONOSAppAdmin ( ReadOnlyAwareAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT:name>' , ) <EOL> list_display_links = ( '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> fieldsets = [ ( None , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] } ) ] <EOL> readonly_fields = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> inlines = [ TenantAttrAsTabInline ] <EOL> form = ONOSAppForm <EOL> suit_form_tabs = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def queryset ( self , request ) : <EOL> return ONOSApp . get_tenant_objects_by_user ( request . user ) <EOL> admin . site . register ( ONOSService , ONOSServiceAdmin ) <EOL> admin . site . register ( ONOSApp , ONOSAppAdmin ) </s>
