From: Christian Heller Date: Sat, 15 Feb 2025 01:53:16 +0000 (+0100) Subject: Minor refactoring of VideoFile tags config. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/move_down?a=commitdiff_plain;h=510d5eea47db782995ddbe07ce473f587fe96f4f;p=ytplom Minor refactoring of VideoFile tags config. --- diff --git a/src/ytplom/http.py b/src/ytplom/http.py index a9e3b8c..4f30f13 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -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: diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 2a27cc9..51a39aa 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -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