|
@@ -0,0 +1,54 @@
|
|
|
|
+from flask import Flask, render_template, request, redirect, url_for
|
|
|
|
+import json
|
|
|
|
+import os
|
|
|
|
+
|
|
|
|
+app = Flask(__name__)
|
|
|
|
+
|
|
|
|
+# File to store checklist items
|
|
|
|
+CHECKLIST_FILE = 'checklist.json'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# Load checklist items from a file
|
|
|
|
+def load_checklist():
|
|
|
|
+ if os.path.exists(CHECKLIST_FILE):
|
|
|
|
+ with open(CHECKLIST_FILE, 'r') as file:
|
|
|
|
+ return json.load(file)
|
|
|
|
+ return []
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# Save checklist items to a file
|
|
|
|
+def save_checklist(items):
|
|
|
|
+ with open(CHECKLIST_FILE, 'w') as file:
|
|
|
|
+ json.dump(items, file)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# In-memory storage for checklist items
|
|
|
|
+checklist_items = load_checklist()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@app.route('/', methods=['GET', 'POST'])
|
|
|
|
+def index():
|
|
|
|
+ if request.method == 'POST':
|
|
|
|
+ item = request.form.get('item')
|
|
|
|
+ if item:
|
|
|
|
+ checklist_items.append({'name': item, 'checked': False})
|
|
|
|
+ save_checklist(checklist_items) # Save to file after adding
|
|
|
|
+ return redirect(url_for('index'))
|
|
|
|
+ return render_template('index.html', items=checklist_items)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@app.route('/check/<int:item_id>')
|
|
|
|
+def check(item_id):
|
|
|
|
+ if 0 <= item_id < len(checklist_items):
|
|
|
|
+ checklist_items[item_id]['checked'] = not checklist_items[item_id]['checked']
|
|
|
|
+ save_checklist(checklist_items) # Save to file after checking
|
|
|
|
+ return redirect(url_for('index'))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@app.route('/list')
|
|
|
|
+def list():
|
|
|
|
+ return render_template('list.html', items=checklist_items)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ app.run(debug=True)
|