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 rules_to_subjects(rules): if not rules: return Subject.objects.filter(provider___id='osf') q = [] for rule in rules: if rule[1]: q.append(Q('parent', 'eq', Subject.load(rule[0][-1]))) if len(rule[0]) == 1: potential_parents = Subject.find(Q('parent', 'eq', Subject.load(rule[0][-1]))) for parent in potential_parents: q.append(Q('parent', '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): if self.subjects.exists(): return self.subjects.all() else: # TODO: Delet this when all PreprintProviders have a mapping from osf.models.subject import Subject q = [] for rule in self.subjects_acceptable: if rule[1]: q.append(Q('parent', 'eq', Subject.load(rule[0][-1]))) if len(rule[0]) == 1: potential_parents = Subject.find(Q('parent', 'eq', Subject.load(rule[0][-1]))) for parent in potential_parents: q.append(Q('parent', '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 top_level_subjects(self): if self.subjects.exists(): return self.subjects.filter(parent__isnull=True) else: # TODO: Delet this when all PreprintProviders have a mapping from osf.models.subject import Subject if len(self.subjects_acceptable) == 0: return Subject.find(Q('parent', 'isnull', True)) tops = set([sub[0][0] for sub in self.subjects_acceptable]) return [Subject.load(sub) for sub in tops]
def top_level_subjects(self): if len(self.subjects_acceptable) == 0: return Subject.find(Q('parents', 'isnull', True)) tops = set([sub[0][0] for sub in self.subjects_acceptable]) return [Subject.load(sub) for sub in tops]