-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (35 loc) · 1.29 KB
/
app.py
File metadata and controls
41 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask, render_template, request, redirect, flash
from data_access import init_db, log_progress, view_progress, edit_progress
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
# Initialize the database
init_db()
@app.route('/')
def index():
return render_template('index.html', progress=view_progress())
@app.route('/log', methods=['GET', 'POST'])
def log():
if request.method == 'POST':
try:
day = int(request.form['day'])
progress = request.form['progress']
log_progress(day, progress)
flash('Progress logged successfully!', 'success')
return redirect('/')
except ValueError:
flash('Invalid day number. Please enter a valid integer.', 'error')
except Exception as e:
flash(f'An error occurred: {str(e)}', 'error')
return render_template('log.html')
@app.route('/edit/<int:day>', methods=['POST'])
def edit(day):
try:
new_progress = request.json['progress']
edit_progress(day, new_progress)
flash('Progress updated successfully!', 'success')
return 'Progress updated successfully!', 200
except Exception as e:
return f'An error occurred: {str(e)}', 500
if __name__ == "__main__":
app.run(debug=True)