mirror of
https://github.com/FAUSheppy/tmnf-replay-server.git
synced 2025-12-05 22:51:37 +01:00
feat: user settings map filter & reload
This commit is contained in:
23
server.py
23
server.py
@@ -397,17 +397,24 @@ def mapnames():
|
||||
'''Index Location'''
|
||||
|
||||
# TODO list by user
|
||||
player = flask.request.headers.get("X-Forwarded-Preferred-Username")
|
||||
player = flask.request.headers.get("X-Forwarded-Preferred-Username") or "anonymous"
|
||||
maps_query = db.session.query(Map).order_by(asc(Map.mapname))
|
||||
|
||||
# limit leaderboard to game #
|
||||
game = flask.request.args.get("game")
|
||||
if game == "tm2020":
|
||||
maps_query = maps_query.filter(Map.game=="tm2020")
|
||||
elif game=="tmnf":
|
||||
maps_query = maps_query.filter(Map.game!="tm2020")
|
||||
else:
|
||||
pass
|
||||
settings = db.session.query(UserSettings).filter(UserSettings.user==player).first()
|
||||
if settings:
|
||||
if not settings.show_tm_2020 and not settings.show_tmnf:
|
||||
maps_query = maps_query.filter(Map.game=="tm2020")
|
||||
latest_season = tm2020parser.get_latest_season_from_maps(maps_query.all())
|
||||
# handle no replays #
|
||||
if latest_season:
|
||||
maps_query = maps_query.filter(Map.map_uid.like("{}%".format(latest_season)))
|
||||
elif settings.show_tm_2020 and not settings.show_tmnf:
|
||||
maps_query = maps_query.filter(Map.game=="tm2020")
|
||||
elif not settings.show_tm_2020 and settings.show_tmnf:
|
||||
maps_query = maps_query.filter(Map.game=="tmnf")
|
||||
else:
|
||||
pass
|
||||
|
||||
maps = maps_query.all()
|
||||
|
||||
|
||||
@@ -32,14 +32,16 @@ function submit(e){
|
||||
}
|
||||
|
||||
const s = e.target
|
||||
console.log(s)
|
||||
const json_data = JSON.stringify({ payload : [ { key : s.id, value : s.checked } ] })
|
||||
console.log(json_data)
|
||||
fetch("/update-user-settings", {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json_data
|
||||
}
|
||||
).then(response => {})
|
||||
).then(response => {
|
||||
if(s.id.startsWith("show")){
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,6 +5,41 @@ import hashlib
|
||||
import pygbx
|
||||
import xmltodict
|
||||
|
||||
def get_latest_season_from_maps(maps):
|
||||
'''Determine the latest season in DB'''
|
||||
|
||||
order = ["Winter", "Spring", "Summer", "Fall"]
|
||||
|
||||
max_year = 0
|
||||
max_season = "Winter"
|
||||
|
||||
if not maps:
|
||||
return
|
||||
|
||||
for m in maps:
|
||||
splitted = m.map_uid.split(" ")
|
||||
|
||||
# not a campain map #
|
||||
if len(splitted) < 3:
|
||||
return
|
||||
|
||||
season = splitted[0]
|
||||
year = splitted[1]
|
||||
|
||||
# also not a campaing map #
|
||||
if not season in order:
|
||||
return
|
||||
try:
|
||||
year = int(year)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
if year > max_year or year == max_year and order.index(season) >= order.index(max_season):
|
||||
max_year = year
|
||||
max_season = season
|
||||
|
||||
return "{} {}".format(max_season, max_year)
|
||||
|
||||
class GhostWrapper():
|
||||
|
||||
def __init__(self, fullpath, uploader):
|
||||
|
||||
Reference in New Issue
Block a user