From: Christian Heller Date: Thu, 28 Nov 2024 14:27:34 +0000 (+0100) Subject: Improve/simplify templating. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/%7Broute%7D?a=commitdiff_plain;h=7d25aead70c6645a6085eb5592000897a41d74a5;p=ytplom Improve/simplify templating. --- diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index 9af8487..35786b4 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -5,8 +5,8 @@ {{ macros.nav_head(page_names, "files") }}

downloaded videos:

{% endblock %} diff --git a/src/templates/playlist.tmpl b/src/templates/playlist.tmpl index d62e7ea..b25d131 100644 --- a/src/templates/playlist.tmpl +++ b/src/templates/playlist.tmpl @@ -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%; } -{% for prev_video, next_video in tuples %} - -{{ prev_video.basename }} - -{{ next_video.basename }} - -{% endfor %} +pastfuture + + + + + + + + {% endblock %} diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index b207d49..e5f3c6f 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -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})