修复bug
This commit is contained in:
parent
b041b73766
commit
0cef097dfa
38
app.py
38
app.py
@ -12,6 +12,11 @@ from io import BytesIO
|
||||
import zipfile
|
||||
from pypinyin import pinyin, Style
|
||||
import uuid
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'your-secret-key-here'
|
||||
from pypinyin import pinyin, Style
|
||||
|
||||
def to_pinyin(text):
|
||||
"""将中文转换为拼音"""
|
||||
if not text:
|
||||
@ -21,14 +26,11 @@ def to_pinyin(text):
|
||||
# 拼接成字符串
|
||||
return "_".join([item[0] for item in pinyin_list])
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'your-secret-key-here'
|
||||
|
||||
# 注册模板过滤器
|
||||
@app.template_filter('to_pinyin')
|
||||
def jinja2_to_pinyin(text):
|
||||
return to_pinyin(text)
|
||||
|
||||
|
||||
# 数据库配置
|
||||
db_config = {
|
||||
'host': '192.168.31.11',
|
||||
@ -631,6 +633,8 @@ def create_ca_view():
|
||||
return render_template('create_ca.html')
|
||||
|
||||
|
||||
from datetime import timedelta # 确保顶部已导入
|
||||
|
||||
@app.route('/cas/<int:ca_id>')
|
||||
@login_required
|
||||
def ca_detail(ca_id):
|
||||
@ -663,7 +667,14 @@ def ca_detail(ca_id):
|
||||
""", (ca_id,))
|
||||
crl = cursor.fetchone()
|
||||
|
||||
return render_template('ca_detail.html', ca=ca, certificates=certificates, crl=crl)
|
||||
return render_template(
|
||||
'ca_detail.html',
|
||||
ca=ca,
|
||||
certificates=certificates,
|
||||
crl=crl,
|
||||
timedelta=timedelta, # 传递timedelta到模板
|
||||
get_username=get_username # 确保这个函数已定义
|
||||
)
|
||||
except Error as e:
|
||||
print(f"Database error: {e}")
|
||||
flash('获取CA详情失败', 'danger')
|
||||
@ -674,6 +685,23 @@ def ca_detail(ca_id):
|
||||
conn.close()
|
||||
return redirect(url_for('ca_list'))
|
||||
|
||||
def get_username(user_id):
|
||||
"""根据用户ID获取用户名"""
|
||||
conn = get_db_connection()
|
||||
if conn:
|
||||
try:
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT username FROM users WHERE id = %s", (user_id,))
|
||||
user = cursor.fetchone()
|
||||
return user['username'] if user else str(user_id)
|
||||
except Error as e:
|
||||
print(f"Database error: {e}")
|
||||
return str(user_id)
|
||||
finally:
|
||||
if conn.is_connected():
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return str(user_id)
|
||||
|
||||
@app.route('/cas/<int:ca_id>/generate_crl')
|
||||
@login_required
|
||||
|
||||
@ -75,8 +75,14 @@
|
||||
<dt class="col-sm-4"><i class="fas fa-key"></i> 密钥长度</dt>
|
||||
<dd class="col-sm-8">{{ ca.key_size }}位</dd>
|
||||
|
||||
<dt class="col-sm-4"><i class="fas fa-calendar-check"></i> 有效期</dt>
|
||||
<dd class="col-sm-8">{{ ca.days_valid }}天 (至 {{ (ca.created_at + timedelta(days=ca.days_valid)).strftime('%Y-%m-%d') }})</dd>
|
||||
<!-- 修改有效期显示部分 -->
|
||||
<dt class="col-sm-4"><i class="fas fa-calendar-check"></i> 有效期</dt>
|
||||
<dd class="col-sm-8">
|
||||
{{ ca.days_valid }}天
|
||||
{% if ca.created_at %}
|
||||
(至 {{ (ca.created_at + timedelta(days=ca.days_valid)).strftime('%Y-%m-%d') }})
|
||||
{% endif %}
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-4"><i class="fas fa-user"></i> 创建者</dt>
|
||||
<dd class="col-sm-8">{{ get_username(ca.created_by) }}</dd>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user