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 _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))