Commit c89ff2ac by Diana Huang

Basic peer grading view using mocks and some cleanup in

the peer grading service
parent 87370096
......@@ -88,18 +88,28 @@ def _err_response(msg):
return HttpResponse(json.dumps({'success': False, 'error': msg}),
mimetype="application/json")
def _check_required(request, required):
actual = set(request.POST.keys())
missing = required - actual
if len(missing) > 0:
return False, "Missing required keys: {0}".format(', '.join(missing))
else:
return True, ""
def _check_post(request):
if request.method != 'POST':
raise Http404
def get_next_submission(request, course_id):
"""
TODO: fill in this documentation
"""
_check_post(request)
required = set(['location'])
if request.method != 'POST':
raise Http404
actual = set(request.POST.keys())
missing = required - actual
if len(missing) > 0:
return _err_response('Missing required keys {0}'.format(
', '.join(missing)))
success, message = _check_required(request, required)
if not success:
return _err_response(message)
grader_id = request.user.id
p = request.POST
location = p['location']
......@@ -119,3 +129,27 @@ def _get_next_submission(course_id, grader_id, location):
return json.dumps({'success': False,
'error': 'Could not connect to grading service'})
def show_calibration_essay(request, course_id):
"""
TODO: fill in this documentation
"""
_check_post(request)
required = set(['location'])
success, message = _check_required(request, required)
if not success:
return _err_response(message)
grader_id = request.user.id
p = request.POST
location = p['location']
try:
response = peer_grading_service().show_calibration_essay(location, grader_id)
return HttpResponse(response, mimetype="application/json")
except GradingServiceError:
log.exception("Error from grading service. server url: {0}"
.format(staff_grading_service().url))
return json.dumps({'success': False,
'error': 'Could not connect to grading service'})
......@@ -106,27 +106,6 @@ def peer_grading_problem(request, course_id, problem_location):
'''
course = get_course_with_access(request.user, course_id, 'load')
# TODO: make sure that we show calibration or next submission correctly
# TODO: figure out if we want to make this page pure ajax or not
problem_info_text = ""
error_text = ""
# if we are still in calibration
# show a calibration essay
# else, show an actual problem
try:
problem_info_text = peer_gs.get_next_submission(problem_location, request.user.id)
log.debug(problem_info_text)
problem_info = json.loads(problem_info_text)
success = problem_info['success']
if 'error' in problem_info:
error_text = problem_info['error']
except GradingServiceError:
success = False
ajax_url = reverse('peer_grading', kwargs={'course_id': course_id})
if not ajax_url.endswith('/'):
ajax_url += '/'
......@@ -134,11 +113,9 @@ def peer_grading_problem(request, course_id, problem_location):
return render_to_response('peer_grading/peer_grading_problem.html', {
'view_html': '',
'course': course,
'problem_location': problem_location,
'course_id': course_id,
'success' : success,
'problem_info': problem_info_text,
'ajax_url': ajax_url,
'error_text': error_text,
# Checked above
'staff_access': False, })
......
class PeerGrading
constructor: (backend) ->
@problem_list = $('.problem-list')
@error_container = $('.error-container')
@error_container.toggle(not @error_container.is(':empty'))
@message_container = $('.message-container')
@message_container.toggle(not @message_container.is(':empty'))
backend = {}
$(document).ready(() -> new PeerGrading(backend))
mock_backend = false
$(document).ready(() -> new PeerGrading(mock_backend))
class PeerGradingProblemBackend
constructor: (ajax_url, mock_backend) ->
@mock_backend = mock_backend
@ajax_url = ajax_url
post: (cmd, data, callback) ->
if @mock_backend
callback(@mock(cmd, data))
else
# TODO: replace with postWithPrefix when that's loaded
$.post(@ajax_url + cmd, data, callback)
.error => callback({success: false, error: "Error occured while performing this operation"})
mock: (cmd, data) ->
if cmd == 'is_student_calibrated'
# change to test each version
response =
success: true
calibrated: false
else if cmd == 'show_calibration_essay'
response =
success: true
submission_id: 1
submission_key: 'abcd'
student_response: 'I am a fake response'
prompt: 'Answer this question'
rubric: 'This is a rubric.'
max_score: 4
return response
class PeerGradingProblem
constructor: (backend) ->
@prompt_wrapper = $('.prompt-wrapper')
@backend = backend
# ugly hack to prevent this code from trying to run on the
# general peer grading page
if( @prompt_wrapper.length == 0)
return
# get the location of the problem
@location = $('.peer-grading').data('location')
# get the other elements we want to fill in
@submission_container = $('.submission-container')
@prompt_container = $('.prompt-container')
@rubric_container = $('.rubric-container')
@error_container = $('.error-container')
@render_problem()
@is_calibrated_check()
is_calibrated_check: () =>
@backend.post('is_student_calibrated', {}, @calibration_check_callback)
fetch_calibration_essay: ()=>
@backend.post('show_calibration_essay', {location: @location}, @render_calibration)
render_calibration: (response) =>
if response.success
#TODO: fill this in
@submission_container.html("<h3>Calibration Essay</h3>")
@submission_container.append(response.student_response)
@prompt_container.html(response.prompt)
@rubric_container.html(response.rubric)
else
@error_container.show()
@error_container.html(response.error)
render_submission: (response) ->
#TODO: fill this in
calibration_check_callback: (response) =>
if response.success
# check whether or not we're still calibrating
if response.calibrated
@fetch_submission()
@calibration = false
else
@fetch_calibration_essay()
@calibration = true
render_problem: () ->
# do this when it makes sense
@error_container.toggle(not @error_container.is(':empty'))
backend = {}
mock_backend = true
ajax_url = $('.peer-grading').data('ajax_url')
backend = new PeerGradingProblemBackend(ajax_url, mock_backend)
$(document).ready(() -> new PeerGradingProblem(backend))
......@@ -19,7 +19,7 @@
<div class="error-container">${error_text}</div>
<h1>Peer Grading</h1>
<h2>Instructions</h2>
<p></p>
<p>Here are a list of problems that need to be peer graded for this course.</p>
% if success:
<ul class="problem-list">
%for problem in problem_list:
......
......@@ -15,8 +15,58 @@
<%static:js group='peer_grading'/>
</%block>
<section class="container">
<div class="peer-grading" data-ajax_url="${ajax_url}">
<div class="error-container">${error_text}</div>
<div class="peer-grading" data-ajax_url="${ajax_url}" location="${problem_location}">
<div class="error-container"></div>
<div class="message-container"></div>
<div class="instructions-panel">
<div class="calibration-panel">
<h3>Calibration</h3>
</div>
<div class="grading-panel">
<h3>Grading</h3>
</div>
</div>
<section class="prompt-wrapper">
<div class="prompt-information-container">
<h3>Question</h3>
<div class="prompt-container">
</div>
</div>
<div class="rubric-wrapper">
<h3>Grading Rubric</h3>
<div class="rubric-container">
</div>
</div>
</section>
<section class="grading-wrapper">
<h2>Grading</h2>
<div class="grading-container">
<div class="submission-wrapper">
<h3></h3>
<div class="submission-container">
</div>
</div>
<div class="evaluation">
<p class="score-selection-container">
</p>
<textarea name="feedback" placeholder="Feedback for student (optional)"
class="feedback-area" cols="70" ></textarea>
</div>
<div class="submission">
<input type="button" value="Submit" class="submit-button" name="show"/>
</div>
</div>
</div>
</section>
......@@ -250,12 +250,17 @@ if settings.COURSEWARE_ENABLED:
'open_ended_grading.staff_grading_service.save_grade', name='staff_grading_save_grade'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/staff_grading/get_problem_list$',
'open_ended_grading.staff_grading_service.get_problem_list', name='staff_grading_get_problem_list'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/peer_grading/get_next_submission$',
'open_ended_grading.peer_grading_service.get_next_submission', name='peer_grading_get_next_submission'),
# Peer Grading
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/peer_grading$',
'open_ended_grading.views.peer_grading', name='peer_grading'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/peer_grading/problem/(?P<problem_location>.*)$',
'open_ended_grading.views.peer_grading_problem', name='peer_grading_problem'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/peer_grading/get_next_submission$',
'open_ended_grading.peer_grading_service.get_next_submission', name='peer_grading_get_next_submission'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/peer_grading/show_calibration_essay$',
'open_ended_grading.peer_grading_service.show_calibration_essay', name='peer_grading_show_calibration_essay'),
)
......
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