Spaces:
Sleeping
Sleeping
Trae Assistant commited on
Commit ·
1c2b9be
1
Parent(s): 6ff4e1a
Fix strftime error by handling date formatting in database layer
Browse files- core/database.py +11 -1
- templates/index.html +1 -1
core/database.py
CHANGED
|
@@ -73,4 +73,14 @@ class StellarDB:
|
|
| 73 |
conn.row_factory = sqlite3.Row
|
| 74 |
cursor = conn.cursor()
|
| 75 |
cursor.execute('SELECT * FROM tasks ORDER BY created_at DESC')
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
conn.row_factory = sqlite3.Row
|
| 74 |
cursor = conn.cursor()
|
| 75 |
cursor.execute('SELECT * FROM tasks ORDER BY created_at DESC')
|
| 76 |
+
tasks = []
|
| 77 |
+
for row in cursor.fetchall():
|
| 78 |
+
task = dict(row)
|
| 79 |
+
# 确保 created_at 是字符串格式,方便模板显示
|
| 80 |
+
if isinstance(task['created_at'], datetime):
|
| 81 |
+
task['created_at'] = task['created_at'].strftime('%Y-%m-%d %H:%M:%S')
|
| 82 |
+
elif isinstance(task['created_at'], str):
|
| 83 |
+
# 如果已经是字符串(SQLite 默认返回),保留前 19 位 (YYYY-MM-DD HH:MM:SS)
|
| 84 |
+
task['created_at'] = task['created_at'][:19]
|
| 85 |
+
tasks.append(task)
|
| 86 |
+
return tasks
|
templates/index.html
CHANGED
|
@@ -172,7 +172,7 @@
|
|
| 172 |
<div class="p-3 rounded-xl bg-white/5 border border-white/5 text-sm cursor-pointer hover:bg-white/10 hover:border-white/20 transition-all group" onclick="showTaskDetail('{{ task.id }}')">
|
| 173 |
<div class="flex justify-between mb-1">
|
| 174 |
<span class="font-mono text-[10px] text-blue-400">#{{ task.id }}</span>
|
| 175 |
-
<span class="text-[9px] text-gray-500">{{ task.created_at
|
| 176 |
</div>
|
| 177 |
<p class="truncate text-gray-300 group-hover:text-white transition-colors">{{ task.description }}</p>
|
| 178 |
<div class="mt-2 flex items-center text-[9px] text-gray-500">
|
|
|
|
| 172 |
<div class="p-3 rounded-xl bg-white/5 border border-white/5 text-sm cursor-pointer hover:bg-white/10 hover:border-white/20 transition-all group" onclick="showTaskDetail('{{ task.id }}')">
|
| 173 |
<div class="flex justify-between mb-1">
|
| 174 |
<span class="font-mono text-[10px] text-blue-400">#{{ task.id }}</span>
|
| 175 |
+
<span class="text-[9px] text-gray-500">{{ task.created_at if task.created_at else '' }}</span>
|
| 176 |
</div>
|
| 177 |
<p class="truncate text-gray-300 group-hover:text-white transition-colors">{{ task.description }}</p>
|
| 178 |
<div class="mt-2 flex items-center text-[9px] text-gray-500">
|