mirror of
https://github.com/FAUSheppy/tmnf-replay-server.git
synced 2025-12-06 15:11:36 +01:00
Compare commits
4 Commits
7a3ce3ef32
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e54f70eaac | |||
| a40bf057ee | |||
| 807860351d | |||
| d89ccf42ff |
34
server.py
34
server.py
@@ -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")
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user