diff --git a/inginious/frontend/pages/aggregation.py b/inginious/frontend/pages/aggregation.py index b11a7985e0..7a8dbe4e47 100644 --- a/inginious/frontend/pages/aggregation.py +++ b/inginious/frontend/pages/aggregation.py @@ -103,10 +103,11 @@ def GET_AUTH(self, courseid): # pylint: disable=arguments-differ if course.use_classrooms(): mygroup = None - for index, group in enumerate(aggregation["groups"]): - if self.user_manager.session_username() in group["students"]: - mygroup = group - mygroup["index"] = index + 1 + if aggregation: + for index, group in enumerate(aggregation["groups"]): + if self.user_manager.session_username() in group["students"]: + mygroup = group + mygroup["index"] = index + 1 return self.template_helper.get_renderer().classroom(course, last_submissions, aggregation, users, mygroup, msg, error, change) diff --git a/inginious/frontend/pages/course_admin/aggregation_edit.py b/inginious/frontend/pages/course_admin/aggregation_edit.py index 025cc31f44..77b7adb1b9 100644 --- a/inginious/frontend/pages/course_admin/aggregation_edit.py +++ b/inginious/frontend/pages/course_admin/aggregation_edit.py @@ -23,6 +23,8 @@ def get_user_lists(self, course, aggregationid=''): tutor_list = course.get_staff() # Determine student list and if they are grouped + course_obj = self.database.courses.find_one({"_id": course.get_id()}) + students = course_obj["students"] if course_obj else [] student_list = list(self.database.aggregations.aggregate([ {"$match": {"courseid": course.get_id()}}, {"$unwind": "$students"}, @@ -50,6 +52,7 @@ def get_user_lists(self, course, aggregationid=''): ])) student_list = dict([(student["students"], student) for student in student_list]) + student_list = {student: student_list[student] if student in student_list else {"students": student, "classroom": None, "grouped": False} for student in students} users_info = self.user_manager.get_users_info(list(student_list.keys()) + tutor_list) if aggregationid: @@ -102,10 +105,11 @@ def update_aggregation(self, course, aggregationid, new_data): if user_info is None or student in aggregation["tutors"]: errored_students.append(student) else: + self.user_manager.course_register_user(course, student, force=True) students.append(student) removed_students = [student for student in aggregation["students"] if student not in new_data["students"]] - self.database.aggregations.find_one_and_update({"courseid": course.get_id(), "default": True}, + self.database.aggregations.find_one_and_update({"courseid": course.get_id()}, {"$push": {"students": {"$each": removed_students}}}) new_data["students"] = students @@ -118,16 +122,11 @@ def update_aggregation(self, course, aggregationid, new_data): new_data["groups"] = groups - # Check for default aggregation - if new_data['default']: - self.database.aggregations.find_one_and_update({"courseid": course.get_id(), "default": True}, - {"$set": {"default": False}}) - aggregation = self.database.aggregations.find_one_and_update( {"_id": ObjectId(aggregationid)}, {"$set": {"description": new_data["description"], "students": students, "tutors": new_data["tutors"], - "groups": groups, "default": new_data['default']}}, return_document=ReturnDocument.AFTER) + "groups": groups}}, return_document=ReturnDocument.AFTER) return aggregation, errored_students @@ -187,7 +186,7 @@ def POST_AUTH(self, courseid, aggregationid=''): # pylint: disable=arguments-di msg = _("You can't remove your default classroom.") error = True else: - self.database.aggregations.find_one_and_update({"courseid": courseid, "default": True}, + self.database.aggregations.find_one_and_update({"courseid": courseid}, {"$push": { "students": {"$each": aggregation["students"]} }}) @@ -209,9 +208,6 @@ def POST_AUTH(self, courseid, aggregationid=''): # pylint: disable=arguments-di # 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']), @@ -221,7 +217,7 @@ def POST_AUTH(self, courseid, aggregationid=''): # pylint: disable=arguments-di 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']: + if course.use_classrooms(): aggregationid = aggregation['_id'] errored_students += errors @@ -234,6 +230,7 @@ def POST_AUTH(self, courseid, aggregationid=''): # pylint: disable=arguments-di elif not error: msg = _("Classroom updated.") if course.use_classrooms() else _("Teams updated.") except: + raise msg = _('An error occurred while parsing the data.') error = True diff --git a/inginious/frontend/pages/course_admin/aggregation_list.py b/inginious/frontend/pages/course_admin/aggregation_list.py index 149b803c0d..f26c0403e9 100644 --- a/inginious/frontend/pages/course_admin/aggregation_list.py +++ b/inginious/frontend/pages/course_admin/aggregation_list.py @@ -26,15 +26,13 @@ def GET_AUTH(self, courseid): # pylint: disable=arguments-differ web.header('Content-Type', 'text/x-yaml', unique=True) web.header('Content-Disposition', 'attachment; filename="aggregations.yaml"', unique=True) if course.use_classrooms(): - aggregations = [{"default": aggregation["default"], - "description": aggregation["description"], + aggregations = [{"description": aggregation["description"], "groups": aggregation["groups"], "students": aggregation["students"], "tutors": aggregation["tutors"]} for aggregation in self.user_manager.get_course_aggregations(course)] else: - aggregations = [{"default": aggregation["default"], - "description": aggregation["description"], + aggregations = [{"description": aggregation["description"], "groups": aggregation["groups"], "students": aggregation["students"], "tutors": aggregation["tutors"]} for aggregation in @@ -56,17 +54,10 @@ def POST_AUTH(self, courseid): # pylint: disable=arguments-differ if self.user_manager.has_admin_rights_on_course(course): data = web.input() if 'classroom' in data: - default = True if self.database.aggregations.find_one({"courseid": courseid, "default": True}) is None else False - self.database.aggregations.insert({"default": default, "courseid": courseid, "students": [], + self.database.aggregations.insert({"courseid": courseid, "students": [], "tutors": [], "groups": [], "description": data['classroom']}) msg = _("New classroom created.") - elif 'default' in data: - self.database.aggregations.find_one_and_update({"courseid": courseid, "default": True}, - {"$set": {"default": False}}) - self.database.aggregations.find_one_and_update({"_id": ObjectId(data['default'])}, - {"$set": {"default": True}}) - msg = _("Default classroom changed.") else: # default, but with no classroom detected msg = _("Invalid classroom selected.") else: diff --git a/inginious/frontend/pages/course_admin/classroom_edit.py b/inginious/frontend/pages/course_admin/classroom_edit.py index ae952c1b36..dc61cc602e 100644 --- a/inginious/frontend/pages/course_admin/classroom_edit.py +++ b/inginious/frontend/pages/course_admin/classroom_edit.py @@ -94,7 +94,7 @@ def update_classroom(self, course, classroomid, new_data): students.append(student) removed_students = [student for student in student_list if student not in new_data["students"]] - self.database.classrooms.find_one_and_update({"courseid": course.get_id(), "default": True}, + self.database.classrooms.find_one_and_update({"courseid": course.get_id()}, {"$push": {"students": {"$each": removed_students}}}) new_data["students"] = students @@ -146,11 +146,8 @@ def POST_AUTH(self, courseid, classroomid): # pylint: disable=arguments-differ 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}, + self.database.classrooms.find_one_and_update({"courseid": courseid}, {"$push": { "students": {"$each": classroom["students"]} }}) diff --git a/inginious/frontend/static/js/aggregations.js b/inginious/frontend/static/js/aggregations.js index d8ce27c308..39e72b8568 100644 --- a/inginious/frontend/static/js/aggregations.js +++ b/inginious/frontend/static/js/aggregations.js @@ -30,9 +30,8 @@ function aggregations_prepare_submit() var id = $("#_id").val(); var description = $("#description").val(); - var cdefault = JSON.parse($("#default").val().toLowerCase()); var aggregations = [{_id: id, description: description, students: students, - groups: groups, tutors: tutors, default: cdefault}]; + groups: groups, tutors: tutors}]; var inputField = jQuery('', { type:"hidden", @@ -71,14 +70,14 @@ function aggregations_prepare_submit() if (i > 0) { var groups = [{size: group_size, students: group_students}]; var aggregation = {_id: id, description: description, students: students, - groups: groups, tutors: tutors, default: (i == 1)}; + groups: groups, tutors: tutors}; aggregations.push(aggregation); } }); if($(".group").length <= 1){ var aggregation = {_id: 'None', description: '', students: ungrouped, - groups: [], tutors: [], default: true}; + groups: [], tutors: []}; aggregations.push(aggregation); } diff --git a/inginious/frontend/templates/classroom.html b/inginious/frontend/templates/classroom.html index 30d6290286..e33133484c 100644 --- a/inginious/frontend/templates/classroom.html +++ b/inginious/frontend/templates/classroom.html @@ -55,7 +55,7 @@