Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d1c55208
Commit
d1c55208
authored
Jan 31, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up response code
parent
c1583dbb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
24 deletions
+41
-24
common/lib/xmodule/xmodule/peer_grading_module.py
+21
-20
common/lib/xmodule/xmodule/peer_grading_service.py
+20
-4
No files found.
common/lib/xmodule/xmodule/peer_grading_module.py
View file @
d1c55208
...
@@ -12,7 +12,6 @@ import requests
...
@@ -12,7 +12,6 @@ import requests
import
sys
import
sys
from
django.conf
import
settings
from
django.conf
import
settings
from
django.http
import
HttpResponse
,
Http404
from
combined_open_ended_rubric
import
CombinedOpenEndedRubric
from
combined_open_ended_rubric
import
CombinedOpenEndedRubric
from
lxml
import
etree
from
lxml
import
etree
...
@@ -81,8 +80,7 @@ class PeerGradingModule(XModule):
...
@@ -81,8 +80,7 @@ class PeerGradingModule(XModule):
"""
"""
Return a HttpResponse with a json dump with success=False, and the given error message.
Return a HttpResponse with a json dump with success=False, and the given error message.
"""
"""
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'error'
:
msg
}),
return
{
'success'
:
False
,
'error'
:
msg
}
mimetype
=
"application/json"
)
def
_check_required
(
self
,
get
,
required
):
def
_check_required
(
self
,
get
,
required
):
actual
=
set
(
get
.
keys
())
actual
=
set
(
get
.
keys
())
...
@@ -107,7 +105,7 @@ class PeerGradingModule(XModule):
...
@@ -107,7 +105,7 @@ class PeerGradingModule(XModule):
Needs to be implemented by child modules. Handles AJAX events.
Needs to be implemented by child modules. Handles AJAX events.
@return:
@return:
"""
"""
log
.
debug
(
get
)
handlers
=
{
handlers
=
{
'get_next_submission'
:
self
.
get_next_submission
,
'get_next_submission'
:
self
.
get_next_submission
,
'show_calibration_essay'
:
self
.
show_calibration_essay
,
'show_calibration_essay'
:
self
.
show_calibration_essay
,
...
@@ -159,13 +157,12 @@ class PeerGradingModule(XModule):
...
@@ -159,13 +157,12 @@ class PeerGradingModule(XModule):
try
:
try
:
response
=
self
.
peer_gs
.
get_next_submission
(
location
,
grader_id
)
response
=
self
.
peer_gs
.
get_next_submission
(
location
,
grader_id
)
return
HttpResponse
(
response
,
return
response
mimetype
=
"application/json"
)
except
GradingServiceError
:
except
GradingServiceError
:
log
.
exception
(
"Error getting next submission. server url: {0} location: {1}, grader_id: {2}"
log
.
exception
(
"Error getting next submission. server url: {0} location: {1}, grader_id: {2}"
.
format
(
self
.
peer_gs
.
url
,
location
,
grader_id
))
.
format
(
self
.
peer_gs
.
url
,
location
,
grader_id
))
return
json
.
dumps
(
{
'success'
:
False
,
return
{
'success'
:
False
,
'error'
:
'Could not connect to grading service'
}
)
'error'
:
'Could not connect to grading service'
}
def
save_grade
(
self
,
get
):
def
save_grade
(
self
,
get
):
"""
"""
...
@@ -199,15 +196,17 @@ class PeerGradingModule(XModule):
...
@@ -199,15 +196,17 @@ class PeerGradingModule(XModule):
try
:
try
:
response
=
self
.
peer_gs
.
save_grade
(
location
,
grader_id
,
submission_id
,
response
=
self
.
peer_gs
.
save_grade
(
location
,
grader_id
,
submission_id
,
score
,
feedback
,
submission_key
,
rubric_scores
,
submission_flagged
)
score
,
feedback
,
submission_key
,
rubric_scores
,
submission_flagged
)
return
HttpResponse
(
response
,
mimetype
=
"application/json"
)
return
response
except
GradingServiceError
:
except
GradingServiceError
:
log
.
exception
(
"""Error saving grade. server url: {0}, location: {1}, submission_id:{2},
log
.
exception
(
"""Error saving grade. server url: {0}, location: {1}, submission_id:{2},
submission_key: {3}, score: {4}"""
submission_key: {3}, score: {4}"""
.
format
(
self
.
peer_gs
.
url
,
.
format
(
self
.
peer_gs
.
url
,
location
,
submission_id
,
submission_key
,
score
)
location
,
submission_id
,
submission_key
,
score
)
)
)
return
json
.
dumps
({
'success'
:
False
,
return
{
'error'
:
'Could not connect to grading service'
})
'success'
:
False
,
'error'
:
'Could not connect to grading service'
}
def
is_student_calibrated
(
self
,
get
):
def
is_student_calibrated
(
self
,
get
):
"""
"""
...
@@ -237,12 +236,14 @@ class PeerGradingModule(XModule):
...
@@ -237,12 +236,14 @@ class PeerGradingModule(XModule):
try
:
try
:
response
=
self
.
peer_gs
.
is_student_calibrated
(
location
,
grader_id
)
response
=
self
.
peer_gs
.
is_student_calibrated
(
location
,
grader_id
)
return
HttpResponse
(
response
,
mimetype
=
"application/json"
)
return
response
except
GradingServiceError
:
except
GradingServiceError
:
log
.
exception
(
"Error from grading service. server url: {0}, grader_id: {0}, location: {1}"
log
.
exception
(
"Error from grading service. server url: {0}, grader_id: {0}, location: {1}"
.
format
(
self
.
peer_gs
.
url
,
grader_id
,
location
))
.
format
(
self
.
peer_gs
.
url
,
grader_id
,
location
))
return
json
.
dumps
({
'success'
:
False
,
return
{
'error'
:
'Could not connect to grading service'
})
'success'
:
False
,
'error'
:
'Could not connect to grading service'
}
def
show_calibration_essay
(
self
,
get
):
def
show_calibration_essay
(
self
,
get
):
"""
"""
...
@@ -278,18 +279,18 @@ class PeerGradingModule(XModule):
...
@@ -278,18 +279,18 @@ class PeerGradingModule(XModule):
location
=
get
[
'location'
]
location
=
get
[
'location'
]
try
:
try
:
response
=
self
.
peer_gs
.
show_calibration_essay
(
location
,
grader_id
)
response
=
self
.
peer_gs
.
show_calibration_essay
(
location
,
grader_id
)
return
HttpResponse
(
response
,
mimetype
=
"application/json"
)
return
response
except
GradingServiceError
:
except
GradingServiceError
:
log
.
exception
(
"Error from grading service. server url: {0}, location: {0}"
log
.
exception
(
"Error from grading service. server url: {0}, location: {0}"
.
format
(
self
.
peer_gs
.
url
,
location
))
.
format
(
self
.
peer_gs
.
url
,
location
))
return
json
.
dumps
(
{
'success'
:
False
,
return
{
'success'
:
False
,
'error'
:
'Could not connect to grading service'
}
)
'error'
:
'Could not connect to grading service'
}
# if we can't parse the rubric into HTML,
# if we can't parse the rubric into HTML,
except
etree
.
XMLSyntaxError
:
except
etree
.
XMLSyntaxError
:
log
.
exception
(
"Cannot parse rubric string. Raw string: {0}"
log
.
exception
(
"Cannot parse rubric string. Raw string: {0}"
.
format
(
rubric
))
.
format
(
rubric
))
return
json
.
dumps
(
{
'success'
:
False
,
return
{
'success'
:
False
,
'error'
:
'Error displaying submission'
}
)
'error'
:
'Error displaying submission'
}
def
save_calibration_essay
(
self
,
get
):
def
save_calibration_essay
(
self
,
get
):
...
@@ -326,7 +327,7 @@ class PeerGradingModule(XModule):
...
@@ -326,7 +327,7 @@ class PeerGradingModule(XModule):
try
:
try
:
response
=
self
.
peer_gs
.
save_calibration_essay
(
location
,
grader_id
,
calibration_essay_id
,
response
=
self
.
peer_gs
.
save_calibration_essay
(
location
,
grader_id
,
calibration_essay_id
,
submission_key
,
score
,
feedback
,
rubric_scores
)
submission_key
,
score
,
feedback
,
rubric_scores
)
return
HttpResponse
(
response
,
mimetype
=
"application/json"
)
return
response
except
GradingServiceError
:
except
GradingServiceError
:
log
.
exception
(
"Error saving calibration grade, location: {0}, submission_id: {1}, submission_key: {2}, grader_id: {3}"
.
format
(
location
,
submission_id
,
submission_key
,
grader_id
))
log
.
exception
(
"Error saving calibration grade, location: {0}, submission_id: {1}, submission_key: {2}, grader_id: {3}"
.
format
(
location
,
submission_id
,
submission_key
,
grader_id
))
return
_err_response
(
'Could not connect to grading service'
)
return
_err_response
(
'Could not connect to grading service'
)
...
...
common/lib/xmodule/xmodule/peer_grading_service.py
View file @
d1c55208
...
@@ -36,7 +36,7 @@ class PeerGradingService():
...
@@ -36,7 +36,7 @@ class PeerGradingService():
def
get_next_submission
(
self
,
problem_location
,
grader_id
):
def
get_next_submission
(
self
,
problem_location
,
grader_id
):
response
=
self
.
get
(
self
.
get_next_submission_url
,
response
=
self
.
get
(
self
.
get_next_submission_url
,
{
'location'
:
problem_location
,
'grader_id'
:
grader_id
})
{
'location'
:
problem_location
,
'grader_id'
:
grader_id
})
return
json
.
dumps
(
self
.
_render_rubric
(
response
)
)
return
self
.
_render_rubric
(
response
)
def
save_grade
(
self
,
location
,
grader_id
,
submission_id
,
score
,
feedback
,
submission_key
,
rubric_scores
,
submission_flagged
):
def
save_grade
(
self
,
location
,
grader_id
,
submission_id
,
score
,
feedback
,
submission_key
,
rubric_scores
,
submission_flagged
):
data
=
{
'grader_id'
:
grader_id
,
data
=
{
'grader_id'
:
grader_id
,
...
@@ -58,7 +58,7 @@ class PeerGradingService():
...
@@ -58,7 +58,7 @@ class PeerGradingService():
def
show_calibration_essay
(
self
,
problem_location
,
grader_id
):
def
show_calibration_essay
(
self
,
problem_location
,
grader_id
):
params
=
{
'problem_id'
:
problem_location
,
'student_id'
:
grader_id
}
params
=
{
'problem_id'
:
problem_location
,
'student_id'
:
grader_id
}
response
=
self
.
get
(
self
.
show_calibration_essay_url
,
params
)
response
=
self
.
get
(
self
.
show_calibration_essay_url
,
params
)
return
json
.
dumps
(
self
.
_render_rubric
(
response
)
)
return
self
.
_render_rubric
(
response
)
def
save_calibration_essay
(
self
,
problem_location
,
grader_id
,
calibration_essay_id
,
submission_key
,
def
save_calibration_essay
(
self
,
problem_location
,
grader_id
,
calibration_essay_id
,
submission_key
,
score
,
feedback
,
rubric_scores
):
score
,
feedback
,
rubric_scores
):
...
@@ -111,7 +111,13 @@ class PeerGradingService():
...
@@ -111,7 +111,13 @@ class PeerGradingService():
# reraise as promised GradingServiceError, but preserve stacktrace.
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
text
=
r
.
text
try
:
text
=
json
.
loads
(
text
)
except
:
pass
return
text
def
get
(
self
,
url
,
params
,
allow_redirects
=
False
):
def
get
(
self
,
url
,
params
,
allow_redirects
=
False
):
"""
"""
...
@@ -127,7 +133,13 @@ class PeerGradingService():
...
@@ -127,7 +133,13 @@ class PeerGradingService():
# reraise as promised GradingServiceError, but preserve stacktrace.
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
text
=
r
.
text
try
:
text
=
json
.
loads
(
text
)
except
:
pass
return
text
def
_try_with_login
(
self
,
operation
):
def
_try_with_login
(
self
,
operation
):
...
@@ -163,6 +175,10 @@ class PeerGradingService():
...
@@ -163,6 +175,10 @@ class PeerGradingService():
"""
"""
try
:
try
:
response_json
=
json
.
loads
(
response
)
response_json
=
json
.
loads
(
response
)
except
:
response_json
=
response
try
:
if
'rubric'
in
response_json
:
if
'rubric'
in
response_json
:
rubric
=
response_json
[
'rubric'
]
rubric
=
response_json
[
'rubric'
]
rubric_renderer
=
CombinedOpenEndedRubric
(
self
.
system
,
False
)
rubric_renderer
=
CombinedOpenEndedRubric
(
self
.
system
,
False
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment