home · contact · privacy
Improve/simplify templating.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 28 Nov 2024 14:27:34 +0000 (15:27 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 28 Nov 2024 14:27:34 +0000 (15:27 +0100)
src/templates/files.tmpl
src/templates/playlist.tmpl
src/ytplom/misc.py

index 9af8487d3687dd6e3baba4f601c044e2d1d479d1..35786b44cb2e8e172b72fe5a4041ca9ce946b57b 100644 (file)
@@ -5,8 +5,8 @@
 {{ macros.nav_head(page_names, "files") }}
 <p>downloaded videos:</p>
 <ul>
-{% for rel_path_b64, full_path in files %}
-<li><a href="/{{page_names.file}}/{{rel_path_b64}}">{{ full_path }}</a>
+{% for file in files %}
+<li><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a>
 {% endfor %}
 </ul>
 {% endblock %}
index d62e7ea7d98f931385150857dd60bf7939b1fbae..b25d1317b664b86fd501739125088afc50b79765 100644 (file)
@@ -29,8 +29,10 @@ window.onload = keep_updated;
 
 
 {% block css %}
-table { width: 100%; }
 #status { text-align: center; font-weight: bold; }
+table { width: 100%; }
+th { text-align: center; }
+td { vertical-align: top; }
 td.history { width: 50%; }
 {% endblock %}
 
@@ -49,13 +51,19 @@ td.history { width: 50%; }
 <input type="submit" name="reload" value="reload">
 </form>
 </td></tr>
-{% for prev_video, next_video in tuples %}
-<tr><td class="history">
-<a href="/{{page_names.file}}/{{prev_video.rel_path_b64}}">{{ prev_video.basename }}</a>
-</td><td class="history">
-<a href="/{{page_names.file}}/{{next_video.rel_path_b64}}">{{ next_video.basename }}</a>
-</td></tr>
-{% endfor %}
+<tr><th>past</th><th>future</th></tr>
+<tr>
+<td class="history">
+<ul>{% for file in prev_files %}
+<li><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{ file.basename }}</a>
+{% endfor %}</ul>
+</td>
+<td class="history">
+<ul>{% for file in next_files %}
+<li><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{ file.basename }}</a>
+{% endfor %}</ul>
+</td>
+</tr>
 </table>
 {% endblock %}
 
index b207d4903abcb5fb60c96a36f5843a96e67a4de2..e5f3c6ff2190814419c6cb8ce70b96ca0f6bf524 100644 (file)
@@ -47,12 +47,14 @@ PlayerUpdateId = NewType('PlayerUpdateId', str)
 B64Str = NewType('B64Str', str)
 PageNames: TypeAlias = dict[str, PathStr]
 DownloadsIndex: TypeAlias = dict[YoutubeId, PathStr]
-PlaylistTuples = list[tuple[Optional['VideoFile'], Optional['VideoFile']]]
 TemplateContext: TypeAlias = dict[
-        str, None | bool | PlayerUpdateId | Optional[PathStr] | YoutubeId
-        | QueryText | QuotaCost | list[FlagName] | 'VideoFile' | 'YoutubeVideo'
-        | PageNames | list['YoutubeVideo'] | list['YoutubeQuery']
-        | list[tuple[B64Str, PathStr]] | PlaylistTuples]
+        str,
+        None | bool
+        | PageNames | PathStr | PlayerUpdateId | QueryText | QuotaCost
+        | 'VideoFile' | YoutubeId | 'YoutubeVideo'
+        | list[FlagName] | list['VideoFile'] | list['YoutubeVideo']
+        | list['YoutubeQuery']
+]
 
 # major expected directories
 PATH_HOME = PathStr(environ.get('HOME', ''))
@@ -917,9 +919,9 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def _send_files_index(self) -> None:
         conn = DbConnection()
-        files = [(f.rel_path_b64, f.rel_path) for f in VideoFile.get_all(conn)]
+        files = VideoFile.get_all(conn)
         conn.commit_close()
-        files.sort(key=lambda t: t[1])
+        files.sort(key=lambda t: t.rel_path)
         self._send_rendered_template(NAME_TEMPLATE_FILES, {'files': files})
 
     def _send_missing_json(self) -> None:
@@ -936,22 +938,11 @@ class TaskHandler(BaseHTTPRequestHandler):
                         headers=[('Content-type', 'application/json')])
 
     def _send_playlist(self) -> None:
-        tuples: PlaylistTuples = []
-        i: int = 0
-        while True:
-            prev, next_ = None, None
-            if len(self.server.player.prev_files) > i:
-                prev = self.server.player.prev_files[i]
-            if len(self.server.player.next_files) > i:
-                next_ = self.server.player.next_files[i]
-            if not (prev or next_):
-                break
-            tuples += [(prev, next_)]
-            i += 1
         self._send_rendered_template(
                 NAME_TEMPLATE_PLAYLIST,
                 {'last_update': self.server.player.last_update,
                  'running': self.server.player.is_running,
                  'paused': self.server.player.is_paused,
                  'current_video': self.server.player.current_file,
-                 'tuples': tuples})
+                 'prev_files': self.server.player.prev_files,
+                 'next_files': self.server.player.next_files})