Example #1
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))
Example #2
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