Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refresh the correct notes when a character is updated #207

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions addon/kanji.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ def reset_custom_keywods(self):
def reset_custom_stories(self):
self.crs_execute("DELETE FROM usr.stories")

def get_related_characters(self, character: str):
raw_data = self.crs_execute_and_fetch_one(
f"SELECT primitives, primitive_of FROM characters "
"WHERE characters.character = (?)",
(character,),
)

if raw_data is None:
return None

return custom_list(raw_data[0]) + custom_list(raw_data[1])

# Recursivly finds new characters given a specific character
def _new_characters_find(self, card_type, character, out, max_characters=-1):
# Check if max characters already reached
Expand Down Expand Up @@ -566,9 +578,14 @@ def mass_set_characters_known(self, card_type, characters):

def refresh_notes_for_character(self, character):
ct_find_filter = [f'"note:{ct.model_name}"' for ct in CardType]
note_ids = aqt.mw.col.find_notes(
" OR ".join(ct_find_filter) + f' AND "Character:{character}"'
)
ct_filter = " OR ".join(ct_find_filter)
ct_filter = f"({ct_filter})" if ct_filter != "" else ""
related_characters = (self.get_related_characters(character) or []) + [character]
related_chars_filter = [f'"Character:{character}"' for character in related_characters]
related_chars_filter = " OR ".join(related_chars_filter)

# mind the parens
note_ids = aqt.mw.col.find_notes(f"({ct_filter}) AND ({related_chars_filter})")

for note_id in note_ids:
note = aqt.mw.col.getNote(note_id)
Expand Down