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

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

        error = False
        data = web.input(tutors=[], groups=[], classroomfile={})
        if "delete" in data:
            # Get the classroom
            classroom = self.database.classrooms.find_one({"_id": ObjectId(classroomid), "courseid": courseid})

            if classroom is None:
                msg = _("Classroom not found.")
                error = True
            elif classroom['default']:
                msg = _("You can't remove your default classroom.")
                error = True
            else:
                self.database.classrooms.find_one_and_update({"courseid": courseid, "default": True},
                                                             {"$push": {
                                                                 "students": {"$each": classroom["students"]}
                                                             }})

                self.database.classrooms.delete_one({"_id": ObjectId(classroomid)})
                raise web.seeother(self.app.get_homepath() + "/admin/" + courseid + "/classrooms")
        else:
            try:
                if "upload" in data:
                    new_data = custom_yaml.load(data["classroomfile"].file)
                else:
                    # Prepare classroom-like data structure from input
                    new_data = {"description": data["description"], "tutors": data["tutors"], "students": [], "groups": []}
                    for index, groupstr in enumerate(data["groups"]):
                        group = json.loads(groupstr)
                        new_data["students"].extend(group["students"])
                        if index != 0:
                            new_data["groups"].append(group)

                classroom, errored_students = self.update_classroom(course, classroomid, new_data)
                student_list, tutor_list, other_students, users_info = self.get_user_lists(course, classroom["_id"])

                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
                else:
                    msg = _("Classroom updated.")
            except:
                classroom = self.database.classrooms.find_one({"_id": ObjectId(classroomid), "courseid": courseid})
                student_list, tutor_list, other_students, users_info = self.get_user_lists(course, classroom["_id"])
                msg = _('An error occurred while parsing the data.')
                error = True

        return self.template_helper.get_renderer().course_admin.edit_classroom(course, student_list, tutor_list, other_students, users_info,
                                                                               classroom, msg, error)
def POST_AUTH ( self , courseid , classroomid ) : course , __ = self . get_course_and_check_rights ( courseid , allow_all_staff = True ) if course . is_lti ( ) : raise web . notfound ( ) error = False data = web . input ( tutors = [ ] , groups = [ ] , classroomfile = { } ) if "delete" in data : classroom = self . database . classrooms . find_one ( { "_id" : ObjectId ( classroomid ) , "courseid" : courseid } ) if classroom is None : msg = _ ( "Classroom not found." ) error = True elif classroom [ 'default' ] : msg = _ ( "You can't remove your default classroom." ) error = True else : self . database . classrooms . find_one_and_update ( { "courseid" : courseid , "default" : True } , { "$push" : { "students" : { "$each" : classroom [ "students" ] } } } ) self . database . classrooms . delete_one ( { "_id" : ObjectId ( classroomid ) } ) raise web . seeother ( self . app . get_homepath ( ) + "/admin/" + courseid + "/classrooms" ) else : try : if "upload" in data : new_data = custom_yaml . load ( data [ "classroomfile" ] . file ) else : new_data = { "description" : data [ "description" ] , "tutors" : data [ "tutors" ] , "students" : [ ] , "groups" : [ ] } for index , groupstr in enumerate ( data [ "groups" ] ) : group = json . loads ( groupstr ) new_data [ "students" ] . extend ( group [ "students" ] ) if index != 0 : new_data [ "groups" ] . append ( group ) classroom , errored_students = self . update_classroom ( course , classroomid , new_data ) student_list , tutor_list , other_students , users_info = self . get_user_lists ( course , classroom [ "_id" ] ) 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 else : msg = _ ( "Classroom updated." ) except : classroom = self . database . classrooms . find_one ( { "_id" : ObjectId ( classroomid ) , "courseid" : courseid } ) student_list , tutor_list , other_students , users_info = self . get_user_lists ( course , classroom [ "_id" ] ) msg = _ ( 'An error occurred while parsing the data.' ) error = True return self . template_helper . get_renderer ( ) . course_admin . edit_classroom ( course , student_list , tutor_list , other_students , users_info , classroom , msg , error )
Edit a classroom