Skip to content

Commit

Permalink
Remove the need for a default classroom
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonygego committed Oct 21, 2019
1 parent a429449 commit 62b6625
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 312 deletions.
9 changes: 5 additions & 4 deletions inginious/frontend/pages/aggregation.py
Expand Up @@ -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)
Expand Down
21 changes: 9 additions & 12 deletions inginious/frontend/pages/course_admin/aggregation_edit.py
Expand Up @@ -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"},
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"]}
}})
Expand All @@ -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']),
Expand All @@ -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

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

Expand Down
15 changes: 3 additions & 12 deletions inginious/frontend/pages/course_admin/aggregation_list.py
Expand Up @@ -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
Expand All @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions inginious/frontend/pages/course_admin/classroom_edit.py
Expand Up @@ -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
Expand Down Expand Up @@ -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"]}
}})
Expand Down
7 changes: 3 additions & 4 deletions inginious/frontend/static/js/aggregations.js
Expand Up @@ -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('<input/>', {
type:"hidden",
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 62b6625

Please sign in to comment.