Skip to content
New issue

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

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

Already on GitHub? # to your account

Update note, deck and model management for Anki 2.1.28+ #100

Merged
merged 4 commits into from
Oct 15, 2020

Conversation

aplaice
Copy link
Collaborator

@aplaice aplaice commented Oct 9, 2020

Fix #92.

  1. Adjust check for "nullness" of model id

    Previously, a new model had an id of None, now it's 0.

    See: pylib/anki/media.py:171 in Anki itself (commit f637ac957d206ead619d54d6cf86eb8958ea508c).

  2. Pass deck to collection.decks.save()

    It's now required.

  3. Update note addition for Anki 2.1.28 and later

    col.addNote() is legacy.

    note.flush() is now impossible (and unnecessary) for a new note.


I've written this in a way to preserve compatibility with Anki 2.1.26 (and presumably earlier), since this made it easier to interactively test that behaviour was preserved.

This slightly complicates the code, so might not be desirable.


I think that the fix is correct (it seems to work for me, for both importing a fresh CrowdAnki deck and updating an existing one, for Anki 2.1.28, 2.1.34 and 2.1.35), but I'm not sure, as I'm not too familiar with either CrowdAnki or Anki's Note management (pre- or post- overhaul).

(pipenv run mamba ./ resulted in no errors.)

Previously, a new model had an id of None, now it's 0.

See: pylib/anki/media.py:171 in f637ac957d206ead619d54d6cf86eb8958ea508c
col.addNote() is legacy.

note.flush() is now impossible (and unnecessary) for a new note.
elif not import_config.ignore_deck_movement:
self.move_cards_to_deck(deck.anki_dict["id"])
if saner_note_addition:
collection.add_note(self.anki_object, deck.anki_dict["id"])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean we can directly specify the deck id, and so don't need the did magic above anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

I had wrapped the did magic so it only ran for old Anki versions, for compatibility, and now have completely removed it. (Unless I missed part of it.)

Switching to an explicit equality check in note_model.py is not
necessary and arguably less "pythonic", but IMO clearer.
@Stvad
Copy link
Owner

Stvad commented Oct 15, 2020

Thank you for contributing this!

@Stvad Stvad merged commit a583fa8 into Stvad:master Oct 15, 2020
@aplaice
Copy link
Collaborator Author

aplaice commented Oct 15, 2020

Thanks for merging, as well as for having created this incredibly valuable add-on in the first place!

@Stvad
Copy link
Owner

Stvad commented Oct 16, 2020

Uploaded new version to ankiweb

@aplaice aplaice deleted the anki_2_1_28_hotfix branch November 25, 2020 00:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to import .json on Anki Version 2.1.29
2 participants