From 310b3ccc6c36db26a66429f143962575de0923ce Mon Sep 17 00:00:00 2001 From: goumiaoqiong Date: Sat, 29 Nov 2025 10:34:39 +0800 Subject: [PATCH] add ai code --- .DS_Store | Bin 0 -> 6148 bytes README.md | 76 ++++++++- app.py | 162 ++++++++++++++++++ instance/notes.db | Bin 0 -> 8192 bytes requirements.txt | 3 + templates/add_note.html | 45 +++++ templates/base.html | 344 +++++++++++++++++++++++++++++++++++++++ templates/edit_note.html | 49 ++++++ templates/index.html | 121 ++++++++++++++ templates/view_note.html | 84 ++++++++++ 10 files changed, 883 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 app.py create mode 100644 instance/notes.db create mode 100644 requirements.txt create mode 100644 templates/add_note.html create mode 100644 templates/base.html create mode 100644 templates/edit_note.html create mode 100644 templates/index.html create mode 100644 templates/view_note.html diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0' + +# 初始化数据库 +with app.app_context(): + db.create_all() + +# 首页 - 显示备忘录列表 +@app.route('/') +def index(): + # 按优先级和完成状态排序 + # 未完成的按优先级排序,已完成的按完成时间排序 + completed_notes = Note.query.filter_by(is_completed=True).order_by(Note.created_at.desc()).all() + incomplete_notes = Note.query.filter_by(is_completed=False).order_by( + db.case( + (Note.priority == 'P0', 0), + (Note.priority == 'P1', 1), + (Note.priority == 'P2', 2), + else_=3 + ) + ).all() + + return render_template('index.html', incomplete_notes=incomplete_notes, completed_notes=completed_notes) + +# 添加备忘录 +@app.route('/add', methods=['GET', 'POST']) +def add_note(): + if request.method == 'POST': + title = request.form['title'] + content = request.form['content'] + priority = request.form['priority'] + + # 处理预计完成时间 + due_time_str = request.form['due_time'] + due_time = None + if due_time_str: + try: + due_time = datetime.strptime(due_time_str, '%Y-%m-%dT%H:%M') + due_time = local_tz.localize(due_time) + except ValueError: + flash('预计完成时间格式不正确') + return redirect(url_for('add_note')) + + new_note = Note( + title=title, + content=content, + due_time=due_time, + priority=priority + ) + + try: + db.session.add(new_note) + db.session.commit() + flash('备忘录添加成功!') + return redirect(url_for('index')) + except Exception as e: + db.session.rollback() + flash(f'添加备忘录失败: {str(e)}') + + return render_template('add_note.html') + +# 查看备忘录详情 +@app.route('/note/') +def view_note(note_id): + note = Note.query.get_or_404(note_id) + return render_template('view_note.html', note=note) + +# 编辑备忘录 +@app.route('/edit/', methods=['GET', 'POST']) +def edit_note(note_id): + note = Note.query.get_or_404(note_id) + + if request.method == 'POST': + note.title = request.form['title'] + note.content = request.form['content'] + note.priority = request.form['priority'] + note.is_completed = 'is_completed' in request.form + + # 处理预计完成时间 + due_time_str = request.form['due_time'] + if due_time_str: + try: + due_time = datetime.strptime(due_time_str, '%Y-%m-%dT%H:%M') + note.due_time = local_tz.localize(due_time) + except ValueError: + flash('预计完成时间格式不正确') + return redirect(url_for('edit_note', note_id=note_id)) + else: + note.due_time = None + + try: + db.session.commit() + flash('备忘录更新成功!') + return redirect(url_for('view_note', note_id=note_id)) + except Exception as e: + db.session.rollback() + flash(f'更新备忘录失败: {str(e)}') + + # 为表单准备时间格式 + due_time_formatted = note.due_time.strftime('%Y-%m-%dT%H:%M') if note.due_time else '' + + return render_template('edit_note.html', note=note, due_time_formatted=due_time_formatted) + +# 删除备忘录 +@app.route('/delete/') +def delete_note(note_id): + note = Note.query.get_or_404(note_id) + + try: + db.session.delete(note) + db.session.commit() + flash('备忘录删除成功!') + except Exception as e: + db.session.rollback() + flash(f'删除备忘录失败: {str(e)}') + + return redirect(url_for('index')) + +# 标记备忘录完成状态 +@app.route('/toggle_completed/') +def toggle_completed(note_id): + note = Note.query.get_or_404(note_id) + note.is_completed = not note.is_completed + + try: + db.session.commit() + except Exception as e: + db.session.rollback() + flash(f'更新状态失败: {str(e)}') + + return redirect(url_for('index')) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/instance/notes.db b/instance/notes.db new file mode 100644 index 0000000000000000000000000000000000000000..384a201f95dee5dd87574f234b9191faa8de1a3d GIT binary patch literal 8192 zcmeH~?@!Y}7{{-OaU+2Vge)eSobOnadDnI@YGN$d2yu*AtC3d=(qh^HBWr!3iHSfE zi6|Olf^nHYiG*O55MmbJ`md}-{{vrow+Vv0@SWks^YpI0d+xdK^W5iN_1e{x?OAv{ zUzi;Au!N2yK|mKVMhLaB-oW~f32e}~Ghtso|ChC)_>-T_EJ}z(5o=&T00;m9AOHk_ z01yBIKmZ5;0U!Vb4ikZyap73BqeGZG=Z)T)u%_}}tvB@Rnrdj+Q2SCE=3d;{6t+z~ zm^QS_nvT=M22Nj3rOx7}uxEP{7QUhC{R67rNePMVTOP|#F;Nd2+D*1+&%UvOHR@Sr zmi>=kV#$obA&twKcdV>uPg?t&(*-+Uu)VvxX~Yu@PhXGD5WA16J3;ciM^N-MWPB7<8p7eBy}HHAtX*}mLUU2LMR$# zM-MXzCQ`HgN<>M>@g(U<%DXv8Pb~*g{wRqT8bT;>LPf1%e|3Si;MH32W|cLQ)#}!{ z{#6N4L^)0+iAc!|Wfy+(%xPZ9_QpoF@}OE-uYP?T%+0g?=Z`Y&cBUN)KF+(Q=?0~; Y=`wz$vdgp&99~i+5|?GtOA{IT3zP~4!~g&Q literal 0 HcmV?d00001 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..eccead5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask==3.0.0 +flask-sqlalchemy==3.1.1 +pytz==2023.3.post1 \ No newline at end of file diff --git a/templates/add_note.html b/templates/add_note.html new file mode 100644 index 0000000..733b9f2 --- /dev/null +++ b/templates/add_note.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} + +{% block content %} +
+

添加新备忘录

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + + 设置备忘录的预计完成时间,留空表示不设置截止时间 + +
+ +
+ + + 取消 + +
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..95b057b --- /dev/null +++ b/templates/base.html @@ -0,0 +1,344 @@ + + + + + + 备忘录应用 + + + +
+
+

个人备忘录

+

记录生活和工作中的每一个重要时刻

+
+
+ +
+ + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} + + + {% block content %} + {% endblock %} +
+ + \ No newline at end of file diff --git a/templates/edit_note.html b/templates/edit_note.html new file mode 100644 index 0000000..488bec7 --- /dev/null +++ b/templates/edit_note.html @@ -0,0 +1,49 @@ +{% extends 'base.html' %} + +{% block content %} +
+

编辑备忘录

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ +
+ + + 取消 + +
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..fa89e63 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,121 @@ +{% extends 'base.html' %} + +{% block content %} + + + + +
+

📝 待办事项

+ + {% if incomplete_notes %} + {% for note in incomplete_notes %} +
+
+
+

+ + {{ note.title }} + +

+
+ + {{ note.priority }} + + + {% if note.due_time %} + + 🕒 截止: {{ note.due_time.strftime('%Y-%m-%d %H:%M') }} + + {% endif %} +
+
+
+ +

+ {{ note.content[:150] }}{% if note.content|length > 150 %}...{% endif %} +

+ + +
+ {% endfor %} + {% else %} +
+

暂无待办事项

+

添加一个新的备忘录开始记录吧!

+
+ {% endif %} +
+ + + {% if completed_notes %} +
+

✅ 已完成事项

+ + {% for note in completed_notes %} +
+
+
+

+ + {{ note.title }} + +

+
+ + {{ note.priority }} + + + + 已完成 + +
+
+
+ +

+ {{ note.content[:150] }}{% if note.content|length > 150 %}...{% endif %} +

+ + +
+ {% endfor %} +
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/view_note.html b/templates/view_note.html new file mode 100644 index 0000000..7eadc73 --- /dev/null +++ b/templates/view_note.html @@ -0,0 +1,84 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+
+

{{ note.title }}

+
+ + {{ note.priority }} + + + + {{ '已完成' if note.is_completed else '未完成' }} + +
+
+ + +
+ +
+

详情

+
+ {{ note.content }} +
+
+ +
+

备忘录信息

+ +
+
+ 创建时间: {{ note.created_at.strftime('%Y-%m-%d %H:%M:%S') }} +
+ + {% if note.due_time %} +
+ 预计完成时间: {{ note.due_time.strftime('%Y-%m-%d %H:%M:%S') }} +
+ {% else %} +
+ 预计完成时间: 未设置 +
+ {% endif %} + +
+ 优先级: + {% if note.priority == 'P0' %}紧急重要 + {% elif note.priority == 'P1' %}一般重要 + {% elif note.priority == 'P2' %}不太紧急 + {% endif %} +
+ +
+ 状态: {{ '已完成' if note.is_completed else '未完成' }} +
+
+
+ +
+ + 返回列表 + + + {% if not note.is_completed %} + + 标记为完成 + + {% else %} + + 标记为未完成 + + {% endif %} +
+
+{% endblock %} \ No newline at end of file