Pārlūkot izejas kodu

指定了计算节点创建虚拟机时,实现了计算节点选择字段的表单校验

James Iter 8 gadi atpakaļ
vecāks
revīzija
793eb9a542
2 mainītis faili ar 11 papildinājumiem un 3 dzēšanām
  1. 4 2
      templates/guest_create.html
  2. 7 1
      views/guest.py

+ 4 - 2
templates/guest_create.html

@@ -119,9 +119,11 @@
 
 
     function allocation_by_random_click_handler(me) {
     function allocation_by_random_click_handler(me) {
         if ($(me).prop('checked')) {
         if ($(me).prop('checked')) {
-            $('#on_host').parent().parent().css('display', 'none')
+            $('#create_guest_form').formValidation('removeField', 'on_host');
+            $('#on_host').parent().parent().css('display', 'none');
         } else {
         } else {
-            $('#on_host').parent().parent().css('display', 'unset')
+            $('#create_guest_form').formValidation('addField', 'on_host', {validators: {notEmpty: {}}});
+            $('#on_host').parent().parent().css('display', 'unset');
         }
         }
     }
     }
 </script>
 </script>

+ 7 - 1
views/guest.py

@@ -153,7 +153,13 @@ def create():
         headers = {'content-type': 'application/json'}
         headers = {'content-type': 'application/json'}
         r = requests.post(url, data=json.dumps(payload), headers=headers, cookies=request.cookies)
         r = requests.post(url, data=json.dumps(payload), headers=headers, cookies=request.cookies)
         j_r = json.loads(r.content)
         j_r = json.loads(r.content)
-        # TODO: 状态码返回非200时,转到失败页面。
+
+        if j_r['state']['code'] != '200':
+            return render_template('failure.html',
+                                   go_back_url='/guests',
+                                   timeout=10000, title='创建失败',
+                                   message_title='创建实例失败',
+                                   message=j_r['state']['sub']['zh-cn'])
 
 
         guests_url = host_url + url_for('api_guests.r_get_by_filter')
         guests_url = host_url + url_for('api_guests.r_get_by_filter')
         guests_ret = requests.get(url=guests_url, cookies=request.cookies)
         guests_ret = requests.get(url=guests_url, cookies=request.cookies)