From a73e45a04eded2ee6179bd373ec00ff00bd62ab9 Mon Sep 17 00:00:00 2001 From: Jakub Fidler <31575114+RisingOrange@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:58:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Define=20defaults=20for=C2=A0the=20Susp?= =?UTF-8?q?end=20new=20cards=20of=20new=20notes=20option=20(#776)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add card-suspension options to deck config * Set `suspend_new_cards_of_new_notes=True` when installing AnKing deck * Add migration to set `suspend_new_cards_of_new_notes=True` for installed AnKing deck * Use enum for `suspend_new_cards_of_existing_notes` --- ankihub/private_config_migrations.py | 20 ++++++++++++++++++++ ankihub/settings.py | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/ankihub/private_config_migrations.py b/ankihub/private_config_migrations.py index 9b898d32c..57dff77a3 100644 --- a/ankihub/private_config_migrations.py +++ b/ankihub/private_config_migrations.py @@ -21,6 +21,9 @@ def migrate_private_config(private_config_dict: Dict) -> None: """ maybe_rename_ankihub_deck_uuid_to_ah_did(private_config_dict) maybe_reset_media_update_timestamps(private_config_dict) + maybe_set_suspend_new_cards_of_new_notes_to_true_for_anking_deck( + private_config_dict + ) def maybe_reset_media_update_timestamps(private_config_dict: Dict) -> None: @@ -49,6 +52,23 @@ def maybe_rename_ankihub_deck_uuid_to_ah_did(private_config_dict: Dict) -> None: ) +def maybe_set_suspend_new_cards_of_new_notes_to_true_for_anking_deck( + private_config_dict: Dict, +) -> None: + """Set suspend_new_cards_of_new_notes to True in the DeckConfig of the AnKing deck if the field + doesn't exist yet.""" + from .settings import ANKING_DECK_ID + + field_name = "suspend_new_cards_of_new_notes" + decks = private_config_dict["decks"] + for ah_did, deck in decks.items(): + if ah_did == ANKING_DECK_ID and deck.get(field_name) is None: + deck[field_name] = True + LOGGER.info( + f"Set {field_name} to True for the previously installed AnKing deck." + ) + + def _is_api_version_on_last_sync_below_threshold( private_config_dict: Dict, version_threshold: float ) -> bool: diff --git a/ankihub/settings.py b/ankihub/settings.py index 904de0408..e09f8fabc 100644 --- a/ankihub/settings.py +++ b/ankihub/settings.py @@ -61,6 +61,12 @@ def _deserialize_datetime(x: str) -> Optional[datetime]: return datetime.strptime(x, ANKIHUB_DATETIME_FORMAT_STR) if x else None +class SuspendNewCardsOfExistingNotes(Enum): + ALWAYS = "Always" + NEVER = "Never" + IF_SIBLINGS_SUSPENDED = "If siblings are suspended" + + @dataclass class DeckConfig(DataClassJSONMixin): anki_id: DeckId @@ -83,6 +89,10 @@ class DeckConfig(DataClassJSONMixin): subdecks_enabled: bool = ( False # whether deck is organized into subdecks by the add-on ) + suspend_new_cards_of_new_notes: bool = False + suspend_new_cards_of_existing_notes: SuspendNewCardsOfExistingNotes = ( + SuspendNewCardsOfExistingNotes.IF_SIBLINGS_SUSPENDED + ) @dataclass @@ -231,6 +241,7 @@ def add_deck( anki_id=DeckId(anki_did), user_relation=user_relation, subdecks_enabled=subdecks_enabled, + suspend_new_cards_of_new_notes=ankihub_did == ANKING_DECK_ID, ) # remove duplicates self.save_latest_deck_update(ankihub_did, latest_udpate)