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
7984c4df
Commit
7984c4df
authored
Feb 05, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move over grading service to xmodule
parent
e8a690df
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
39 deletions
+38
-39
common/lib/xmodule/xmodule/grading_service_module.py
+19
-26
common/lib/xmodule/xmodule/peer_grading_service.py
+12
-6
lms/djangoapps/open_ended_grading/controller_query_service.py
+4
-2
lms/djangoapps/open_ended_grading/staff_grading_service.py
+2
-4
lms/djangoapps/open_ended_grading/views.py
+1
-1
No files found.
lms/djangoapps/open_ended_grading/grading_servic
e.py
→
common/lib/xmodule/xmodule/grading_service_modul
e.py
View file @
7984c4df
...
...
@@ -5,16 +5,8 @@ import requests
from
requests.exceptions
import
RequestException
,
ConnectionError
,
HTTPError
import
sys
from
django.conf
import
settings
from
django.http
import
HttpResponse
,
Http404
from
courseware.access
import
has_access
from
util.json_request
import
expect_json
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.combined_open_ended_rubric
import
CombinedOpenEndedRubric
,
RubricParsingError
from
lxml
import
etree
from
mitxmako.shortcuts
import
render_to_string
from
xmodule.x_module
import
ModuleSystem
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -31,7 +23,7 @@ class GradingService(object):
self
.
url
=
config
[
'url'
]
self
.
login_url
=
self
.
url
+
'/login/'
self
.
session
=
requests
.
session
()
self
.
system
=
ModuleSystem
(
None
,
None
,
None
,
render_to_string
,
None
)
self
.
system
=
config
[
'system'
]
def
_login
(
self
):
"""
...
...
@@ -42,20 +34,20 @@ class GradingService(object):
Returns the decoded json dict of the response.
"""
response
=
self
.
session
.
post
(
self
.
login_url
,
{
'username'
:
self
.
username
,
'password'
:
self
.
password
,})
{
'username'
:
self
.
username
,
'password'
:
self
.
password
,})
response
.
raise_for_status
()
return
response
.
json
def
post
(
self
,
url
,
data
,
allow_redirects
=
False
):
def
post
(
self
,
url
,
data
,
allow_redirects
=
False
):
"""
Make a post request to the grading controller
"""
try
:
op
=
lambda
:
self
.
session
.
post
(
url
,
data
=
data
,
allow_redirects
=
allow_redirects
)
allow_redirects
=
allow_redirects
)
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
# reraise as promised GradingServiceError, but preserve stacktrace.
...
...
@@ -69,8 +61,8 @@ class GradingService(object):
"""
log
.
debug
(
params
)
op
=
lambda
:
self
.
session
.
get
(
url
,
allow_redirects
=
allow_redirects
,
params
=
params
)
allow_redirects
=
allow_redirects
,
params
=
params
)
try
:
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
...
...
@@ -78,7 +70,7 @@ class GradingService(object):
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
def
_try_with_login
(
self
,
operation
):
"""
...
...
@@ -96,8 +88,8 @@ class GradingService(object):
r
=
self
.
_login
()
if
r
and
not
r
.
get
(
'success'
):
log
.
warning
(
"Couldn't log into staff_grading backend. Response:
%
s"
,
r
)
# try again
r
)
# try again
response
=
operation
()
response
.
raise_for_status
()
...
...
@@ -113,23 +105,23 @@ class GradingService(object):
"""
try
:
response_json
=
json
.
loads
(
response
)
except
:
response_json
=
response
try
:
if
'rubric'
in
response_json
:
rubric
=
response_json
[
'rubric'
]
rubric_renderer
=
CombinedOpenEndedRubric
(
self
.
system
,
False
)
success
,
rubric_html
=
rubric_renderer
.
render_rubric
(
rubric
)
response_json
[
'rubric'
]
=
rubric_html
return
response_json
# if we can't parse the rubric into HTML,
# if we can't parse the rubric into HTML,
except
etree
.
XMLSyntaxError
,
RubricParsingError
:
log
.
exception
(
"Cannot parse rubric string. Raw string: {0}"
.
format
(
rubric
))
.
format
(
rubric
))
return
{
'success'
:
False
,
'error'
:
'Error displaying submission'
}
'error'
:
'Error displaying submission'
}
except
ValueError
:
log
.
exception
(
"Error parsing response: {0}"
.
format
(
response
))
return
{
'success'
:
False
,
'error'
:
"Error displaying submission"
}
'error'
:
"Error displaying submission"
}
\ No newline at end of file
common/lib/xmodule/xmodule/peer_grading_service.py
View file @
7984c4df
...
...
@@ -12,22 +12,20 @@ from django.conf import settings
from
combined_open_ended_rubric
import
CombinedOpenEndedRubric
,
RubricParsingError
from
lxml
import
etree
from
grading_service_module
import
GradingService
,
GradingServiceError
log
=
logging
.
getLogger
(
__name__
)
class
GradingServiceError
(
Exception
):
pass
class
PeerGradingService
():
class
PeerGradingService
(
GradingService
):
"""
Interface with the grading controller for peer grading
"""
def
__init__
(
self
,
config
,
system
):
self
.
username
=
config
[
'username'
]
self
.
password
=
config
[
'password'
]
self
.
url
=
config
[
'url'
]
self
.
login_url
=
self
.
url
+
'/login/'
self
.
session
=
requests
.
session
()
config
[
'system'
]
=
system
super
(
StaffGradingService
,
self
)
.
__init__
(
config
)
self
.
get_next_submission_url
=
self
.
url
+
'/get_next_submission/'
self
.
save_grade_url
=
self
.
url
+
'/save_grade/'
self
.
is_student_calibrated_url
=
self
.
url
+
'/is_student_calibrated/'
...
...
@@ -107,6 +105,14 @@ class PeerGradingService():
return
response
.
json
def
try_to_decode
(
self
,
text
):
try
:
text
=
json
.
loads
(
text
)
except
:
pass
return
text
def
post
(
self
,
url
,
data
,
allow_redirects
=
False
):
"""
Make a post request to the grading controller
...
...
lms/djangoapps/open_ended_grading/controller_query_service.py
View file @
7984c4df
...
...
@@ -3,11 +3,12 @@ import logging
import
requests
from
requests.exceptions
import
RequestException
,
ConnectionError
,
HTTPError
import
sys
from
grading_service
import
GradingService
from
grading_service
import
GradingServiceError
from
xmodule.grading_service_module
import
GradingService
,
GradingServiceError
from
django.conf
import
settings
from
django.http
import
HttpResponse
,
Http404
from
xmodule.x_module
import
ModuleSystem
from
mitxmako.shortcuts
import
render_to_string
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -16,6 +17,7 @@ class ControllerQueryService(GradingService):
Interface to staff grading backend.
"""
def
__init__
(
self
,
config
):
config
[
'system'
]
=
ModuleSystem
(
None
,
None
,
None
,
render_to_string
,
None
)
super
(
ControllerQueryService
,
self
)
.
__init__
(
config
)
self
.
check_eta_url
=
self
.
url
+
'/get_submission_eta/'
self
.
is_unique_url
=
self
.
url
+
'/is_name_unique/'
...
...
lms/djangoapps/open_ended_grading/staff_grading_service.py
View file @
7984c4df
...
...
@@ -7,8 +7,7 @@ import logging
import
requests
from
requests.exceptions
import
RequestException
,
ConnectionError
,
HTTPError
import
sys
from
grading_service
import
GradingService
from
grading_service
import
GradingServiceError
from
xmodule.grading_service_module
import
GradingService
,
GradingServiceError
from
django.conf
import
settings
from
django.http
import
HttpResponse
,
Http404
...
...
@@ -22,8 +21,6 @@ from mitxmako.shortcuts import render_to_string
log
=
logging
.
getLogger
(
__name__
)
class
MockStaffGradingService
(
object
):
"""
A simple mockup of a staff grading service, testing.
...
...
@@ -64,6 +61,7 @@ class StaffGradingService(GradingService):
Interface to staff grading backend.
"""
def
__init__
(
self
,
config
):
config
[
'system'
]
=
ModuleSystem
(
None
,
None
,
None
,
render_to_string
,
None
)
super
(
StaffGradingService
,
self
)
.
__init__
(
config
)
self
.
get_next_url
=
self
.
url
+
'/get_next_submission/'
self
.
save_grade_url
=
self
.
url
+
'/save_grade/'
...
...
lms/djangoapps/open_ended_grading/views.py
View file @
7984c4df
...
...
@@ -13,7 +13,7 @@ from student.models import unique_id_for_user
from
courseware.courses
import
get_course_with_access
from
controller_query_service
import
ControllerQueryService
from
grading_servic
e
import
GradingServiceError
from
xmodule.grading_service_modul
e
import
GradingServiceError
import
json
from
.staff_grading
import
StaffGrading
from
student.models
import
unique_id_for_user
...
...
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