@require_role('admin')
def asset_add(request):
 (header_title, path1, path2) = (u'\u6dfb\u52a0\u8d44\u4ea7', u'\u8d44\u4ea7\u7ba1\u7406', u'\u6dfb\u52a0\u8d44\u4ea7')
 asset_group_all = AssetGroup.objects.all()
 af = AssetForm()
 default_setting = get_object(Setting, name='default')
 default_port = (default_setting.field2 if default_setting else '')
 if (request.method == 'POST'):
  af_post = AssetForm(request.POST)
  ip = request.POST.get('ip', '')
  hostname = request.POST.get('hostname', '')
  is_active = (True if (request.POST.get('is_active') == '1') else False)
  use_default_auth = request.POST.get('use_default_auth', '')
  try:
   if Asset.objects.filter(hostname=unicode(hostname)):
    error = (u'\u8be5\u4e3b\u673a\u540d %s \u5df2\u5b58\u5728!' % hostname)
    raise ServerError(error)
   if (len(hostname) > 54):
    error = u'\u4e3b\u673a\u540d\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc753\u4f4d!'
    raise ServerError(error)
  except ServerError:
   pass
  else:
   if af_post.is_valid():
    asset_save = af_post.save(commit=False)
    if (not use_default_auth):
     password = request.POST.get('password', '')
     password_encode = CRYPTOR.encrypt(password)
     asset_save.password = password_encode
    if (not ip):
     asset_save.ip = hostname
    asset_save.is_active = (True if is_active else False)
    asset_save.save()
    af_post.save_m2m()
    msg = (u'\u4e3b\u673a %s \u6dfb\u52a0\u6210\u529f' % hostname)
   else:
    esg = (u'\u4e3b\u673a %s \u6dfb\u52a0\u5931\u8d25' % hostname)
 return my_render('jasset/asset_add.html', locals(), request)

@ require_role ( 'admin' ) def asset_add ( request ) : ( header_title , path1 , path2 ) = ( u'\u6dfb\u52a0\u8d44\u4ea7' , u'\u8d44\u4ea7\u7ba1\u7406' , u'\u6dfb\u52a0\u8d44\u4ea7' ) asset_group_all = AssetGroup . objects . all ( ) af = AssetForm ( ) default_setting = get_object ( Setting , name = 'default' ) default_port = ( default_setting . field2 if default_setting else '' ) if ( request . method == 'POST' ) : af_post = AssetForm ( request . POST ) ip = request . POST . get ( 'ip' , '' ) hostname = request . POST . get ( 'hostname' , '' ) is_active = ( True if ( request . POST . get ( 'is_active' ) == '1' ) else False ) use_default_auth = request . POST . get ( 'use_default_auth' , '' ) try : if Asset . objects . filter ( hostname = unicode ( hostname ) ) : error = ( u'\u8be5\u4e3b\u673a\u540d %s \u5df2\u5b58\u5728!' % hostname ) raise ServerError ( error ) if ( len ( hostname ) > 54 ) : error = u'\u4e3b\u673a\u540d\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc753\u4f4d!' raise ServerError ( error ) except ServerError : pass else : if af_post . is_valid ( ) : asset_save = af_post . save ( commit = False ) if ( not use_default_auth ) : password = request . POST . get ( 'password' , '' ) password_encode = CRYPTOR . encrypt ( password ) asset_save . password = password_encode if ( not ip ) : asset_save . ip = hostname asset_save . is_active = ( True if is_active else False ) asset_save . save ( ) af_post . save_m2m ( ) msg = ( u'\u4e3b\u673a %s \u6dfb\u52a0\u6210\u529f' % hostname ) else : esg = ( u'\u4e3b\u673a %s \u6dfb\u52a0\u5931\u8d25' % hostname ) return my_render ( 'jasset/asset_add.html' , locals ( ) , request )
new asset form .