Add new episode editor.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -93,4 +93,5 @@ install.txt
|
|||||||
Screenshots/
|
Screenshots/
|
||||||
.vscode
|
.vscode
|
||||||
typesheds/
|
typesheds/
|
||||||
*.db
|
*.db
|
||||||
|
*.env
|
||||||
34
app.py
34
app.py
@@ -42,14 +42,14 @@ def close_connection(exception):
|
|||||||
|
|
||||||
def set_user_role(data):
|
def set_user_role(data):
|
||||||
"""Set the users role in the flask g object for later usage"""
|
"""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):
|
def authorize(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
set_user_role(session["role"])
|
set_user_role(session["user_type"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect("/login")
|
return redirect("/login")
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
@@ -57,11 +57,12 @@ def authorize(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def get_role(password):
|
def get_user_type(password):
|
||||||
|
# TODO password hashing?
|
||||||
if password == Config.WRITE_PW:
|
if password == Config.WRITE_PW:
|
||||||
return "write"
|
return "editor"
|
||||||
if password == Config.READ_PW:
|
if password == Config.READ_PW:
|
||||||
return "read"
|
return "readonly"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -70,10 +71,10 @@ def login():
|
|||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
else:
|
else:
|
||||||
role = get_role(request.form.get("password"))
|
user_type = get_user_type(request.form.get("password"))
|
||||||
if not role:
|
if not user_type:
|
||||||
return redirect("/login")
|
return redirect("/login")
|
||||||
session["role"] = role
|
session["user_type"] = user_type
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
@@ -167,7 +168,7 @@ def season_overview(season_id: int):
|
|||||||
"End Date": db_season.end if db_season.end else "Ongoing",
|
"End Date": db_season.end if db_season.end else "Ongoing",
|
||||||
}
|
}
|
||||||
model = {"title": f"{db_season.code} {db_season.game}", "season_info": infos}
|
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/<season_id>/episodes", methods=["GET"])
|
@app.route("/seasons/<season_id>/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)
|
db_season = db.query_db(sql, args, one=True, cls=models.Season)
|
||||||
|
|
||||||
model = {"season_id": season_id, "season_code": db_season.code}
|
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/<season_id>/new", methods=["GET"])
|
@app.route("/seasons/<season_id>/episodes/new", methods=["GET"])
|
||||||
@authorize
|
@authorize
|
||||||
def episode_new(season_id: int):
|
def episode_new(season_id: int):
|
||||||
model = models.GenericFormModel(
|
model = models.GenericFormModel(
|
||||||
@@ -194,12 +195,13 @@ def episode_new(season_id: int):
|
|||||||
return render_template("generic_form.html", model=model, form=form)
|
return render_template("generic_form.html", model=model, form=form)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/episodes/save", methods=["POST"])
|
@app.route("/seasons/<season_id>/episodes/edit/<episode_id>", methods=["GET", "POST"])
|
||||||
@authorize
|
@authorize
|
||||||
def episode_save():
|
def episode_edit(season_id: int, episode_id: int):
|
||||||
form = forms.EpisodeForm(request.form)
|
if request.method == "GET":
|
||||||
val = form.validate()
|
pass
|
||||||
return render_template("editepisode.html", form=form)
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@app.route("/players/new")
|
@app.route("/players/new")
|
||||||
|
|||||||
10
db.py
10
db.py
@@ -164,3 +164,13 @@ def load_season(id=None):
|
|||||||
args = (id,)
|
args = (id,)
|
||||||
sql += " order by season.start"
|
sql += " order by season.start"
|
||||||
return sql, args
|
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
|
||||||
|
|||||||
15
models.py
15
models.py
@@ -101,3 +101,18 @@ class Season:
|
|||||||
|
|
||||||
self = cls(season_id, game, description, start, end, code)
|
self = cls(season_id, game, description, start, end, code)
|
||||||
return self
|
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()
|
||||||
|
|||||||
19
schema.sql
19
schema.sql
@@ -55,3 +55,22 @@ create table if not exists enemy
|
|||||||
|
|
||||||
create unique index if not exists enemy_id_uindex
|
create unique index if not exists enemy_id_uindex
|
||||||
on enemy (id);
|
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);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
<span class="fas fa-pencil-alt"></span>
|
<span class="fas fa-pencil-alt"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a class="btn btn-default" href="#">
|
<a class="btn btn-default" href="{{ url_for("episode_new", season_id = item.id) }}">
|
||||||
<span class="fas fa-plus"></span> Episode
|
<span class="fas fa-plus"></span> Episode
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user