From e5e09b4c680715b33bdd38fe88efcade876098c6 Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Fri, 29 Nov 2024 01:48:37 +0100 Subject: [PATCH] To files view, add VideoFile.present filter. --- src/templates/files.tmpl | 16 +++++++++++----- src/ytplom/misc.py | 17 +++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index 72f99ac..0dda3db 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -4,12 +4,18 @@ {% block body %} {{ macros.nav_head(page_names, "files") }} <form method="GET"> -filter: <input name="filter" value="{{filter}}" /><input type="submit" value="filter" /> +filter: <input name="filter" value="{{filter}}" /> +show absent: <input type="checkbox" name="show_absent" {% if show_absent %}checked{% endif %}/> +<input type="submit" value="filter" /> </form> -<p>downloaded videos ({{files|length}}):</p> -<ul> +<p>known files (shown: {{files|length}}):</p> +<table> +<tr><th>present</th><th>path</th></td> {% for file in files %} -<li><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a> +<tr> +<td><input type="checkbox"{% if file.present %} checked{% endif %} disabled/></td> +<td><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a></td> +</tr> {% endfor %} -</ul> +</table> {% endblock %} diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index f35a9c8..0cd4c92 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -857,8 +857,10 @@ class TaskHandler(BaseHTTPRequestHandler): elif PAGE_NAMES['download'] == page_name: self._send_or_download_video(YoutubeId(toks_url[2])) elif PAGE_NAMES['files'] == page_name: - filter_ = ParamsStr(parse_qs(url.query).get('filter', [''])[0]) - self._send_files_index(filter_) + params = parse_qs(url.query) + filter_ = ParamsStr(params.get('filter', [''])[0]) + show_absent = params.get('show_absent', [False])[0] + self._send_files_index(filter_, bool(show_absent)) elif PAGE_NAMES['file'] == page_name: self._send_file_data(B64Str(toks_url[2])) elif PAGE_NAMES['yt_result'] == page_name: @@ -962,13 +964,16 @@ class TaskHandler(BaseHTTPRequestHandler): NAME_TEMPLATE_FILE_DATA, {'file': file, 'flag_names': list(FILE_FLAGS)}) - def _send_files_index(self, filter_: ParamsStr) -> None: + def _send_files_index(self, filter_: ParamsStr, show_absent: bool) -> None: conn = DbConnection() - files = [f for f in VideoFile.get_all(conn) if filter_ in f.rel_path] + files = [f for f in VideoFile.get_all(conn) + if (filter_ in f.rel_path) and (show_absent or f.present)] conn.commit_close() files.sort(key=lambda t: t.rel_path) - self._send_rendered_template(NAME_TEMPLATE_FILES, - {'files': files, 'filter': filter_}) + self._send_rendered_template( + NAME_TEMPLATE_FILES, + {'files': files, 'filter': filter_, + 'show_absent': show_absent}) def _send_missing_json(self) -> None: conn = DbConnection() -- 2.30.2