From 0d9a3a54e11b0444b9600019bfcbdf171856d7f4 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Fri, 23 Jun 2023 22:28:16 +0200 Subject: [PATCH] app: Fix preference_from_base64 for generic PreferenceScore --- server/app.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/app.py b/server/app.py index 91c68c2..5cbf228 100644 --- a/server/app.py +++ b/server/app.py @@ -86,6 +86,13 @@ def adapt_score_list( return o +def preference_from_base64(in_data: str) -> PreferenceScore[Tag]: + return PreferenceScore.from_base64( + in_data=in_data, + get_tag=lambda i: Tag[i], + ) + + #### # Logging Config #### @@ -652,7 +659,7 @@ def recommend_adaptive() -> ResponseReturnValue: preferences = request.cookies.get( key=PREFERENCES_SCORE_NAME, default=PreferenceScore(), - type=PreferenceScore.from_base64, + type=preference_from_base64, ) * (1 if score_adapt > 0 else -1 if score_adapt < 0 else 0) if "max_length" not in request.args: # ask for max length before calculating to save time @@ -700,7 +707,7 @@ def cookies_rating(negative: bool) -> ResponseReturnValue: preferences = request.cookies.get( key=PREFERENCES_SCORE_NAME, default=PreferenceScore(), - type=PreferenceScore.from_base64, + type=preference_from_base64, ).adapt_score(element, score=3 if negative else -3) resp = redirect_back_or_okay() resp.set_cookie(PREFERENCES_SCORE_NAME, preferences.to_base64())