def __init__(self, tab_type, tab_id, sort=None, group_func=None, filters=None, search_text=None): """Create a new ItemList Note: outside classes shouldn't call this directly. Instead, they should use the app.item_list_pool.get() method. :param tab_type: type of tab that this list is for :param tab_id: id of the tab that this list is for :param sort: initial sort to use :param group_func: initial grouping to use :param filters: initial filters :param search_text: initial search text """ self.tab_type = tab_type self.tab_id = tab_id self.base_query = self._make_base_query(tab_type, tab_id) self.item_attributes = collections.defaultdict(dict) self.filter_set = itemfilter.ItemFilterSet() if filters is not None: self.filter_set.set_filters(filters) if sort is None: self.sorter = itemsort.DateSort() else: self.sorter = sort self.search_text = search_text self.group_func = group_func itemtrack.ItemTracker.__init__(self, call_on_ui_thread, self._make_query(), self._make_item_source())
def test_filter_items(self): filter_set = itemfilter.ItemFilterSet() downloaded_audio_item = FakeItemInfo('audio', True) downloaded_video_item = FakeItemInfo('video', True) audio_item = FakeItemInfo('audio', False) video_item = FakeItemInfo('video', False) # initially we should let everything through self.check_active_filters(filter_set, 'all') self.assertEquals(filter_set.filter(video_item), True) self.assertEquals(filter_set.filter(audio_item), True) self.assertEquals(filter_set.filter(downloaded_video_item), True) self.assertEquals(filter_set.filter(downloaded_audio_item), True) # test with 1 filter selected filter_set.select('downloaded') self.check_active_filters(filter_set, 'downloaded') self.assertEquals(filter_set.filter(video_item), False) self.assertEquals(filter_set.filter(audio_item), False) self.assertEquals(filter_set.filter(downloaded_video_item), True) self.assertEquals(filter_set.filter(downloaded_audio_item), True) # test with 2 filter selected. Both need to return True for the # filter set filter to pass filter_set.select('video') self.check_active_filters(filter_set, 'video', 'downloaded') self.assertEquals(filter_set.filter(video_item), False) self.assertEquals(filter_set.filter(audio_item), False) self.assertEquals(filter_set.filter(downloaded_video_item), True) self.assertEquals(filter_set.filter(downloaded_audio_item), False)
def __init__(self): self._sorter = DEFAULT_SORT self.model = widgetset.InfoListModel(self._sorter.sort_key, self._sorter.reverse) self.filter_set = itemfilter.ItemFilterSet() self.resort_on_update = False # maps ids -> items that are this list, but are filtered by our # ItemFilters self._hidden_items = {}
def test_filter_selection(self): # Test simple cases of changing filters filter_set = itemfilter.ItemFilterSet() # all should be the default self.check_active_filters(filter_set, 'all') # change to unplayed filter_set.select('unplayed') self.check_active_filters(filter_set, 'unplayed') # change back to all filter_set.select('all') self.check_active_filters(filter_set, 'all')
def test_podcast_filters_selection(self): # Test the filters for the podcasts tab. filter_set = itemfilter.ItemFilterSet() filter_set.select('all') self.check_active_filters(filter_set, 'all') # selecting video should auto-select downloaded by default filter_set.select('video') self.check_active_filters(filter_set, 'video', 'downloaded') # but if unplayed is selected, then it should not leave that alone filter_set.select('all') filter_set.select('unplayed') filter_set.select('video') self.check_active_filters(filter_set, 'video', 'unplayed') # if we select unplayed again nothing should change filter_set.select('unplayed') self.check_active_filters(filter_set, 'video', 'unplayed') # if we select downloaded, then unplayed should unselect filter_set.select('downloaded') self.check_active_filters(filter_set, 'video', 'downloaded')