收窄廠商模板載入範圍
All checks were successful
CD Pipeline / deploy (push) Successful in 57s

This commit is contained in:
OoO
2026-05-14 00:11:03 +08:00
parent e006814ed5
commit 3263e1b400
3 changed files with 22 additions and 16 deletions

9
app.py
View File

@@ -30,7 +30,6 @@ except OSError as e:
# ================= 🔧 2. 核心模組導入 =================
try:
from flask import Flask, render_template, jsonify, request, send_file, redirect, url_for, send_from_directory, flash, session
from jinja2 import ChoiceLoader, FileSystemLoader
from werkzeug.utils import secure_filename
from pyngrok import ngrok, conf
import schedule
@@ -128,7 +127,6 @@ else:
sys_log.warning("[Security] ⚠️ NGROK_AUTH_TOKEN 未設定,已跳過 ngrok auth token 注入")
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
WEB_TEMPLATE_DIR = os.path.join(BASE_DIR, 'web/templates')
STATIC_DIR = os.path.join(BASE_DIR, 'web/static')
# 檢查關鍵模板是否存在
@@ -139,13 +137,6 @@ app = Flask(__name__,
template_folder=TEMPLATE_DIR,
static_folder=STATIC_DIR)
if os.path.isdir(WEB_TEMPLATE_DIR):
# Keep newer module templates ahead of stale legacy copies that may exist on older hosts.
app.jinja_loader = ChoiceLoader([
FileSystemLoader(WEB_TEMPLATE_DIR),
app.jinja_loader,
])
# ==========================================
# 🔒 Flask 安全配置
# ==========================================

View File

@@ -320,7 +320,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
# ==========================================
# 系統版本與路徑
# ==========================================
SYSTEM_VERSION = "V10.144"
SYSTEM_VERSION = "V10.145"
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
public_url = PUBLIC_URL # 用於模板顯示

View File

@@ -6,6 +6,7 @@
"""
from flask import Blueprint, render_template, jsonify, request, send_file
from jinja2 import ChoiceLoader, FileSystemLoader, PrefixLoader
from werkzeug.utils import secure_filename
from datetime import datetime, date
from sqlalchemy import or_, func, desc
@@ -35,6 +36,20 @@ sys_log = SystemLogger("VendorRoutes").get_logger()
_base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_template_folder = os.path.join(_base_dir, 'web', 'templates')
vendor_bp = Blueprint('vendor', __name__, url_prefix='/vendor-stockout', template_folder=_template_folder)
_VENDOR_TEMPLATE_PREFIX = '__vendor_web__'
@vendor_bp.record_once
def _register_vendor_template_loader(setup_state):
app = setup_state.app
app.jinja_loader = ChoiceLoader([
PrefixLoader({_VENDOR_TEMPLATE_PREFIX: FileSystemLoader(_template_folder)}),
app.jinja_loader,
])
def _render_vendor_template(template_name, **context):
return render_template(f'{_VENDOR_TEMPLATE_PREFIX}/{template_name}', **context)
# 初始化資料庫管理器
vendor_db = VendorDatabaseManager()
@@ -49,7 +64,7 @@ def index():
"""廠商缺貨系統主頁"""
sys_log.info("[VendorStockout] 進入廠商缺貨系統主頁")
if request.args.get('ui') == 'legacy':
return render_template('vendor_stockout/index.html')
return _render_vendor_template('vendor_stockout/index.html')
return render_template(
'vendor_stockout_index_v2.html',
active_page='vendor_stockout',
@@ -62,7 +77,7 @@ def import_page():
"""Excel 匯入頁面"""
sys_log.info("[VendorStockout] 進入匯入頁面")
if request.args.get('ui') == 'legacy':
return render_template('vendor_stockout/import.html')
return _render_vendor_template('vendor_stockout/import.html')
return render_template(
'vendor_stockout_import_v2.html',
active_page='vendor_stockout'
@@ -74,7 +89,7 @@ def list_page():
"""缺貨清單頁面"""
sys_log.info("[VendorStockout] 進入缺貨清單頁面")
if request.args.get('ui') == 'legacy':
return render_template('vendor_stockout/list.html')
return _render_vendor_template('vendor_stockout/list.html')
return render_template(
'vendor_stockout_list_v2.html',
active_page='vendor_stockout',
@@ -94,21 +109,21 @@ def list_page():
def vendor_management_page():
"""廠商管理頁面"""
sys_log.info("[VendorStockout] 進入廠商管理頁面")
return render_template('vendor_stockout/vendor_management.html')
return _render_vendor_template('vendor_stockout/vendor_management.html')
@vendor_bp.route('/send-email')
def send_email_page():
"""郵件發送頁面"""
sys_log.info("[VendorStockout] 進入郵件發送頁面")
return render_template('vendor_stockout/send_email.html')
return _render_vendor_template('vendor_stockout/send_email.html')
@vendor_bp.route('/history')
def history_page():
"""發送歷史頁面"""
sys_log.info("[VendorStockout] 進入發送歷史頁面")
return render_template('vendor_stockout/history.html')
return _render_vendor_template('vendor_stockout/history.html')
# ==========================================