kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
2.06k stars 161 forks source link

Allow setting sort_field from model #42

Closed remiberthoz closed 3 years ago

remiberthoz commented 5 years ago

It is now possible to define a sort_field value for notes by setting a sort_field_number when creating the model. When the sort_field argument is unused upon note creation, then the field corresponding to the models sort_field_number will be used. The default value is 1 (for first field).

The changes are compatible with previous versions.

remiberthoz commented 3 years ago

Sorry I don't know why it says I closed the PR... I forced-push on my master branch after rebasing on top of your master branch and resolving conflicts. I am normally two commits ahead.

kerrickstaley commented 3 years ago

@remiberthoz I pushed one quick change to your PR to avoid potentially breaking API compatibility, and it looks good to merge :smile: Will merge it momentarily once the CI tests pass.

One note is that we need to add tests that exercise this functionality. I can do that in the next few days or if you want to take it on, just comment here to let me know so we don't duplicate work.

remiberthoz commented 3 years ago

Hey, I will write the tests!

What behaviors would you like to test against? Of course, that the sorting index actually sorts when its used. Do you have edge-cases in mind?

kerrickstaley commented 3 years ago

@remiberthoz I think a simple "happy path" test case would be fine for this feature, just to make sure nobody accidentally breaks it in the future.