diff --git a/.gitignore b/.gitignore index 9837342..bdc8131 100644 --- a/.gitignore +++ b/.gitignore @@ -93,4 +93,5 @@ install.txt Screenshots/ .vscode typesheds/ -*.db \ No newline at end of file +*.db +*.env \ No newline at end of file diff --git a/app.py b/app.py index a42eac6..006a6a8 100644 --- a/app.py +++ b/app.py @@ -42,14 +42,14 @@ def close_connection(exception): def set_user_role(data): """Set the users role in the flask g object for later usage""" - g.is_editor = data == "write" + g.is_editor = data == "editor" def authorize(func): @functools.wraps(func) def wrapper(*args, **kwargs): try: - set_user_role(session["role"]) + set_user_role(session["user_type"]) except KeyError: return redirect("/login") return func(*args, **kwargs) @@ -57,11 +57,12 @@ def authorize(func): return wrapper -def get_role(password): +def get_user_type(password): + # TODO password hashing? if password == Config.WRITE_PW: - return "write" + return "editor" if password == Config.READ_PW: - return "read" + return "readonly" return False @@ -70,10 +71,10 @@ def login(): if request.method == "GET": return render_template("login.html") else: - role = get_role(request.form.get("password")) - if not role: + user_type = get_user_type(request.form.get("password")) + if not user_type: return redirect("/login") - session["role"] = role + session["user_type"] = user_type return redirect("/") @@ -167,7 +168,7 @@ def season_overview(season_id: int): "End Date": db_season.end if db_season.end else "Ongoing", } model = {"title": f"{db_season.code} {db_season.game}", "season_info": infos} - return render_template("seasonoverview.html", model=model) + return render_template("season_overview.html", model=model) @app.route("/seasons//episodes", methods=["GET"]) @@ -177,10 +178,10 @@ def episode_list(season_id: int): db_season = db.query_db(sql, args, one=True, cls=models.Season) model = {"season_id": season_id, "season_code": db_season.code} - return render_template("episodelist.html", model=model) + return render_template("episode_list.html", model=model) -@app.route("/seasons//new", methods=["GET"]) +@app.route("/seasons//episodes/new", methods=["GET"]) @authorize def episode_new(season_id: int): model = models.GenericFormModel( @@ -194,12 +195,13 @@ def episode_new(season_id: int): return render_template("generic_form.html", model=model, form=form) -@app.route("/episodes/save", methods=["POST"]) +@app.route("/seasons//episodes/edit/", methods=["GET", "POST"]) @authorize -def episode_save(): - form = forms.EpisodeForm(request.form) - val = form.validate() - return render_template("editepisode.html", form=form) +def episode_edit(season_id: int, episode_id: int): + if request.method == "GET": + pass + else: + pass @app.route("/players/new") diff --git a/db.py b/db.py index 7c47d33..9536eef 100644 --- a/db.py +++ b/db.py @@ -164,3 +164,13 @@ def load_season(id=None): args = (id,) sql += " order by season.start" return sql, args + + +def load_episodes(season_id: int = None): + sql = "select * from episode" + args = () + if season_id: + sql += " where episode.season_id = ?" + args = (season_id,) + sql += " order by episode.date" + return sql, args diff --git a/conf.sh b/environment similarity index 100% rename from conf.sh rename to environment diff --git a/models.py b/models.py index 7bdfc7d..ef440b6 100644 --- a/models.py +++ b/models.py @@ -101,3 +101,18 @@ class Season: self = cls(season_id, game, description, start, end, code) return self + + +@dataclass +class Episode: + id: int + season_id: int + title: str + date: datetime.date + start: datetime.time + end: datetime.time + + def __post_init__(self): + self.date = datetime.datetime.strptime(self.date, "%Y-%m-%d").date() + self.start = datetime.datetime.strptime(self.start, "%H:%M").time() + self.end = datetime.datetime.strptime(self.end, "%H:%M").time() diff --git a/schema.sql b/schema.sql index d96f09f..8559492 100644 --- a/schema.sql +++ b/schema.sql @@ -55,3 +55,22 @@ create table if not exists enemy create unique index if not exists enemy_id_uindex on enemy (id); + + + +create table if not exists episode +( + id integer not null + constraint episode_pk + primary key autoincrement, + season_id integer not null + constraint episode_season_id_fk + references season, + title text not null, + date text not null, + start text not null, + end text not null +); + +create unique index if not exists episode_id_uindex + on episode (id); diff --git a/templates/episodelist.html b/templates/episode_list.html similarity index 100% rename from templates/episodelist.html rename to templates/episode_list.html diff --git a/templates/season_list.html b/templates/season_list.html index 1a59274..3a0a044 100644 --- a/templates/season_list.html +++ b/templates/season_list.html @@ -44,7 +44,7 @@ - + Episode diff --git a/templates/seasonoverview.html b/templates/season_overview.html similarity index 100% rename from templates/seasonoverview.html rename to templates/season_overview.html