Browse Source

实现404、500页面

James Iter 9 years ago
parent
commit
12b28d706b
5 changed files with 133 additions and 99 deletions
  1. 58 0
      templates/404.html
  2. 55 0
      templates/500.html
  3. 0 11
      templates/config_init.html
  4. 1 1
      templates/layout.html
  5. 19 87
      views/config.py

+ 58 - 0
templates/404.html

@@ -0,0 +1,58 @@
+{% extends "layout.html" %}
+{% block head %}
+    {{ super() }}
+
+    <style type="text/css">
+
+        label>span {
+            color: deepskyblue;
+        }
+
+        .btn,
+        .form-group>div>div,
+        .form-control {
+            border-radius: 0;
+        }
+
+        html,body {
+            height: 100%;
+        }
+        .page-box {
+            min-height: 200px;
+        }
+
+        .page-box .server-message {
+            padding: 35px 0;
+        }
+        body {
+            overflow: hidden;
+        }
+    </style>
+{% endblock head %}
+{% block body %}
+<script type="text/javascript" src="{{ url_for('static', filename='widgets/wow/wow.js') }}"></script>
+<script type="text/javascript">
+    /* WOW animations */
+
+    wow = new WOW({
+        animateClass: 'animated',
+        offset: 100
+    });
+    wow.init();
+</script>
+<div class="center-vertical">
+    <div class="center-content row">
+        <div class="col-md-6 wow bounceInDown center-margin">
+            <div class="server-message">
+                <h1>Error 404</h1>
+                <h2>Page not found</h2>
+                <form>
+                    <a href="/" class="btn btn-lg btn-success">返回首页</a>
+                </form>
+            </div>
+        </div>
+
+    </div>
+</div>
+{% endblock body %}
+

+ 55 - 0
templates/500.html

@@ -0,0 +1,55 @@
+{% extends "layout.html" %}
+{% block head %}
+    {{ super() }}
+
+    <style type="text/css">
+
+        label>span {
+            color: deepskyblue;
+        }
+
+        .btn,
+        .form-group>div>div,
+        .form-control {
+            border-radius: 0;
+        }
+
+        html,body {
+            height: 100%;
+        }
+        .page-box {
+            min-height: 200px;
+        }
+
+        .page-box .server-message {
+            padding: 35px 0;
+        }
+        body {
+            overflow: hidden;
+        }
+    </style>
+{% endblock head %}
+{% block body %}
+<script type="text/javascript" src="{{ url_for('static', filename='widgets/wow/wow.js') }}"></script>
+<script type="text/javascript">
+    /* WOW animations */
+
+    wow = new WOW({
+        animateClass: 'animated',
+        offset: 100
+    });
+    wow.init();
+</script>
+<div class="center-vertical">
+    <div class="center-content row">
+        <div class="col-md-6 center-margin">
+            <div class="server-message wow bounceInDown">
+                <h1>Error 500</h1>
+                <h2>The server encountered a syntax error and could not complete your request.</h2>
+                <p>Try again in a few minutes or contact the website administrator.</p>
+            </div>
+        </div>
+
+    </div>
+</div>
+{% endblock body %}

+ 0 - 11
templates/config_init.html

@@ -13,17 +13,6 @@
         .form-control {
             border-radius: 0;
         }
-
-        .btn-ability {
-            margin-right: 16px;
-            height: 50px;
-            padding: 8px 50px;
-            margin-bottom: 30px;
-        }
-
-        .btn-ability-line {
-        }
-
     </style>
 {% endblock head %}
 {% block body %}

+ 1 - 1
templates/layout.html

@@ -222,7 +222,7 @@
 
 </head>
 <body>
-    <div id="sb-site">
+    <div id="sb-site" style="height: 100%;">
         <!--<div id="loading">
             <div class="spinner">
                 <div class="bounce1"></div>

+ 19 - 87
views/config.py

@@ -3,9 +3,8 @@
 
 
 import json
-from flask import Blueprint, render_template, url_for, request
+from flask import Blueprint, render_template, request
 import requests
-from math import ceil
 
 
 __author__ = 'James Iter'
@@ -22,84 +21,16 @@ blueprint = Blueprint(
 
 
 def show():
-    args = list()
-    page = int(request.args.get('page', 1))
-    page_size = int(request.args.get('page_size', 10))
-    keyword = request.args.get('keyword', None)
-    resource_path = request.path
-
-    if page is not None:
-        args.append('page=' + page.__str__())
-
-    if page_size is not None:
-        args.append('page_size=' + page_size.__str__())
-
-    if keyword is not None:
-        args.append('keyword=' + keyword.__str__())
-
     host_url = request.host_url.rstrip('/')
+    config_url = host_url + '/api/config'
+    config_ret = requests.get(url=config_url)
+    config_ret = json.loads(config_ret.content)
 
-    guests_url = host_url + url_for('api_guests.r_get_by_filter')
-    if keyword is not None:
-        guests_url = host_url + url_for('api_guests.r_content_search')
-
-    os_templates_url = host_url + url_for('api_os_templates.r_get_by_filter')
-
-    if args.__len__() > 0:
-        guests_url = guests_url + '?' + '&'.join(args)
-
-    guests_ret = requests.get(url=guests_url)
-    guests_ret = json.loads(guests_ret.content)
-
-    os_templates_ret = requests.get(url=os_templates_url)
-    os_templates_ret = json.loads(os_templates_ret.content)
-    os_templates_mapping_by_id = dict()
-    for os_template in os_templates_ret['data']:
-        os_templates_mapping_by_id[os_template['id']] = os_template
-
-    guests_uuid = list()
-
-    for guest in guests_ret['data']:
-        guests_uuid.append(guest['uuid'])
-
-    guests_boot_jobs_ret = {'data': dict()}
+    # 检测 JimV 的配置是否已被初始化,只有未被初始化时,才展现初始化配置页面
+    if config_ret['state']['code'] == '404':
+        return render_template('404.html'), 404
 
-    if guests_uuid.__len__() > 0:
-        # 获取指定 Guest 的启动作业 ID
-        guests_boot_jobs_url = host_url + url_for('api_guests.r_get_boot_jobs', uuids=','.join(guests_uuid))
-        guests_boot_jobs_ret = requests.get(url=guests_boot_jobs_url)
-
-        guests_boot_jobs_ret = json.loads(guests_boot_jobs_ret.content)
-
-        # 统一单个、多个的返回JSON格式
-        if guests_uuid.__len__() == 1:
-            guests_boot_jobs_ret['data'] = {guests_uuid[0]: guests_boot_jobs_ret['data']}
-
-    last_page = int(ceil(guests_ret['paging']['total'] / float(page_size)))
-    page_length = 5
-    pages = list()
-    if page < int(ceil(page_length / 2.0)):
-        for i in range(1, page_length + 1):
-            pages.append(i)
-            if i == last_page:
-                break
-
-    elif last_page - page < page_length / 2:
-        for i in range(last_page - page_length + 1, last_page + 1):
-            if i < 1:
-                continue
-            pages.append(i)
-
-    else:
-        for i in range(page - page_length / 2, page + int(ceil(page_length / 2.0))):
-            pages.append(i)
-            if i == last_page:
-                break
-
-    return render_template('config_show.html', guests_ret=guests_ret, resource_path=resource_path,
-                           os_templates_mapping_by_id=os_templates_mapping_by_id,
-                           guests_boot_jobs_ret=guests_boot_jobs_ret, page=page,
-                           page_size=page_size, keyword=keyword, pages=pages, last_page=last_page)
+    return render_template('config_show.html', config_ret=config_ret)
 
 
 def create():
@@ -124,19 +55,20 @@ def create():
 
         url = host_url + '/api/config'
         headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
+        config_ret = requests.post(url, data=json.dumps(payload), headers=headers)
+        config_ret = json.loads(config_ret.content)
         return render_template('success.html', go_back_url='/', timeout=5000, title='提交成功',
                                message_title='初始化 JimV 请求已被接受',
                                message='JimV 已被初始化。页面将在5秒钟后自动跳转到实例列表页面!')
 
     else:
-        return render_template('config_init.html')
-
-
-def success():
-    return render_template('success.html', go_back_url='/', timeout=5000, title='提交成功',
-                           message_title='初始化 JimV 的请求已被接受',
-                           message='JimV 已被初始化。页面将在5秒钟后自动跳转到实例列表页面!')
-
+        url = host_url + '/api/config'
+        config_ret = requests.get(url=url)
+        config_ret = json.loads(config_ret.content)
+
+        # 检测 JimV 的配置是否已被初始化,只有未被初始化时,才展现初始化配置页面
+        if config_ret['state']['code'] == '404':
+            return render_template('config_init.html')
+        else:
+            return render_template('404.html'), 404