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 @@

$:_("Last tried exercises")

@@ -63,7 +63,8 @@

$:_("Last tried exercises")

$var Navbar: $:NavbarF() $# Start content -

$course.get_name(user_manager.session_language()) - $classroom["description"]

+

$course.get_name(user_manager.session_language()) - $:(classroom["description"] if classroom else _('My classroom'))

+ $if error: - -
-
- +$if not classroom: + -
-
- $if len(classroom["tutors"]) > 0: -
-
- $:_("Tutors") +$else: +
+ +
+
+ $if len(classroom["tutors"]) > 0: +
+
+ $:_("Tutors") +
+
    + $for user in classroom["tutors"]: +
  • + $if users[user] is not None: + $users[user][0] +
    + + + +
    + $else: + $user +
  • +
-
    - $for user in classroom["tutors"]: -
  • - $if users[user] is not None: - $users[user][0] -
    - - - -
    - $else: - $user -
  • -
-
- $if len(classroom["students"]) > 0: -
-
- $:_("Students") + $if len(classroom["students"]) > 0: +
+
+ $:_("Students") +
+
    + $for user in classroom["students"]: +
  • + $if users[user] is not None: + $users[user][0] +
    + + + +
    + $else: + $user +
  • +
+
+ +
+ $if mygroup is not None: +

$:_("My group")

+
+
+ $:_("Group #{}").format(mygroup['index']) + $if course.can_students_choose_group(): +
+ + + +
+
+
    - $for user in classroom["students"]: + $for user in mygroup["students"]:
  • $if users[user] is not None: $users[user][0] @@ -130,98 +167,67 @@

    $course.get_name(user_manager.session_language()) - $classroom["description" $user

-
-
- -
- $if mygroup is not None: -

$:_("My group")

-
-
- $:_("Group #{}").format(mygroup['index']) - $if course.can_students_choose_group(): -
- - - -
-
    - $for user in mygroup["students"]: -
  • - $if users[user] is not None: - $users[user][0] -
    - - - -
    - $else: - $user -
  • -
-
- - $elif len(classroom["groups"]) == 0: - - $elif course.can_students_choose_group(): -

$:_("My group")

- - $else: -

$:_("My group")

- - - $if not len(classroom["groups"]) == 0: -

$:_("All groups")

- $for index, group in enumerate(classroom["groups"]): - $if mygroup is None and (group["size"]-len(group["students"])) > 0 and course.can_students_choose_group(): -
- $ text_white = "text-white" - $else: -
- $ text_white = "" + $elif len(classroom["groups"]) == 0: + + $elif course.can_students_choose_group(): +

$:_("My group")

+ + $else: +

$:_("My group")

+ -
- $:_("Group #{}").format(index+1) + $if not len(classroom["groups"]) == 0: +

$:_("All groups")

+ $for index, group in enumerate(classroom["groups"]): $if mygroup is None and (group["size"]-len(group["students"])) > 0 and course.can_students_choose_group(): - (available : $(group["size"]-len(group["students"])) ) -
- - - -
-
- -
    - - $if len(group["students"]) == 0: -
  • $:_("No registered member.")
  • - $else: - - $for user in group["students"]: -
  • - $if users[user] is not None: - $users[user][0] +
    + $ text_white = "text-white" + $else: +
    + $ text_white = "" + +
    + $:_("Group #{}").format(index+1) + $if mygroup is None and (group["size"]-len(group["students"])) > 0 and course.can_students_choose_group(): + (available : $(group["size"]-len(group["students"])) ) - $else: - $user -
  • +
- -
+
    + + $if len(group["students"]) == 0: +
  • $:_("No registered member.")
  • + $else: + + $for user in group["students"]: +
  • + $if users[user] is not None: + $users[user][0] +
    + + + +
    + $else: + $user +
  • + +
+
+
-
-$:include.unregister_modal(course) \ No newline at end of file + $:include.unregister_modal(course) \ No newline at end of file diff --git a/inginious/frontend/templates/course.html b/inginious/frontend/templates/course.html index a5494852c4..031cbac373 100644 --- a/inginious/frontend/templates/course.html +++ b/inginious/frontend/templates/course.html @@ -55,8 +55,8 @@

$:_("Last tried exercises")

  $ myaggregation = user_manager.get_course_user_aggregation(course) $if course.use_classrooms(): - $:_("Classroom : {}").format(myaggregation['description']) - $elif len(myaggregation['groups']) > 0 and user_manager.session_username() in myaggregation['groups'][0]['students']: + $:_("Classroom : {}").format(myaggregation['description'] if myaggregation else _("none")) + $elif myaggregation and len(myaggregation['groups']) > 0 and user_manager.session_username() in myaggregation['groups'][0]['students']: $:_("Team : {}").format(myaggregation['description']) $else: $:_("Teams management") diff --git a/inginious/frontend/templates/course_admin/aggregation_list.html b/inginious/frontend/templates/course_admin/aggregation_list.html index f587a21fad..e50ec6ada8 100644 --- a/inginious/frontend/templates/course_admin/aggregation_list.html +++ b/inginious/frontend/templates/course_admin/aggregation_list.html @@ -123,21 +123,6 @@ $if course.use_classrooms(): -
-
- -
- -
-
-
-
- $ placeholder = _('New classroom description') $ btn = _("New classroom")
diff --git a/inginious/frontend/templates/course_admin/classroom_edit.html b/inginious/frontend/templates/course_admin/classroom_edit.html index 55a5c4d04a..60daf77540 100644 --- a/inginious/frontend/templates/course_admin/classroom_edit.html +++ b/inginious/frontend/templates/course_admin/classroom_edit.html @@ -100,7 +100,6 @@ -
@@ -115,25 +114,17 @@
- $if aggregation["default"]: -
- $if aggregation["default"]: - - $else: -
-
- -
-
- -
+
+
+ +
+
+
+
@@ -192,8 +183,7 @@ $user[0] ($username) $else: $username - $ style = 'style="display:none;"' if aggregation["default"] else '' - + @@ -233,8 +223,7 @@ $users_info[student][0] ($student) $else: $student - $ style = 'style="display:none;"' if aggregation["default"] else '' - + diff --git a/inginious/frontend/templates/task.html b/inginious/frontend/templates/task.html index d28eca308f..82dc1c40c3 100644 --- a/inginious/frontend/templates/task.html +++ b/inginious/frontend/templates/task.html @@ -150,8 +150,8 @@

$:_("Submitting as")

  $ myaggregation = user_manager.get_course_user_aggregation(course) $if course.use_classrooms(): - $:_("Classroom : {}").format(myaggregation["description"]) - $elif len(myaggregation['groups']) > 0 and user_manager.session_username() in myaggregation['groups'][0]['students']: + $:_("Classroom : {}").format(myaggregation['description'] if myaggregation else _("none")) + $elif myaggregation and len(myaggregation['groups']) > 0 and user_manager.session_username() in myaggregation['groups'][0]['students']: $:_("Team : {}").format(myaggregation['description']) $else: $:_("Teams management") @@ -393,7 +393,7 @@
$elif not task.get_accessible_time().is_open(): $elif task.is_group_task() and not groups_ok: - $(_('Please register in a group') if course.use_classrooms() else _('Please register in a team')) + $elif not tokens_ok:
-$if len(myteam["groups"]) > 0 and username in myteam["groups"][0]["students"]: -

$:_("My team : {}").format(myteam["description"])

-
-
- $:_("Students") - $if course.can_students_choose_group(): -
- - - -
-
- -
    - $for user in myteam["groups"][0]["students"]: -
  • - $if users[user] is not None: - $users[user][0] -
    - - - -
    - $else: - $user -
  • -
- - $if len(myteam["tutors"]) > 0: -