Add new episode editor.

This commit is contained in:
2019-02-16 11:50:11 +01:00
parent c3a40978eb
commit ded8fc586a
9 changed files with 65 additions and 18 deletions

3
.gitignore vendored
View File

@@ -93,4 +93,5 @@ install.txt
Screenshots/
.vscode
typesheds/
*.db
*.db
*.env

34
app.py
View File

@@ -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/<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)
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
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/<season_id>/episodes/edit/<episode_id>", 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")

10
db.py
View File

@@ -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

View File

@@ -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()

View File

@@ -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);

View File

@@ -44,7 +44,7 @@
<span class="fas fa-pencil-alt"></span>
</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
</a>
</td>