home · contact · privacy
Minor refactoring of VideoFile tags config.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 15 Feb 2025 01:53:16 +0000 (02:53 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 15 Feb 2025 01:53:16 +0000 (02:53 +0100)
src/ytplom/http.py
src/ytplom/misc.py

index a9e3b8cc4bd881e26ab3ab333346852f719797a8..4f30f131b95ec65b7dc886c98d44ee88c09f285b 100644 (file)
@@ -123,7 +123,7 @@ class _TaskHandler(PlomHttpHandler):
             self._redirect(Path(self.postvars.first_for('redir_target')))
             return
         if not (self.server.config.allow_file_edit  # also if whitelist, …
-                and self.server.config.whitelist_tags_display.empty):
+                and self.server.config.tags_display_whitelist.empty):
             self.send_http(b'no way', code=403)  # … cuz input form under …
             return  # … this display filter might have suppressed set tags
         with DbConn() as conn:
index 2a27cc99f05eb35c76ed0e9096ee4d47a917f2a0..51a39aa0092e1b89e3c0ed91dd8b124497db47d3 100644 (file)
@@ -29,9 +29,9 @@ DEFAULTS = {
     'port_remote': 8090,
     'background_color': '#ffffff',
     'queries_cutoff': '',
-    'whitelist_tags_prefilter': [],
-    'needed_tags_prefilter': [],
-    'whitelist_tags_display': [],
+    'tags_prefilter_whitelist': [],
+    'tags_prefilter_needed': [],
+    'tags_display_whitelist': [],
     'allow_file_edit': True
 }
 
@@ -166,9 +166,9 @@ class Config:
     background_color: str
     allow_file_edit: bool
     queries_cutoff: DatetimeStr
-    needed_tags_prefilter: TagSet
-    whitelist_tags_prefilter: TagSet
-    whitelist_tags_display: TagSet
+    tags_prefilter_needed: TagSet
+    tags_prefilter_whitelist: TagSet
+    tags_display_whitelist: TagSet
 
     def __init__(self):
         def set_attrs_from_dict(d):
@@ -182,10 +182,9 @@ class Config:
         set_attrs_from_dict({k[len(ENVIRON_PREFIX):].lower(): v
                              for k, v in environ.items()
                              if k.isupper() and k.startswith(ENVIRON_PREFIX)})
-        for attr_name in ('needed_tags_prefilter',
-                          'whitelist_tags_prefilter',
-                          'whitelist_tags_display'):
-            setattr(VideoFile, attr_name, getattr(self, attr_name))
+        for attr_key in [key for key in self.__class__.__annotations__.keys()
+                         if key.startswith('tags_')]:
+            setattr(VideoFile, attr_key, getattr(self, attr_key))
 
 
 class YoutubeQuery(DbData):
@@ -329,9 +328,9 @@ class VideoFile(DbData):
     digest: Hash
     tags: TagSet
     # class attributes
-    needed_tags_prefilter: TagSet
-    whitelist_tags_prefilter: TagSet
-    whitelist_tags_display: TagSet
+    tags_prefilter_needed: TagSet
+    tags_prefilter_whitelist: TagSet
+    tags_display_whitelist: TagSet
 
     def __init__(self,
                  digest: Optional[Hash],
@@ -386,22 +385,22 @@ class VideoFile(DbData):
             f for f in cls.get_all(conn)
             if (show_absent or f.present)
             and str(filter_path).lower() in str(f.rel_path).lower()
-            and (cls.needed_tags_prefilter.are_all_in(f.tags)
-                 or not cls.whitelist_tags_prefilter.all_also_in(f.tags).empty)
-            and needed_tags_seen.whitelisted(cls.whitelist_tags_display
+            and (cls.tags_prefilter_needed.are_all_in(f.tags)
+                 or not cls.tags_prefilter_whitelist.all_also_in(f.tags).empty)
+            and needed_tags_seen.whitelisted(cls.tags_display_whitelist
                                              ).are_all_in(f.tags)]
 
     @property
     def tags_showable(self) -> TagSet:
-        """Show .tags passing .whitelist_tags_display, if latter set."""
-        return self.tags.whitelisted(self.whitelist_tags_display)
+        """Show .tags passing .tags_display_whitelist, if latter set."""
+        return self.tags.whitelisted(self.tags_display_whitelist)
 
     def unused_tags(self, conn: DbConn) -> TagSet:
         """Return tags used among other VideoFiles, not in self."""
         tags = TagSet()
         for file in self.get_all(conn):
             tags.add(file.tags.all_not_in(self.tags).whitelisted(
-                self.whitelist_tags_display))
+                self.tags_display_whitelist))
         return tags
 
     @property