def _perform_request(self, user, name, values): gr = GroupRepository() group = gr.fetch(values['group']) gr.close() if group is None or group.academic_entity_type != 'term': print "Invalid group id." return tr = TermRepository() term = tr.fetch(group.academic_entity_id) tr.close() if term is None: print "Requested term not found." return cr = ClassRepository() classes = cr.find_classes_with_name_prefix(term, values['query']) cr.close() self.write(json.dumps([{"value":klass.name, "class_id":klass.id} for klass in classes]))
def get_root_group(self): # TODO(roh7): this is a hack uiuc_name = "University of Illinois at Urbana-Champaign" ir = InstitutionRepository() institutions = ir.fetch_all() uiuc = None for inst in institutions: if inst.name == uiuc_name: uiuc = inst break ir.close() assert uiuc is not None, 'institution for UIUC group not found...' # with the UIUC group, find the term. we currently want UIUC Spring 2014. tr = TermRepository() gr = GroupRepository() term = tr.fetch_term_by_year_index(uiuc, 2014, 0) assert term is not None, 'Spring 2014 not found...' if term.group: root = gr.fetch(term.group) else: # create UIUC group root = Group() root.name = "UIUC " + term.name root.description = uiuc_name root.type = 0 # make sure bidirectional references work root.academic_entity_id = term.id root = gr.persist(root) term.group = root.id tr.persist(term) tr.close() gr.close() return root