From c097562ddfae72583031679e6bda06ba184d1668 Mon Sep 17 00:00:00 2001 From: luxick Date: Tue, 22 Jan 2019 19:40:46 +0100 Subject: [PATCH] Add constants module. --- app.py | 16 ++++++++++++---- const.py | 9 +++++++++ db.py | 8 +++----- templates/seasonoverview.html | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 const.py diff --git a/app.py b/app.py index febb155..1179c3e 100644 --- a/app.py +++ b/app.py @@ -6,12 +6,13 @@ from flask import Flask, g, render_template, request, redirect, session import db import models +import const -logging.basicConfig(filename='estus-shots.log', level=logging.DEBUG) +logging.basicConfig(filename=const.LOG_PATH, level=logging.DEBUG) -logging.info(f'Starting with working dir: {os.getcwd()}') -logging.info(f'App file location: {os.path.abspath(__file__)}') +logging.info(f'Starting in working dir: {os.getcwd()}') +logging.info(f'App base path: {const.BASE_PATH}') app = Flask(__name__) @@ -127,8 +128,15 @@ def save_season(): def season_overview(id: int): sql, args = db.load_season(id) db_season = db.query_db(sql, args, one=True, cls=models.Season) + infos = { + 'Number': db_season.code, + 'Game': db_season.game, + 'Start Date': db_season.start, + 'End Date': db_season.end if db_season.end else 'Ongoing' + } model = { - 'title': f'{db_season.code} {db_season.game}' + 'title': f'{db_season.code} {db_season.game}', + 'season_info': infos } return render_template('seasonoverview.html', model=model) diff --git a/const.py b/const.py new file mode 100644 index 0000000..55ae27c --- /dev/null +++ b/const.py @@ -0,0 +1,9 @@ +import os + +BASE_PATH = os.path.dirname(os.path.realpath(__file__)) + +DATABASE_NAME = 'es_debug.db' +DATABASE_PATH = os.path.join(BASE_PATH, DATABASE_NAME) + +LOG_NAME = 'estus-shots.log' +LOG_PATH = os.path.join(BASE_PATH, LOG_NAME) \ No newline at end of file diff --git a/db.py b/db.py index 94f4b85..c559cf7 100644 --- a/db.py +++ b/db.py @@ -3,17 +3,15 @@ import logging as log from flask import g import models - - -DATABASE = 'database/es_debug.db' +import const def connect_db(): """Create a new sqlite3 connection and register it in 'g._database'""" db = getattr(g, '_database', None) if db is None: - log.info(f'Connecting {DATABASE}') - db = g._database = sqlite3.connect(DATABASE) + log.info(f'Connecting {const.DATABASE_NAME}') + db = g._database = sqlite3.connect(const.DATABASE_PATH) db.row_factory = sqlite3.Row return db diff --git a/templates/seasonoverview.html b/templates/seasonoverview.html index be3dee7..822237c 100644 --- a/templates/seasonoverview.html +++ b/templates/seasonoverview.html @@ -3,5 +3,40 @@ {% block title %}{{ model.title }}{% endblock %} {% block content %} +
+
+ {# Overview #} +
+
+
+ {{ model.title }} +
+
+
Infos
+ {% for item in model.season_info %} +
+
    +
  • + {{ item }}: + {{ model.season_info[item] }} +
  • +
+
+ {% endfor %} +
+
+
+ {# Episode List #} +
+
+
Episodes
+
+ Episode list here +
+
+
+ +
+
{% endblock %} \ No newline at end of file