From 1663a060d93f573f11fab1488a5181d20ebe6027 Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Sun, 30 Oct 2022 12:55:24 +0100 Subject: [PATCH 1/2] Add convert_times function to jinja2 (useful, if you want to include times in templates) --- iwm_browser/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iwm_browser/main.py b/iwm_browser/main.py index 45c561a..fad9176 100644 --- a/iwm_browser/main.py +++ b/iwm_browser/main.py @@ -8,14 +8,17 @@ import httpx import json import os import re +from . import utils basedir = os.path.dirname(__file__) app = FastAPI() app.mount("/static", StaticFiles(directory=basedir + "/static"), name="static") template_env = jinja2.Environment( - loader=jinja2.PackageLoader("iwm_browser", "templates"), - auto_reload=True - ) + loader=jinja2.PackageLoader("iwm_browser", "templates"), + auto_reload=True +) + +template_env.globals['convert_times'] = utils.convert_times BASE_URL = "http://make.fangam.es" THUMB_URL = "https://images.make.fangam.es" From f728070815e851bfd8c698c2cf6df2aa423723b7 Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Sun, 30 Oct 2022 13:03:14 +0100 Subject: [PATCH 2/2] Show user times + single level preview --- iwm_browser/static/search/searchResults.css | 25 ++++++++++++++-- iwm_browser/templates/levelInfo.html | 5 +++- iwm_browser/templates/search.html | 32 ++++++++++++--------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/iwm_browser/static/search/searchResults.css b/iwm_browser/static/search/searchResults.css index ac4cf51..4eb3f1b 100644 --- a/iwm_browser/static/search/searchResults.css +++ b/iwm_browser/static/search/searchResults.css @@ -26,6 +26,9 @@ .searchResults { font-size: 16px; } + .times { + display: none; + } } @@ -77,6 +80,21 @@ margin-bottom: 0.3rem; } +.levelTitle a:link, a:visited { + color: inherit; + text-decoration: initial; + cursor: auto; +} + +.levelTitle a:hover { + outline: 2px dotted blue; +} + +.levelTitle a:link:active { + color: inherit; + outline: 2px dotted blue; +} + .creatorName { justify-self: left; text-align: left; @@ -84,10 +102,11 @@ } .levelDescription { + overflow-x: scroll; text-align: left; - background-color: rgba(245, 222, 179, 0.128); - padding: 1em; - font-size: 1rem; + background-color: #30303a; + padding: 0.5rem; + font-size: small; /* justify-self: right; diff --git a/iwm_browser/templates/levelInfo.html b/iwm_browser/templates/levelInfo.html index 40e5e3e..5de70fa 100644 --- a/iwm_browser/templates/levelInfo.html +++ b/iwm_browser/templates/levelInfo.html @@ -33,10 +33,13 @@
Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}
by {{ map['CreatorName'] }}
{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎
+ {% if map['Description'] != ''%}
{{ map['Description'] }}
{% endif %}
Code:
-
First Clear: {{ map['FirstClearUsername'] }}
+
First Clear: {{ map['FirstClearUsername'] }}
+ {% set BestTime = convert_times(map['BestTimePlaytime']) %} +
Best Time: {{ map['BestTimeUsername'] }} [{{ BestTime[0] }}:{{ BestTime[1] }}:{{ BestTime[2] }}]
diff --git a/iwm_browser/templates/search.html b/iwm_browser/templates/search.html index c83fab2..c390101 100644 --- a/iwm_browser/templates/search.html +++ b/iwm_browser/templates/search.html @@ -60,21 +60,27 @@ {% if searchResults %}
{% for map in searchResults %} -
-
-
-
-
{{ map['Name'] }}
-
Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}
-
by {{ map['CreatorName'] }}
-
{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎
-
Code:
+
+
+
+
+ +
Difficulty: {{ '▲' * map['AverageUserDifficulty']|int }}
+
by {{ map['CreatorName'] }}
+
{{ map['NumThumbsUp'] }} 👍 {{ map['NumThumbsDown'] }} 👎
+ {% if map['Description'] != ''%}
{{ map['Description'] }}
{% endif %} +
Code:
+
+
+
First Clear: {{ map['FirstClearUsername'] }}
+ {% set BestTime = convert_times(map['BestTimePlaytime']) %} +
Best Time: {{ map['BestTimeUsername'] }} [{{ BestTime[0] }}:{{ BestTime[1] }}:{{ BestTime[2] }}]
+
+
-
- -
- {% endfor %} + {% endfor %} +

Page {{ searchPage+1 }}