home · contact · privacy
Add basic filtering by filename to /files view. master
authorChristian Heller <c.heller@plomlompom.de>
Thu, 28 Nov 2024 21:14:53 +0000 (22:14 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 28 Nov 2024 21:14:53 +0000 (22:14 +0100)
src/templates/files.tmpl
src/ytplom/misc.py

index 35786b44cb2e8e172b72fe5a4041ca9ce946b57b..72f99ac1557ef9d781161c434096113c2e6321b4 100644 (file)
@@ -3,7 +3,10 @@
 
 {% block body %}
 {{ macros.nav_head(page_names, "files") }}
 
 {% block body %}
 {{ macros.nav_head(page_names, "files") }}
-<p>downloaded videos:</p>
+<form method="GET">
+filter: <input name="filter" value="{{filter}}" /><input type="submit" value="filter" />
+</form>
+<p>downloaded videos ({{files|length}}):</p>
 <ul>
 {% for file in files %}
 <li><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a>
 <ul>
 {% for file in files %}
 <li><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a>
index a85e6bc760f3fc344cf19c60d51fab0a88af0d71..f35a9c8cb89f22c3f2a805880595deff77d5606c 100644 (file)
@@ -46,14 +46,15 @@ FlagsInt = NewType('FlagsInt', int)
 AmountDownloads = NewType('AmountDownloads', int)
 PlayerUpdateId = NewType('PlayerUpdateId', str)
 B64Str = NewType('B64Str', str)
 AmountDownloads = NewType('AmountDownloads', int)
 PlayerUpdateId = NewType('PlayerUpdateId', str)
 B64Str = NewType('B64Str', str)
+ParamsStr = NewType('ParamsStr', str)
 PageNames: TypeAlias = dict[str, PathStr]
 DownloadsIndex: TypeAlias = dict[YoutubeId, PathStr]
 FilesWithIndex: TypeAlias = list[tuple[int, 'VideoFile']]
 TemplateContext: TypeAlias = dict[
         str,
         None | bool
 PageNames: TypeAlias = dict[str, PathStr]
 DownloadsIndex: TypeAlias = dict[YoutubeId, PathStr]
 FilesWithIndex: TypeAlias = list[tuple[int, 'VideoFile']]
 TemplateContext: TypeAlias = dict[
         str,
         None | bool
-        | FilesWithIndex | PageNames | PathStr | PlayerUpdateId | QueryText
-        | QuotaCost | 'VideoFile' | YoutubeId | 'YoutubeVideo'
+        | FilesWithIndex | PageNames | ParamsStr | PathStr | PlayerUpdateId
+        | QueryText | QuotaCost | 'VideoFile' | YoutubeId | 'YoutubeVideo'
         | list[FlagName] | list['VideoFile'] | list['YoutubeVideo']
         | list['YoutubeQuery']
 ]
         | list[FlagName] | list['VideoFile'] | list['YoutubeVideo']
         | list['YoutubeQuery']
 ]
@@ -856,7 +857,8 @@ class TaskHandler(BaseHTTPRequestHandler):
             elif PAGE_NAMES['download'] == page_name:
                 self._send_or_download_video(YoutubeId(toks_url[2]))
             elif PAGE_NAMES['files'] == page_name:
             elif PAGE_NAMES['download'] == page_name:
                 self._send_or_download_video(YoutubeId(toks_url[2]))
             elif PAGE_NAMES['files'] == page_name:
-                self._send_files_index()
+                filter_ = ParamsStr(parse_qs(url.query).get('filter', [''])[0])
+                self._send_files_index(filter_)
             elif PAGE_NAMES['file'] == page_name:
                 self._send_file_data(B64Str(toks_url[2]))
             elif PAGE_NAMES['yt_result'] == page_name:
             elif PAGE_NAMES['file'] == page_name:
                 self._send_file_data(B64Str(toks_url[2]))
             elif PAGE_NAMES['yt_result'] == page_name:
@@ -960,12 +962,13 @@ class TaskHandler(BaseHTTPRequestHandler):
                 NAME_TEMPLATE_FILE_DATA,
                 {'file': file, 'flag_names': list(FILE_FLAGS)})
 
                 NAME_TEMPLATE_FILE_DATA,
                 {'file': file, 'flag_names': list(FILE_FLAGS)})
 
-    def _send_files_index(self) -> None:
+    def _send_files_index(self, filter_: ParamsStr) -> None:
         conn = DbConnection()
         conn = DbConnection()
-        files = VideoFile.get_all(conn)
+        files = [f for f in VideoFile.get_all(conn) if filter_ in f.rel_path]
         conn.commit_close()
         files.sort(key=lambda t: t.rel_path)
         conn.commit_close()
         files.sort(key=lambda t: t.rel_path)
-        self._send_rendered_template(NAME_TEMPLATE_FILES, {'files': files})
+        self._send_rendered_template(NAME_TEMPLATE_FILES,
+                                     {'files': files, 'filter': filter_})
 
     def _send_missing_json(self) -> None:
         conn = DbConnection()
 
     def _send_missing_json(self) -> None:
         conn = DbConnection()