Commit dc372692 by Victor Shnayder

WIP -- figuring out how to add cs50 progress page

parent 4594d37b
......@@ -97,6 +97,18 @@ def _textbooks(tab, user, course, active_page):
for index, textbook in enumerate(course.textbooks)]
return []
# This is a hack for fall 2012 -- pull cs50 grades from their API when a student
# clicks on the progress tab. This might be a reasonable thing to do more
# broadly later, but will need a well defined and documented API.
def _cs50_progress(tab, user, course, active_page):
"""
Generates a tab that calls the CS50 gradebook API and renders progress.
"""
link = reverse('progress50', args=[course.id])
return [CourseTab(tab['name'], link, active_page=='progress50')]
#### Validators
......@@ -132,6 +144,7 @@ VALID_TAB_TYPES = {
'textbooks': TabImpl(null_validator, _textbooks),
'progress': TabImpl(need_name, _progress),
'static_tab': TabImpl(key_checker(['name', 'url_slug']), _static_tab),
'cs50_progress': TabImpl(key_checker(['name', 'link']), _cs50_progress),
}
......
......@@ -499,3 +499,49 @@ def progress(request, course_id, student_id=None):
return render_to_response('courseware/progress.html', context)
@login_required
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
def progress50(request, course_id, student_id=None):
"""Show user progress for cs50. (HACK, fall 2012)
Call the cs50 api for this user
"""
course = get_course_with_access(request.user, course_id, 'load')
staff_access = has_access(request.user, course, 'staff')
if student_id is None or student_id == request.user.id:
# always allowed to see your own profile
student = request.user
else:
# Requesting access to a different student's profile
if not staff_access:
raise Http404
student = User.objects.get(id=int(student_id))
# NOTE: To make sure impersonation by instructor works, use
# student instead of request.user in the rest of the function.
# The pre-fetching of groups is done to make auth checks not require an
# additional DB lookup (this kills the Progress page in particular).
student = User.objects.prefetch_related("groups").get(id=student.id)
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(
course_id, student, course)
courseware_summary = grades.progress_summary(student, request, course,
student_module_cache)
grade_summary = grades.grade(student, request, course, student_module_cache)
if courseware_summary is None:
#This means the student didn't have access to the course (which the instructor requested)
raise Http404
context = {'course': course,
'courseware_summary': courseware_summary,
'grade_summary': grade_summary,
'staff_access': staff_access,
}
context.update()
return render_to_response('courseware/progress.html', context)
import requests
from urllib import quote_plus
from pprint import pprint
def get_cs50_grades(email):
"""
"""
base_url = 'http://apps.cs50.edx.org/'
slug = '5075680a-88a0-4562-8e41-7fe30a000204'
s = requests.session()
r = s.post(base_url + 'users/authenticate', data={'slug': slug})
if r.json is None or not r.json['User']:
# auth failed
print "auth failed. Response:" + r.text
else:
print "auth response: " + str(r.json)
# # What is a suite id?
suite_id = 7
r = s.get(base_url + str(suite_id))
print 'response to suite selection: ' + r.text[:200]
#user_token = quote_plus(r.json['User']['token'])
user_token = quote_plus(email)
grades = s.get(base_url + "gradebook/grades/user/{0}".format(user_token))
#grades = s.get(base_url + "gradebook/grades/") #/user/{0}".format(user_token))
print 'grades: '
pprint(grades.json)
......@@ -194,6 +194,11 @@ if settings.COURSEWARE_ENABLED:
'courseware.views.index', name="courseware_position"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/progress$',
'courseware.views.progress', name="progress"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/progress50$',
'courseware.views.progress50', name="progress50"),
# Takes optional student_id for instructor use--shows profile as that student sees it.
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/progress/(?P<student_id>[^/]*)/$',
'courseware.views.progress', name="student_progress"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment