From 3fffd22996481ce5e7c819896dce54435a37b6ae Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Tue, 20 Sep 2022 10:46:40 -0500 Subject: [PATCH] Fixes for add_category/genre_when_multi_category settings. #884 --- fanficfare/story.py | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/fanficfare/story.py b/fanficfare/story.py index 76dcad7d..d9a87b17 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -1079,14 +1079,16 @@ class Story(Requestable): ## there's more than one category value. Does not work ## consistently well if you try to include_in_ chain genre ## back into category--breaks with fandoms sites like AO3 - if listname == 'genre' and self.getConfig('add_genre_when_multi_category') and len(self.getList('category', - removeallentities=False, - # to avoid inf loops if genre/cat substs - includelist=includelist+[listname], - doreplacements=False, - skip_cache=True, - seen_list=seen_list - )) > 1: + if( listname == 'genre' and self.getConfig('add_genre_when_multi_category') + and len(self.getList('category', + removeallentities=False, + # to avoid inf loops if genre/cat substs + includelist=includelist+[listname], + doreplacements=False, + skip_cache=True, + seen_list=seen_list + )) > 1 + and self.getConfig('add_genre_when_multi_category') not in retlist ): retlist.append(self.getConfig('add_genre_when_multi_category')) if retlist: @@ -1111,15 +1113,24 @@ class Story(Requestable): # remove dups and sort. retlist = sorted(list(set(retlist))) - ## Add value of add_genre_when_multi_category to - ## category if there's more than one category - ## value (before this, obviously). Applied - ## *after* doReplacements. For normalization - ## crusaders who want Crossover as a category - ## instead of genre. Moved after dedup'ing so - ## consolidated category values don't count. - if listname == 'category' and self.getConfig('add_category_when_multi_category') and len(retlist) > 1: - retlist.append(self.getConfig('add_category_when_multi_category')) + ## Add value of add_genre_when_multi_category to + ## category if there's more than one category + ## value (before this, obviously). Applied + ## *after* doReplacements. For normalization + ## crusaders who want Crossover as a category + ## instead of genre. Moved after dedup'ing so + ## consolidated category values don't count. + if( listname == 'category' + and self.getConfig('add_category_when_multi_category') + and len(retlist) > 1 + and self.getConfig('add_category_when_multi_category') not in retlist ): + retlist.append(self.getConfig('add_category_when_multi_category')) + ## same sort as above, but has to be after due to + ## changing list. unique filter not needed: 'not + ## in retlist' check + if not (listname in ('author','authorUrl','authorId') or self.getConfig('keep_in_order_'+listname)): + retlist = sorted(list(set(retlist))) + else: retlist = []