feat: Added timezone environment variable
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import pytz
|
||||||
from flask import Flask, render_template, request, redirect, url_for, session
|
from flask import Flask, render_template, request, redirect, url_for, session
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import date as datedate
|
from datetime import date as datedate
|
||||||
@@ -10,6 +11,9 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
TIMEZONE = os.getenv('TZ', 'UTC')
|
||||||
|
tz = pytz.timezone(TIMEZONE)
|
||||||
|
|
||||||
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'defaultsecret')
|
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'defaultsecret')
|
||||||
app.config['LOGIN_ENABLED'] = os.getenv('LOGIN_ENABLED', 'false').lower() == 'true'
|
app.config['LOGIN_ENABLED'] = os.getenv('LOGIN_ENABLED', 'false').lower() == 'true'
|
||||||
|
|
||||||
@@ -52,13 +56,13 @@ def index():
|
|||||||
conn.close()
|
conn.close()
|
||||||
has_prev = page > 1
|
has_prev = page > 1
|
||||||
has_next = offset + per_page < total
|
has_next = offset + per_page < total
|
||||||
today = datedate.today().isoformat()
|
today = datetime.now(tz).date().isoformat()
|
||||||
now = dt.now()
|
now = datetime.now(tz)
|
||||||
return render_template('index.html', entries=entries, today=today, page=page, has_prev=has_prev, has_next=has_next, now=now)
|
return render_template('index.html', entries=entries, today=today, page=page, has_prev=has_prev, has_next=has_next, now=now)
|
||||||
|
|
||||||
@app.route('/add', methods=['POST'])
|
@app.route('/add', methods=['POST'])
|
||||||
def add_entry():
|
def add_entry():
|
||||||
date = request.form.get('date', datetime.today().strftime('%Y-%m-%d'))
|
date = request.form.get('date', datetime.now(tz).strftime('%Y-%m-%d'))
|
||||||
content = request.form.get('content', '')
|
content = request.form.get('content', '')
|
||||||
if content.strip():
|
if content.strip():
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -116,7 +120,6 @@ def require_login():
|
|||||||
if app.config['LOGIN_ENABLED'] and not session.get('logged_in') and request.endpoint not in ['login', 'static']:
|
if app.config['LOGIN_ENABLED'] and not session.get('logged_in') and request.endpoint not in ['login', 'static']:
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
# Edit entry route
|
|
||||||
@app.route('/edit/<int:entry_id>', methods=['GET', 'POST'])
|
@app.route('/edit/<int:entry_id>', methods=['GET', 'POST'])
|
||||||
def edit_entry(entry_id):
|
def edit_entry(entry_id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -138,7 +141,6 @@ def edit_entry(entry_id):
|
|||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
return render_template('edit.html', entry=entry)
|
return render_template('edit.html', entry=entry)
|
||||||
|
|
||||||
# Edit entry via modal
|
|
||||||
@app.route('/edit_modal', methods=['POST'])
|
@app.route('/edit_modal', methods=['POST'])
|
||||||
def edit_entry_modal():
|
def edit_entry_modal():
|
||||||
entry_id = request.form.get('id')
|
entry_id = request.form.get('id')
|
||||||
@@ -153,7 +155,6 @@ def edit_entry_modal():
|
|||||||
conn.close()
|
conn.close()
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
# Delete entry route
|
|
||||||
@app.route('/delete/<int:entry_id>', methods=['POST'])
|
@app.route('/delete/<int:entry_id>', methods=['POST'])
|
||||||
def delete_entry(entry_id):
|
def delete_entry(entry_id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -167,4 +168,4 @@ def delete_entry(entry_id):
|
|||||||
init_db()
|
init_db()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000)
|
||||||
@@ -31,6 +31,8 @@ spec:
|
|||||||
value: "echolog"
|
value: "echolog"
|
||||||
- name: SECRET_KEY
|
- name: SECRET_KEY
|
||||||
value: "bgSNcrA0gZiRX9LbZmminf2LItEXeo"
|
value: "bgSNcrA0gZiRX9LbZmminf2LItEXeo"
|
||||||
|
- name: TZ
|
||||||
|
value: "Europe/London"
|
||||||
- name: LOGIN_ENABLED
|
- name: LOGIN_ENABLED
|
||||||
value: "true"
|
value: "true"
|
||||||
- name: LOGIN_USERNAME
|
- name: LOGIN_USERNAME
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
Flask
|
Flask
|
||||||
mysql-connector-python
|
mysql-connector-python
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
pytz
|
||||||
Reference in New Issue
Block a user