Edit a aggregation

def POST_AUTH(self, courseid, aggregationid=''):  # pylint: disable=arguments-differ
        """ Edit a aggregation """
        course, __ = self.get_course_and_check_rights(courseid, allow_all_staff=True)

        if course.is_lti():
            raise web.notfound()

        msg=''
        error = False
        errored_students = []
        data = web.input(delete=[], tutors=[], groups=[], aggregationfile={})
        if len(data["delete"]):

            for classid in data["delete"]:
                # Get the aggregation
                aggregation = self.database.aggregations.find_one({"_id": ObjectId(classid), "courseid": courseid}) if ObjectId.is_valid(classid) else None

                if aggregation is None:
                    msg = _("Classroom with id {} not found.").format(classid) if course.use_classrooms() else _("Team with id {} not found.").format(classid)
                    error = True
                elif aggregation['default'] and aggregationid:
                    msg = _("You can't remove your default classroom.")
                    error = True
                else:
                    self.database.aggregations.find_one_and_update({"courseid": courseid, "default": True},
                                                                 {"$push": {
                                                                     "students": {"$each": aggregation["students"]}
                                                                 }})

                    self.database.aggregations.delete_one({"_id": ObjectId(classid)})
                    msg = _("Classroom updated.")

            if aggregationid and aggregationid in data["delete"]:
                raise web.seeother(self.app.get_homepath() + "/admin/" + courseid + "/aggregations")

        try:
            if "upload" in data:
                self.database.aggregations.delete_many({"courseid": course.get_id()})
                aggregations = custom_yaml.load(data["aggregationfile"].file)
            else:
                aggregations = json.loads(data["aggregations"])

            for index, new_aggregation in enumerate(aggregations):
                # In case of file upload, no id specified
                new_aggregation['_id'] = new_aggregation['_id'] if '_id' in new_aggregation else 'None'

                # In case of no aggregation usage, set the first entry default
                new_aggregation["default"] = not aggregationid and index == 0

                # If no groups field set, create group from class students if in groups only mode
                if "groups" not in new_aggregation:
                    new_aggregation["groups"] = [] if aggregationid else [{'size': len(new_aggregation['students']),
                                                                       'students': new_aggregation['students']}]

                # Update the aggregation
                aggregation, errors = self.update_aggregation(course, new_aggregation['_id'], new_aggregation)

                # If file upload was done, get the default aggregation id
                if course.use_classrooms() and aggregation['default']:
                    aggregationid = aggregation['_id']
                errored_students += errors

            if len(errored_students) > 0:
                msg = _("Changes couldn't be applied for following students :") + "<ul>"
                for student in errored_students:
                    msg += "<li>" + student + "</li>"
                msg += "</ul>"
                error = True
            elif not error:
                msg = _("Classroom updated.") if course.use_classrooms() else _("Teams updated.")
        except:
            msg = _('An error occurred while parsing the data.')
            error = True

        # Display the page
        return self.display_page(course, aggregationid, msg, error)