From a301abd5adeb0a0346014007982b2bb113289b4a Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Wed, 22 Aug 2012 15:49:48 -0400 Subject: [PATCH 1/3] Enrollment hack for allowing Berkeley to add their students. --- lms/djangoapps/courseware/views.py | 42 ++++++++++++++++++++++++++++++ lms/urls.py | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 98444c176d..f67f79cf11 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -393,3 +393,45 @@ def instructor_dashboard(request, course_id): context = {'course': course, 'staff_access': True,} return render_to_response('courseware/instructor_dashboard.html', context) + +@ensure_csrf_cookie +@cache_control(no_cache=True, no_store=True, must_revalidate=True) +def enroll_students(request, course_id): + course = get_course_with_access(request.user, course_id, 'staff') + ''' Allows a staff member to enroll students in a course. + + This is a short-term hack for Berkeley courses launching fall + 2012. In the long term, we would like functionality like this, but + we would like both the instructor and the student to agree. Right + now, this allows any instructor to add students to their course, + which we do not want. + + It is poorly written and poorly tested, but it's designed to be + stripped out. + ''' + + course = get_course_with_access(request.user, course_id, 'staff') + existing_students = [ce.user.email for ce in CourseEnrollment.objects.filter(course_id = course_id)] + print request.POST + if 'new_students' in request.POST: + new_students = request.POST['new_students'].split('\n') + else: + new_students = [] + new_students = [s.strip() for s in new_students] + + added_students = [] + rejected_students = [] + + for student in new_students: + try: + nce = CourseEnrollment(user=User.objects.get(email = student), course_id = course_id) + nce.save() + added_students.append(student) + except: + rejected_students.append(student) + + return render_to_response("enroll_students.html", {'course':course_id, + 'existing_students': existing_students, + 'added_students': added_students, + 'rejected_students': rejected_students, + 'debug':new_students}) diff --git a/lms/urls.py b/lms/urls.py index 6e6ad4300e..af21b8bf45 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -154,7 +154,8 @@ if settings.COURSEWARE_ENABLED: 'courseware.views.gradebook', name='gradebook'), url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/grade_summary$', 'courseware.views.grade_summary', name='grade_summary'), - + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/enroll_students$', + 'courseware.views.enroll_students', name='enroll_students'), ) # discussion forums live within courseware, so courseware must be enabled first From 3777cd2f5efece32c7bf735d42ca43e2451088f5 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Wed, 22 Aug 2012 16:15:24 -0400 Subject: [PATCH 2/3] Added missing file --- lms/templates/enroll_students.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lms/templates/enroll_students.html diff --git a/lms/templates/enroll_students.html b/lms/templates/enroll_students.html new file mode 100644 index 0000000000..2f0b6ccc01 --- /dev/null +++ b/lms/templates/enroll_students.html @@ -0,0 +1,29 @@ +

Student Enrollment Form

+ +

Course: ${ course } + +

+ +

Add new students

+ + +
+ +

Existing students: + +

${ existing_students } + +

New students added: +${ added_students } + +

Students rejected: +${ rejected_students } + +

Debug: +

${ debug } + + +

foo +

bar +

biff From 69a3ea63bcd0497bc9786b4d805eab6294b7a33a Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Wed, 22 Aug 2012 16:32:14 -0400 Subject: [PATCH 3/3] Fixed minor issues (removed two unnecessary lines) --- lms/djangoapps/courseware/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index f67f79cf11..640dd7c08d 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -397,7 +397,6 @@ def instructor_dashboard(request, course_id): @ensure_csrf_cookie @cache_control(no_cache=True, no_store=True, must_revalidate=True) def enroll_students(request, course_id): - course = get_course_with_access(request.user, course_id, 'staff') ''' Allows a staff member to enroll students in a course. This is a short-term hack for Berkeley courses launching fall @@ -412,7 +411,7 @@ def enroll_students(request, course_id): course = get_course_with_access(request.user, course_id, 'staff') existing_students = [ce.user.email for ce in CourseEnrollment.objects.filter(course_id = course_id)] - print request.POST + if 'new_students' in request.POST: new_students = request.POST['new_students'].split('\n') else: