def all_subjects(self): q = [] for rule in self.subjects_acceptable: if rule[1]: q.append(Q('parents', 'eq', Subject.load(rule[0][-1]))) if len(rule[0]) == 1: potential_parents = Subject.find(Q('parents', 'eq', Subject.load(rule[0][-1]))) for parent in potential_parents: q.append(Q('parents', 'eq', parent)) for sub in rule[0]: q.append(Q('_id', 'eq', sub)) return Subject.find(reduce(lambda x, y: x | y, q)) if len(q) > 1 else (Subject.find(q[0]) if len(q) else Subject.find())
def all_subjects(self): q = [] for rule in self.subjects_acceptable: if rule[1]: q.append(Q('parents', 'eq', Subject.load(rule[0][-1]))) if len(rule[0]) == 1: potential_parents = Subject.find( Q('parents', 'eq', Subject.load(rule[0][-1]))) for parent in potential_parents: q.append(Q('parents', 'eq', parent)) for sub in rule[0]: q.append(Q('_id', 'eq', sub)) return Subject.find(reduce(lambda x, y: x | y, q)) if len(q) > 1 else ( Subject.find(q[0]) if len(q) else Subject.find())
def get_subjects(self): ret = [] for subj_list in self.subjects: subj_hierarchy = [] for subj_id in subj_list: subj = Subject.load(subj_id) if subj: subj_hierarchy += ({'id': subj_id, 'text': subj.text}, ) if subj_hierarchy: ret.append(subj_hierarchy) return ret
def top_level_subjects(self): if len(self.subjects_acceptable) == 0: return Subject.find(Q('parents', 'eq', [])) tops = set([sub[0][0] for sub in self.subjects_acceptable]) return [Subject.load(sub) for sub in tops]