def _create(cls, target_class, text=None, parents=[], *args, **kwargs): try: subject = Subject.find_one(Q('text', 'eq', text)) except NoResultsFound: subject = target_class(*args, **kwargs) subject.text = text subject.save() subject.parents.add(*parents) subject.save() return subject
def _create(cls, target_class, text=None, parents=[], *args, **kwargs): try: subject = Subject.find_one(Q('text', 'eq', text)) except NoResultsFound: subject = target_class(*args, **kwargs) subject.text = text subject.save() subject.parents.add(*parents) subject.save() return subject
def get_subject_id(name): if name not in SUBJECTS_CACHE: subject = None try: subject = Subject.find_one(Q('text', 'eq', name)) except NoResultsFound: raise Exception('Subject: "{}" not found'.format(name)) else: SUBJECTS_CACHE[name] = subject._id return SUBJECTS_CACHE[name]
def get_subject_id(name): if name not in SUBJECTS_CACHE: subject = None try: subject = Subject.find_one(Q('text', 'eq', name)) except NoResultsFound: raise Exception('Subject: "{}" not found'.format(name)) else: SUBJECTS_CACHE[name] = subject._id return SUBJECTS_CACHE[name]