mirror of
https://github.com/FAUSheppy/tmnf-replay-server.git
synced 2025-12-06 07:01:37 +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"
|
||||
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):
|
||||
|
||||
__tablename__ = "maps"
|
||||
@@ -139,7 +160,7 @@ def update_user_settings():
|
||||
|
||||
if key is None or value is None:
|
||||
return ("element in payload list does not contain key and value", 422)
|
||||
|
||||
|
||||
try:
|
||||
getattr(settings, key)
|
||||
setattr(settings, key, bool(value))
|
||||
@@ -260,7 +281,7 @@ class DataTable():
|
||||
if map_uid:
|
||||
print("Filter for map: {}".format(map_uid))
|
||||
query = query.filter(ParsedReplay.map_uid == map_uid)
|
||||
|
||||
|
||||
total = query.count()
|
||||
if self.searchValue:
|
||||
|
||||
@@ -312,7 +333,7 @@ class DataTable():
|
||||
|
||||
def _extracted_login_from_file(fullpath):
|
||||
'''Extract a login from a tmnf 2020 replay manually'''
|
||||
|
||||
|
||||
# TODO fix underscores in filenames #
|
||||
if "its_a_sheppy" in fullpath:
|
||||
login_from_filename = "its_a_sheppy"
|
||||
@@ -344,7 +365,7 @@ def replay_from_path(fullpath, uploader=None):
|
||||
upload_dt=ghost.upload_dt,
|
||||
cp_times=ghost.cp_times,
|
||||
game=ghost.game)
|
||||
|
||||
|
||||
# build database map object from replay #
|
||||
m = Map(map_uid=replay.map_uid, mapname=replay.map_uid, game=replay.game)
|
||||
|
||||
@@ -388,7 +409,7 @@ def ranks():
|
||||
|
||||
|
||||
@app.route("/map-info")
|
||||
def list():
|
||||
def map_info():
|
||||
player = flask.request.headers.get("X-Forwarded-Preferred-Username")
|
||||
header_col = ["Player", "Time", "Date", "Replay"]
|
||||
map_uid = flask.request.args.get("map_uid")
|
||||
@@ -425,6 +446,9 @@ def mapnames():
|
||||
allowed = ("A", "B", "C", "D", "E", "Fall", "Winter", "Spring", "Summer")
|
||||
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)
|
||||
|
||||
@app.route("/open-info")
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
{% include "upload-button.html" %}
|
||||
|
||||
<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">
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user