kerrickstaley / genanki

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

Add deck and note options. #12

Open holocronweaver opened 7 years ago

holocronweaver commented 7 years ago

Adds options to decks and notes. This fulfills #11 and then some.

I tried to stick to the coding style that already existed. Hopefully my blasphemies were kept at a minimum. X-D

Edit: Currently investigating test failures. I have succesfully created and imported decks into Anki 2.0.47 and 2.1 beta 12, so curious why it is failing in test...

Edit 2: Found the problem. OptionsGroup requires a unique ID, which means the OptionsGroup ID must be manually set same as for the deck ID. Could generate an ID from the name of the OptionsGroup, but if users create generic option group names this could lead to conflicts. I updated tests accordingly by adding options groups to test decks. Now all tests pass.

kerrickstaley commented 7 years ago

Thanks for the PR! I don't have time to look at it right now but will try to get to it in the next two days.

holocronweaver commented 7 years ago

I think I made all the requested changes.

I moved the card options to a new CardOptions class. This simplifies sharing the same options among multiple cards, similar to what OptionsGroup does for decks, so it's handy on several levels.

I also added @property for the aliases as you suggested, while leaving the 'real' internal names consistent with the Anki DB field names.

holocronweaver commented 7 years ago

Okydoke, removed CardOptions and now Card has all the attributes. I left a utility function in Note to make the common case of setting all card options at once more concise.

jontelang commented 2 years ago

Very old bump, but is this something that can be done nowadays even without these changes?