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
def _perform_request(self, user, name, values): class_id = values[u"class_id"] # get the appropriate class cr = ClassRepository() klass = cr.fetch(class_id) cr.close() if not klass: print "Invalid class id" return root_group = self.get_root_group() gr = GroupRepository() if not klass.group: # create the group group = Group() group.name = klass.name group.type = 0 group.academic_entity_id = class_id group = gr.persist(group) gr.add_group_as_subgroup(root_group.id, group.id) klass.group = group.id # associate with the class cr = ClassRepository() cr.persist(klass) cr.close() else: group = gr.fetch(klass.group) gr.close() # assign the user as a member of the subgroup user.groups = user.groups + [group.id] self._persist_user(user) result = {} result['id'] = group.id result['name'] = group.name result['maintainer'] = "" self.write(json.dumps(result))