Skip to content

Commit

Permalink
Merge pull request Stvad#153 from aplaice/compatibility_deprecation_f…
Browse files Browse the repository at this point in the history
…ixes

Annotate/clean up compatibility shims
  • Loading branch information
aplaice authored Nov 29, 2021
2 parents 2e1b08e + 0320a6b commit 029140a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions crowd_anki/representation/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def get_media_file_list(self, data_from_models=True, include_children=True):
media = set()
for note in self.notes:
anki_object = note.anki_object
# TODO Remove compatibility shims for Anki 2.1.46 and
# lower.
join_fields = anki_object.joined_fields if hasattr(anki_object, 'joined_fields') else anki_object.joinedFields
for media_file in self.collection.media.filesInStr(anki_object.mid, join_fields()):
media.add(media_file)
Expand Down
1 change: 1 addition & 0 deletions crowd_anki/representation/deck_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, anki_deck_config=None):
@classmethod
def from_collection(cls, collection, deck_config_id):
decks = collection.decks
# TODO Remove compatibility shims for Anki 2.1.46 and lower.
get_conf = decks.get_config if hasattr(decks, 'get_config') else decks.getConf
anki_dict = get_conf(deck_config_id)
deck_config = DeckConfig(anki_dict)
Expand Down
1 change: 1 addition & 0 deletions crowd_anki/representation/deck_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

def from_collection(collection, name, deck_metadata=None, is_child=False) -> Deck:
decks = collection.decks
# TODO Remove compatibility shims for Anki 2.1.46 and lower.
by_name = decks.by_name if hasattr(decks, 'by_name') else decks.byName
anki_dict = by_name(name)

Expand Down
3 changes: 3 additions & 0 deletions crowd_anki/representation/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def get_uuid(self):
return self.anki_object.guid if self.anki_object else self.anki_object_dict.get("guid")

def note_type(self):
# TODO Remove compatibility shims for Anki 2.1.46 and lower.
# (Remove this method altogether — see old version in git
# history.)
return self.anki_object.note_type() if hasattr(self.anki_object, 'note_type') else self.anki_object.model()

def handle_model_update(self, collection, model_map_cache):
Expand Down
9 changes: 0 additions & 9 deletions crowd_anki/representation/note_model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
from collections import namedtuple

from anki import Collection
from anki import version as anki_version
from .json_serializable import JsonSerializableAnkiDict
from ..anki.overrides.change_model_dialog import ChangeModelDialog
from ..utils import utils
from ..utils.uuid import UuidFetcher

anki_version = anki_version.split(".")
anki_major = int(anki_version[0])
anki_minor = int(anki_version[1])
anki_point = int(anki_version[2])


class NoteModel(JsonSerializableAnkiDict):
ModelMap = namedtuple("ModelMap", ["field_map", "template_map"])
Expand Down Expand Up @@ -55,9 +49,6 @@ def save_to_collection(self, collection: Collection):
else:
collection.models.update(self.anki_dict)

if anki_major < 3 and anki_minor < 2 and anki_point < 48:
collection.models.flush()

if not new_model:
self.update_cards(collection, note_model_dict)

Expand Down

0 comments on commit 029140a

Please sign in to comment.