From ed6a8f68ac7c422dfd198ea1a582d186d4a3da53 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Mon, 19 Nov 2012 10:04:56 -0500 Subject: [PATCH] starting to stub out the backend staff grading service [wip] --- .../instructor/staff_grading_service.py | 57 +++++++++++++++++++ lms/urls.py | 4 ++ 2 files changed, 61 insertions(+) create mode 100644 lms/djangoapps/instructor/staff_grading_service.py diff --git a/lms/djangoapps/instructor/staff_grading_service.py b/lms/djangoapps/instructor/staff_grading_service.py new file mode 100644 index 0000000000..d4a4d82e63 --- /dev/null +++ b/lms/djangoapps/instructor/staff_grading_service.py @@ -0,0 +1,57 @@ +""" +This module provides views that proxy to the staff grading backend service. +""" + +import json +import requests +import sys + +from django.http import Http404 +from django.http import HttpResponse + + +from util.json_request import expect_json + +class GradingServiceError(Exception): + pass + +class StaffGradingService(object): + """ + Interface to staff grading backend. + """ + def __init__(self, url): + self.url = url + # TODO: add auth + self.session = requests.session() + + def get_next(course_id): + """ + Get the next thing to grade. Returns json, or raises GradingServiceError + if there's a problem. + """ + try: + r = self.session.get(url + 'get_next') + except requests.exceptions.ConnectionError as err: + # reraise as promised GradingServiceError, but preserve stacktrace. + raise GradingServiceError, str(err), sys.exc_info()[2] + + return r.text + + +#@login_required +def get_next(request, course_id): + """ + """ + d = {'success': False} + return HttpResponse(json.dumps(d)) + + +#@login_required +@expect_json +def save_grade(request, course_id): + """ + + """ + d = {'success': False} + return HttpResponse(json.dumps(d)) + diff --git a/lms/urls.py b/lms/urls.py index 7c1ccb6bde..0b2def9135 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -232,6 +232,10 @@ if settings.COURSEWARE_ENABLED: 'instructor.views.enroll_students', name='enroll_students'), url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/staff_grading$', 'instructor.views.staff_grading', name='staff_grading'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/staff_grading/get_next$', + 'instructor.staff_grading_service.get_next', name='staff_grading_get_next'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/staff_grading/save_grade$', + 'instructor.staff_grading_service.save_grade', name='staff_grading_save_grade'), ) # discussion forums live within courseware, so courseware must be enabled first