feat: user settings map filter & reload

This commit is contained in:
2024-01-13 07:24:05 +01:00
parent 8258f57a09
commit 8690c3b7bc
3 changed files with 55 additions and 11 deletions

View File

@@ -397,15 +397,22 @@ def mapnames():
'''Index Location''' '''Index Location'''
# TODO list by user # 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)) maps_query = db.session.query(Map).order_by(asc(Map.mapname))
# limit leaderboard to game # # limit leaderboard to game #
game = flask.request.args.get("game") settings = db.session.query(UserSettings).filter(UserSettings.user==player).first()
if game == "tm2020": if settings:
if not settings.show_tm_2020 and not settings.show_tmnf:
maps_query = maps_query.filter(Map.game=="tm2020") maps_query = maps_query.filter(Map.game=="tm2020")
elif game=="tmnf": latest_season = tm2020parser.get_latest_season_from_maps(maps_query.all())
maps_query = maps_query.filter(Map.game!="tm2020") # 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: else:
pass pass

View File

@@ -32,14 +32,16 @@ function submit(e){
} }
const s = e.target const s = e.target
console.log(s)
const json_data = JSON.stringify({ payload : [ { key : s.id, value : s.checked } ] }) const json_data = JSON.stringify({ payload : [ { key : s.id, value : s.checked } ] })
console.log(json_data)
fetch("/update-user-settings", { fetch("/update-user-settings", {
method: "POST", method: "POST",
credentials: "include", credentials: "include",
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: json_data body: json_data
} }
).then(response => {}) ).then(response => {
if(s.id.startsWith("show")){
window.location.reload()
}
})
} }

View File

@@ -5,6 +5,41 @@ import hashlib
import pygbx import pygbx
import xmltodict 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(): class GhostWrapper():
def __init__(self, fullpath, uploader): def __init__(self, fullpath, uploader):