@require_role(role='super')
def asset_edit(request):
 (header_title, path1, path2) = (u'\u4fee\u6539\u8d44\u4ea7', u'\u8d44\u4ea7\u7ba1\u7406', u'\u4fee\u6539\u8d44\u4ea7')
 asset_id = request.GET.get('id', '')
 username = request.user.username
 asset = get_object(Asset, id=asset_id)
 if asset:
  password_old = asset.password
 af = AssetForm(instance=asset)
 if (request.method == 'POST'):
  af_post = AssetForm(request.POST, instance=asset)
  ip = request.POST.get('ip', '')
  hostname = request.POST.get('hostname', '')
  password = request.POST.get('password', '')
  is_active = (True if (request.POST.get('is_active') == '1') else False)
  use_default_auth = request.POST.get('use_default_auth', '')
  try:
   asset_test = get_object(Asset, hostname=hostname)
   if (asset_test and (asset_id != unicode(asset_test.id))):
    emg = (u'\u8be5\u4e3b\u673a\u540d %s \u5df2\u5b58\u5728!' % hostname)
    raise ServerError(emg)
   if (len(hostname) > 54):
    emg = u'\u4e3b\u673a\u540d\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc754\u4f4d!'
    raise ServerError(emg)
   elif af_post.is_valid():
    af_save = af_post.save(commit=False)
    if use_default_auth:
     af_save.username = ''
     af_save.password = ''
    elif password:
     password_encode = CRYPTOR.encrypt(password)
     af_save.password = password_encode
    else:
     af_save.password = password_old
    af_save.is_active = (True if is_active else False)
    af_save.save()
    af_post.save_m2m()
    info = asset_diff(af_post.__dict__.get('initial'), request.POST)
    db_asset_alert(asset, username, info)
    smg = (u'\u4e3b\u673a %s \u4fee\u6539\u6210\u529f' % ip)
   else:
    emg = (u'\u4e3b\u673a %s \u4fee\u6539\u5931\u8d25' % ip)
    raise ServerError(emg)
  except ServerError as e:
   error = e.message
   return my_render('jasset/asset_edit.html', locals(), request)
  return HttpResponseRedirect((reverse('asset_detail') + ('?id=%s' % asset_id)))
 return my_render('jasset/asset_edit.html', locals(), request)

@ require_role ( role = 'super' ) def asset_edit ( request ) : ( header_title , path1 , path2 ) = ( u'\u4fee\u6539\u8d44\u4ea7' , u'\u8d44\u4ea7\u7ba1\u7406' , u'\u4fee\u6539\u8d44\u4ea7' ) asset_id = request . GET . get ( 'id' , '' ) username = request . user . username asset = get_object ( Asset , id = asset_id ) if asset : password_old = asset . password af = AssetForm ( instance = asset ) if ( request . method == 'POST' ) : af_post = AssetForm ( request . POST , instance = asset ) ip = request . POST . get ( 'ip' , '' ) hostname = request . POST . get ( 'hostname' , '' ) password = request . POST . get ( 'password' , '' ) is_active = ( True if ( request . POST . get ( 'is_active' ) == '1' ) else False ) use_default_auth = request . POST . get ( 'use_default_auth' , '' ) try : asset_test = get_object ( Asset , hostname = hostname ) if ( asset_test and ( asset_id != unicode ( asset_test . id ) ) ) : emg = ( u'\u8be5\u4e3b\u673a\u540d %s \u5df2\u5b58\u5728!' % hostname ) raise ServerError ( emg ) if ( len ( hostname ) > 54 ) : emg = u'\u4e3b\u673a\u540d\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc754\u4f4d!' raise ServerError ( emg ) elif af_post . is_valid ( ) : af_save = af_post . save ( commit = False ) if use_default_auth : af_save . username = '' af_save . password = '' elif password : password_encode = CRYPTOR . encrypt ( password ) af_save . password = password_encode else : af_save . password = password_old af_save . is_active = ( True if is_active else False ) af_save . save ( ) af_post . save_m2m ( ) info = asset_diff ( af_post . __dict__ . get ( 'initial' ) , request . POST ) db_asset_alert ( asset , username , info ) smg = ( u'\u4e3b\u673a %s \u4fee\u6539\u6210\u529f' % ip ) else : emg = ( u'\u4e3b\u673a %s \u4fee\u6539\u5931\u8d25' % ip ) raise ServerError ( emg ) except ServerError as e : error = e . message return my_render ( 'jasset/asset_edit.html' , locals ( ) , request ) return HttpResponseRedirect ( ( reverse ( 'asset_detail' ) + ( '?id=%s' % asset_id ) ) ) return my_render ( 'jasset/asset_edit.html' , locals ( ) , request )
asset edit page .