From 83bd19d91f1af41dc9ffb18d3d6e4833e19510d7 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 10 Nov 2022 08:21:54 -0700 Subject: [PATCH] Returned Video.censored when fetching video. --- modules/videos/models.py | 1 + modules/videos/test/test_lib.py | 2 ++ modules/videos/video/lib.py | 8 ++++---- wrolpi/files/models.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/videos/models.py b/modules/videos/models.py index 97d73c5b..8b9e6f44 100644 --- a/modules/videos/models.py +++ b/modules/videos/models.py @@ -235,6 +235,7 @@ class Video(ModelHelper, Base): d = dict( caption_path=self.caption_path, + censored=self.censored, channel=self.channel, channel_id=self.channel_id, modification_datetime=self.modification_datetime, diff --git a/modules/videos/test/test_lib.py b/modules/videos/test/test_lib.py index 3e059c42..c0f6b4d0 100644 --- a/modules/videos/test/test_lib.py +++ b/modules/videos/test/test_lib.py @@ -35,12 +35,14 @@ def test_search_censored_videos(test_session, simple_channel, video_factory): set_entries(map(str, range(5, 50))) videos, total = search_videos(filters=['censored'], order_by='id', limit=20) assert [i['video']['source_id'] for i in videos] == [str(i) for i in range(5)] + assert all(i['video']['censored'] for i in videos) assert total == 5 # First 25 are censored. set_entries(map(str, range(25, 50))) videos, total = search_videos(filters=['censored'], order_by='id', limit=20) assert [i['video']['source_id'] for i in videos] == [str(i) for i in range(20)] + assert all(i['video']['censored'] for i in videos) assert total == 25 diff --git a/modules/videos/video/lib.py b/modules/videos/video/lib.py index a785c9b1..73279599 100644 --- a/modules/videos/video/lib.py +++ b/modules/videos/video/lib.py @@ -84,6 +84,7 @@ def search_videos( order_by: str = None, filters: List[str] = None, ) -> Tuple[List[dict], int]: + filters = filters or [] wheres = ['v.video_path IS NOT NULL'] params = dict(search_str=search_str, offset=offset) @@ -91,11 +92,10 @@ def search_videos( wheres.append('v.channel_id = %(channel_id)s') params['channel_id'] = channel_id - # Filter for/against favorites, if it was provided - if isinstance(filters, list) and 'favorite' in filters: + # Apply filters. + if 'favorite' in filters: wheres.append('v.favorite IS NOT NULL') - - if isinstance(filters, list) and 'censored' in filters: + if 'censored' in filters: wheres.append('v.censored = true') if search_str: diff --git a/wrolpi/files/models.py b/wrolpi/files/models.py index b7a20869..43c447cf 100644 --- a/wrolpi/files/models.py +++ b/wrolpi/files/models.py @@ -43,7 +43,7 @@ class File(ModelHelper, Base): setweight(to_tsvector('english'::regconfig, COALESCE(d_text, '')), 'D'::"char") '''))) - prefetched_model = None # This may be filled with record matching `model. + prefetched_model = None # This may be filled with record matching `model`. def __repr__(self): path = str(self.path.relative_to(get_media_directory()))