Skip to content

Commit

Permalink
rnl - Added the ability to unenroll students / staff from courses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit-L committed Aug 28, 2016
1 parent 4859a9a commit 5716099
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,19 @@ def enrollment(cid):
return render_template('staff/course/enrollment.html',
enrollments=students, staff=staff,
single_form=single_form,
unenroll_form=forms.CSRFForm(),
courses=courses,
current_course=current_course)

@admin.route("/course/<int:cid>/<string:user_id>/unenroll", methods=['POST'])
@is_staff(course_arg='cid')
def unenrollment(cid, user_id):
user = User.query.filter_by(id=user_id).one_or_none()
if user and user.is_enrolled(cid):
Enrollment.unenroll(cid, user_id)
flash("{email} has been unenrolled".format(email=user.email), "success")
return redirect(url_for(".enrollment", cid=cid))

@admin.route("/course/<int:cid>/enrollment/batch",
methods=['GET', 'POST'])
@is_staff(course_arg='cid')
Expand Down
7 changes: 7 additions & 0 deletions server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ def enroll_from_form(cid, form):
}
Enrollment.create(cid, [info], role)

@staticmethod
@transaction
def unenroll(cid, user_id):
enrollment = Enrollment.query.filter_by(course_id=cid, user_id=user_id).one_or_none()
db.session.delete(enrollment)
db.session.commit()

@staticmethod
@transaction
def enroll_from_csv(cid, form):
Expand Down
6 changes: 6 additions & 0 deletions server/templates/staff/course/students.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h3 class="box-title"><span> {{ title }} </span></h3>
<th class="sort" data-sort="role">Role</th>
<th class="sort" data-sort="timestamp">Enrolled At</th>
<th class="sort" data-sort="section">Section</th>
<th class="sort" data-sort="unenroll">Unenroll</th>
</thead>

<tbody class="list">
Expand All @@ -37,6 +38,11 @@ <h3 class="box-title"><span> {{ title }} </span></h3>
<td class="role"><span class="label label-success">{{item.role}}</span></td>
<td class="timestamp" data-timestamp="{{ item.created }}">{{ utils.local_time(item.created, current_course) }}</td>
<td class="section">{{item.section}}</td>
<td class="unenroll">
{% call forms.render_form(unenroll_form, action_url=url_for('.unenrollment', cid=current_course.id, user_id=item.user.id), action_text='Unenroll',
class_='form') %}
{% endcall %}
</td>
</tr>
{% endfor %}
<!-- Include another header because list.js forces us to include this inside of the tbody -->
Expand Down
24 changes: 24 additions & 0 deletions tests/test_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ def test_enroll_from_form(self):
self.studentB['id'] = user.id

self.enrollment_matches_info(user, self.studentB)

def test_unenroll(self):
self.setup_course()

user = User(name=self.studentA['name'], email=self.studentA['email'])
db.session.add(user)
db.session.commit()
self.studentA['id'] = user.id

Enrollment.create(self.course.id, [self.studentA])

enrollment = Enrollment.query.filter_by(
course_id=self.course.id,
user_id=user.id).one_or_none()

assert enrollment

Enrollment.unenroll(self.course.id, user.id)

enrollment = Enrollment.query.filter_by(
course_id=self.course.id,
user_id=user.id).one_or_none()

assert not enrollment

def test_enroll_from_csv(self):
self.setup_course()
Expand Down

0 comments on commit 5716099

Please sign in to comment.