<commit_before>from crowd_anki.utils import utils

from json_serializable import JsonSerializableAnkiDict


class NoteModel(JsonSerializableAnkiDict):
    export_filter_set = JsonSerializableAnkiDict.export_filter_set | {"did"}

    def __init__(self, anki_model=None):
        super(NoteModel, self).__init__(anki_model)

    @classmethod
    def from_collection(cls, collection, model_id):
        anki_dict = collection.models.get(model_id)
        note_model = NoteModel(anki_dict)
        note_model._update_fields()

        return note_model

    def save_to_collection(self, collection):
        default_note_config = collection.models.new(self.anki_dict["name"])
        self.anki_dict = utils.merge_dicts(default_note_config, self.anki_dict)
        collection.models.add(self.anki_dict)
        collection.models.flush()<commit_msg>simple uuid matching update of model. No cards regeneration<commit_after>from crowd_anki.utils import utils

from json_serializable import JsonSerializableAnkiDict


class NoteModel(JsonSerializableAnkiDict):
    export_filter_set = JsonSerializableAnkiDict.export_filter_set | {"did"}

    def __init__(self, anki_model=None):
        super(NoteModel, self).__init__(anki_model)

    @classmethod
    def from_collection(cls, collection, model_id):
        anki_dict = collection.models.get(model_id)
        note_model = NoteModel(anki_dict)
        note_model._update_fields()

        return note_model

    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"])

        self.anki_dict = utils.merge_dicts(note_model_dict, self.anki_dict)
        collection.models.update(self.anki_dict)
        collection.models.flush()
{'fraction_non_alphanumeric': 0.08250131371518654, 'fraction_numerical': 0.0, 'mean_word_length': 3.808080808080808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4138328', 'n_tokens_mistral': 576, 'n_tokens_neox': 566, 'n_words': 100}