Skip to content

Commit

Permalink
feat: Define defaults for the Suspend new cards of new notes option (#…
Browse files Browse the repository at this point in the history
…776)

* 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`
  • Loading branch information
RisingOrange authored Oct 19, 2023
1 parent a0f5d2c commit a73e45a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ankihub/private_config_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions ankihub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a73e45a

Please sign in to comment.