예제 #1
0
    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
예제 #2
0
    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))
예제 #3
0
    def _perform_request(self, user, name, values):
        group_id = values[u"group_id"]
        new_group_name = values[u"group_name"]
        new_group_desc = values[u"group_description"]

        curr_user = self.get_current_user()

        gr = GroupRepository()
        new_group = Group()
        new_group.name = new_group_name
        new_group.description = new_group_desc
        new_group.type = 0 # private group
        new_group.maintainerId = curr_user.id
        new_group = gr.persist(new_group)

        # assign the subgroup as a child of the parent group
        gr.add_group_as_subgroup(group_id, new_group.id)
        gr.close()

        # assign the user as a member of the subgroup
        user_repo = UserRepository()
        user_repo.add_user_to_group(curr_user, new_group)
        user_repo.close()

        self._persist_user(curr_user)

        result = {}

        result['id'] = new_group.id
        result['name'] = new_group.name
        user_repo2 = UserRepository()
        user = user_repo2.fetch(new_group.maintainerId)
        user_repo2.close()
        result['maintainer'] = user.name
        
        self.write(json.dumps(result))
        self.flush
        self.finish