diff --git a/ApiAutomationTest/app/__init__.py b/ApiAutomationTest/app/__init__.py index 19eb7f2..52db8aa 100644 --- a/ApiAutomationTest/app/__init__.py +++ b/ApiAutomationTest/app/__init__.py @@ -14,7 +14,7 @@ from app.extensions import (db, migrate, login_manager, mail, csrf, bootstrap, s from app import models from app.template_global import (render_to_json, sort_by_order_in_module, sort_by_order_in_logic_controller, can_show, is_forbidden, get_latest_reports, get_case_from_id, get_tool_from_id, - calc_percent) + calc_percent, url_for_static) from app.cores.ws import register_all_user_socket @@ -27,6 +27,7 @@ def create_app(config_class=Config): register_blueprints(app) register_shell_context(app) register_template_global(app) + register_template_context_processor(app) register_before_first_request_funcs(app) register_cli(app) @@ -173,6 +174,16 @@ def register_template_global(app: Flask): app.add_template_global(get_case_from_id, 'get_case_from_id') app.add_template_global(get_tool_from_id, 'get_tool_from_id') app.add_template_global(calc_percent, 'calc_percent') + app.add_template_global(url_for_static, 'url_for_static') + + +def register_template_context_processor(app: Flask): + # 注册jinja模板上下文 + @app.context_processor + def context_processor(): + return { + 'version': app.config['AAT_VERSION'], + } def register_before_first_request_funcs(app: Flask): diff --git a/ApiAutomationTest/app/config.py b/ApiAutomationTest/app/config.py index d6f186d..69efa56 100644 --- a/ApiAutomationTest/app/config.py +++ b/ApiAutomationTest/app/config.py @@ -9,6 +9,9 @@ attachment_dir = os.path.join(proj_dir, 'attachment') class Config: + # 版本编号 + AAT_VERSION = '0.3.0' # 'AAT' is 'ApiAutomationTest' + # SERVER_NAME = 'WebUiAutoTest:5000' # enable subdomain support # SERVER_NAME = '0.0.0.0:5000' # enable subdomain support diff --git a/ApiAutomationTest/app/template_global.py b/ApiAutomationTest/app/template_global.py index 380fc69..50146e5 100644 --- a/ApiAutomationTest/app/template_global.py +++ b/ApiAutomationTest/app/template_global.py @@ -10,6 +10,7 @@ LOG: """ import json from typing import Iterable +from flask import url_for, current_app from app.cores.dictionaries import STATUS from app.models import Report, SubElementInLogicController, Case, Tool @@ -120,5 +121,13 @@ def calc_percent(a, b): return None +def url_for_static(endpoint: str, **values): + """为静态资源加上版本号""" + if endpoint.strip().lower() != 'static': + raise ValueError("endpoint expects a 'static' value") + values['version'] = current_app.config['AAT_VERSION'] + return url_for(endpoint=endpoint, **values) + + if __name__ == '__main__': print(render_to_json) diff --git a/ApiAutomationTest/app/templates/auth/email_authentication.html b/ApiAutomationTest/app/templates/auth/email_authentication.html index 5899183..7b63c13 100644 --- a/ApiAutomationTest/app/templates/auth/email_authentication.html +++ b/ApiAutomationTest/app/templates/auth/email_authentication.html @@ -3,7 +3,7 @@ {% block styles %} {{ super() }} - + {% endblock styles %} {% block body_attribs %} diff --git a/ApiAutomationTest/app/templates/auth/login.html b/ApiAutomationTest/app/templates/auth/login.html index a51ae7e..ede5f9b 100644 --- a/ApiAutomationTest/app/templates/auth/login.html +++ b/ApiAutomationTest/app/templates/auth/login.html @@ -3,7 +3,7 @@ {% block styles %} {{ super() }} - + {% endblock styles %} {% block body_attribs %} diff --git a/ApiAutomationTest/app/templates/auth/reset.html b/ApiAutomationTest/app/templates/auth/reset.html index 1225a9e..6cc0cf6 100644 --- a/ApiAutomationTest/app/templates/auth/reset.html +++ b/ApiAutomationTest/app/templates/auth/reset.html @@ -3,7 +3,7 @@ {% block styles %} {{ super() }} - + {% endblock styles %} {% block body_attribs %} diff --git a/ApiAutomationTest/app/templates/auth/reset_password.html b/ApiAutomationTest/app/templates/auth/reset_password.html index 66d2a61..c3e6856 100644 --- a/ApiAutomationTest/app/templates/auth/reset_password.html +++ b/ApiAutomationTest/app/templates/auth/reset_password.html @@ -3,7 +3,7 @@ {% block styles %} {{ super() }} - + {% endblock styles %} {% block body_attribs %} diff --git a/ApiAutomationTest/app/templates/base.html b/ApiAutomationTest/app/templates/base.html index 803ccd4..ba7fd1d 100644 --- a/ApiAutomationTest/app/templates/base.html +++ b/ApiAutomationTest/app/templates/base.html @@ -9,20 +9,20 @@ {%- block metas %} - + {%- endblock metas %} {%- block styles %} - - - - + + + + {# #} - - - - - + + + + + {%- endblock styles %} {%- endblock head %} @@ -73,7 +73,7 @@
  • -
    ApiAutomationTest: Version 0.2.0
    +
    ApiAutomationTest: Version {{ version }}
  • @@ -82,15 +82,15 @@ {%- endblock content %} {% block scripts %} - + {# #} - - - - - - - + + + + + + + - - - + + + + - - - - + + + + + {% endblock %} \ No newline at end of file diff --git a/ApiAutomationTest/app/templates/project/project.html b/ApiAutomationTest/app/templates/project/project.html index 51c9819..32883de 100644 --- a/ApiAutomationTest/app/templates/project/project.html +++ b/ApiAutomationTest/app/templates/project/project.html @@ -2,8 +2,8 @@ {% block styles %} {{ super() }} - - + + {% endblock styles %} {% block body_attribs %} @@ -168,7 +168,7 @@ class="bg-gradient-grey" {% block scripts %} {{ super() }} - - - + + + {% endblock %} \ No newline at end of file diff --git a/ApiAutomationTest/app/templates/report/report.html b/ApiAutomationTest/app/templates/report/report.html index 37706f2..d3d6ae7 100644 --- a/ApiAutomationTest/app/templates/report/report.html +++ b/ApiAutomationTest/app/templates/report/report.html @@ -2,8 +2,8 @@ {% block styles %} {{ super() }} - - + + {% endblock styles %} {% block body_attribs %} @@ -23,7 +23,7 @@ class="bg-gradient-grey" {% block scripts %} {{ super() }} - - - + + + {% endblock %} \ No newline at end of file diff --git a/ApiAutomationTest/app/templates/report/report_detail.html b/ApiAutomationTest/app/templates/report/report_detail.html index c17500d..9e58874 100644 --- a/ApiAutomationTest/app/templates/report/report_detail.html +++ b/ApiAutomationTest/app/templates/report/report_detail.html @@ -2,10 +2,10 @@ {% block styles %} {{ super() }} - - - - + + + + {% endblock styles %} {% block body_attribs %} @@ -88,17 +88,17 @@ class="bg-gradient-grey" {% block scripts %} {{ super() }} - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ApiAutomationTest/app/templates/setting/basic_setting.html b/ApiAutomationTest/app/templates/setting/basic_setting.html index 70bcee4..bd9bb0e 100644 --- a/ApiAutomationTest/app/templates/setting/basic_setting.html +++ b/ApiAutomationTest/app/templates/setting/basic_setting.html @@ -3,9 +3,9 @@ {% block styles %} {{ super() }} - - - + + + {% endblock styles %} {% block body_attribs %} @@ -278,8 +278,8 @@ data-spy="scroll" data-target="#navbar-basic-setting" style="position: relative" {% block scripts %} {{ super() }} - - - - + + + + {% endblock %} \ No newline at end of file