Compare commits

...

4 Commits

Author SHA1 Message Date
e54f70eaac fix: correct ordering & remove debug prints
Some checks failed
Container Build for tmnf-replay-server / docker (push) Failing after 12s
2025-07-13 12:12:03 +02:00
a40bf057ee fix: don't use inbuild function name 2025-07-13 11:45:16 +02:00
807860351d whitespaces: trailing spaces 2025-07-13 11:45:03 +02:00
d89ccf42ff fix: current season selector tm2020 2025-07-13 11:44:33 +02:00
2 changed files with 33 additions and 5 deletions

View File

@@ -22,6 +22,27 @@ app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLITE_LOCATION") or "sqlite:///sqlite.db" app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLITE_LOCATION") or "sqlite:///sqlite.db"
db = SQLAlchemy(app) db = SQLAlchemy(app)
SEASON_ORDERING = ["Winter", "Spring", "Summer", "Fall"]
def filter_for_current_season(maps):
maps = list(maps)
year = str(datetime.datetime.now().year)
season = 0
for m in maps:
if year not in m.mapname:
continue
else:
for i, season_name in enumerate(SEASON_ORDERING):
if season_name in m.mapname and i > season:
season = i
filter_func = lambda m: SEASON_ORDERING[season] in m.mapname and year in m.mapname
maps_season = list(filter(filter_func, maps))
return maps_season
class Map(db.Model): class Map(db.Model):
__tablename__ = "maps" __tablename__ = "maps"
@@ -139,7 +160,7 @@ def update_user_settings():
if key is None or value is None: if key is None or value is None:
return ("element in payload list does not contain key and value", 422) return ("element in payload list does not contain key and value", 422)
try: try:
getattr(settings, key) getattr(settings, key)
setattr(settings, key, bool(value)) setattr(settings, key, bool(value))
@@ -260,7 +281,7 @@ class DataTable():
if map_uid: if map_uid:
print("Filter for map: {}".format(map_uid)) print("Filter for map: {}".format(map_uid))
query = query.filter(ParsedReplay.map_uid == map_uid) query = query.filter(ParsedReplay.map_uid == map_uid)
total = query.count() total = query.count()
if self.searchValue: if self.searchValue:
@@ -312,7 +333,7 @@ class DataTable():
def _extracted_login_from_file(fullpath): def _extracted_login_from_file(fullpath):
'''Extract a login from a tmnf 2020 replay manually''' '''Extract a login from a tmnf 2020 replay manually'''
# TODO fix underscores in filenames # # TODO fix underscores in filenames #
if "its_a_sheppy" in fullpath: if "its_a_sheppy" in fullpath:
login_from_filename = "its_a_sheppy" login_from_filename = "its_a_sheppy"
@@ -344,7 +365,7 @@ def replay_from_path(fullpath, uploader=None):
upload_dt=ghost.upload_dt, upload_dt=ghost.upload_dt,
cp_times=ghost.cp_times, cp_times=ghost.cp_times,
game=ghost.game) game=ghost.game)
# build database map object from replay # # build database map object from replay #
m = Map(map_uid=replay.map_uid, mapname=replay.map_uid, game=replay.game) m = Map(map_uid=replay.map_uid, mapname=replay.map_uid, game=replay.game)
@@ -388,7 +409,7 @@ def ranks():
@app.route("/map-info") @app.route("/map-info")
def list(): def map_info():
player = flask.request.headers.get("X-Forwarded-Preferred-Username") player = flask.request.headers.get("X-Forwarded-Preferred-Username")
header_col = ["Player", "Time", "Date", "Replay"] header_col = ["Player", "Time", "Date", "Replay"]
map_uid = flask.request.args.get("map_uid") map_uid = flask.request.args.get("map_uid")
@@ -425,6 +446,9 @@ def mapnames():
allowed = ("A", "B", "C", "D", "E", "Fall", "Winter", "Spring", "Summer") allowed = ("A", "B", "C", "D", "E", "Fall", "Winter", "Spring", "Summer")
maps_filtered = filter(lambda m: m.mapname.startswith(allowed), maps) maps_filtered = filter(lambda m: m.mapname.startswith(allowed), maps)
if settings.show_tm_2020_current:
maps_filtered = filter_for_current_season(maps_filtered)
return flask.render_template("index.html", maps=maps_filtered, player=player) return flask.render_template("index.html", maps=maps_filtered, player=player)
@app.route("/open-info") @app.route("/open-info")

View File

@@ -5,6 +5,10 @@
{% include "upload-button.html" %} {% include "upload-button.html" %}
<div class="user-settings"> <div class="user-settings">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="show_tm_2020_current">
<label class="form-check-label" for="show_tm_2020_current">Only current TM2020</label>
</div>
<div class="form-check form-switch"> <div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="show_tm_2020"> <input class="form-check-input" type="checkbox" role="switch" id="show_tm_2020">
<label class="form-check-label" for="show_tm_2020">Show All TM2020</label> <label class="form-check-label" for="show_tm_2020">Show All TM2020</label>