def _load_metadata_from_json(self, json_dict): if not self.metadata: self.metadata = self.Metadata({}, {}) note_models_list = [ NoteModel.from_json(model) for model in json_dict.get("note_models", []) ] new_models = utils.merge_dicts( self.metadata.models, {model.get_uuid(): model for model in note_models_list}) deck_config_list = [ DeckConfig.from_json(deck_config) for deck_config in json_dict.get("deck_configurations", []) ] new_deck_configs = utils.merge_dicts( self.metadata.deck_configs, { deck_config.get_uuid(): deck_config for deck_config in deck_config_list }) self.metadata = Deck.Metadata(new_deck_configs, new_models)
def serialization_dict(self): return utils.merge_dicts( super(Deck, self).serialization_dict(), { "media_files": list(self.get_media_file_list(include_children=False)) }, { "note_models": list(self.metadata.models.values()), "deck_configurations": list( self.metadata.deck_configs.values()) } if not self.is_child else {})
def save_to_collection(self, collection): # Todo regenerate cards on update # look into template manipulation in "models" note_model_dict = collection.models.get_by_uuid(self.get_uuid()) or \ collection.models.new(self.anki_dict["name"]) new_model = note_model_dict["id"] is None self.anki_dict = utils.merge_dicts(note_model_dict, self.anki_dict) if new_model: collection.models.add(self.anki_dict) else: collection.models.update(self.anki_dict) collection.models.flush() if not new_model: self.update_cards(collection, note_model_dict)
def serialization_dict(self): return utils.merge_dicts( super(JsonSerializableAnkiDict, self).serialization_dict(), self.anki_dict)
def serialization_dict(self): return utils.merge_dicts(self.__dict__, {"__type__": self.__class__.__name__})
def serialization_dict(self): return utils.merge_dicts( super(JsonSerializableAnkiObject, self).serialization_dict(), self.anki_object.__dict__)