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
125945de
Commit
125945de
authored
Dec 28, 2012
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor get and post logic into new GradingService
parent
ecf04b3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
37 deletions
+42
-37
lms/djangoapps/open_ended_grading/grading_service.py
+30
-2
lms/djangoapps/open_ended_grading/staff_grading_service.py
+12
-35
No files found.
lms/djangoapps/open_ended_grading/grading_service.py
View file @
125945de
# This class gives a common interface for logging into
# the graing controller
# This class gives a common interface for logging into the grading controller
import
json
import
logging
import
requests
...
...
@@ -45,6 +44,35 @@ class GradingService(object):
return
response
.
json
def
post
(
self
,
url
,
allow_redirects
,
data
):
"""
Make a post request to the grading controller
"""
try
:
op
=
lambda
:
self
.
session
.
post
(
url
,
data
=
data
,
allow_redirects
=
allow_redirects
)
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
def
get
(
self
,
url
,
allow_redirects
,
params
):
"""
Make a get request to the grading controller
"""
op
=
lambda
:
self
.
session
.
get
(
url
,
allow_redirects
=
allow_redirects
,
params
=
params
)
try
:
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
def
_try_with_login
(
self
,
operation
):
"""
...
...
lms/djangoapps/open_ended_grading/staff_grading_service.py
View file @
125945de
...
...
@@ -83,17 +83,8 @@ class StaffGradingService(GradingService):
Raises:
GradingServiceError: something went wrong with the connection.
"""
op
=
lambda
:
self
.
session
.
get
(
self
.
get_problem_list_url
,
allow_redirects
=
False
,
params
=
{
'course_id'
:
course_id
,
'grader_id'
:
grader_id
})
try
:
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
params
=
{
'course_id'
:
course_id
,
'grader_id'
:
grader_id
}
return
self
.
get
(
self
.
get_problem_list_url
,
False
,
params
)
def
get_next
(
self
,
course_id
,
location
,
grader_id
):
...
...
@@ -114,17 +105,10 @@ class StaffGradingService(GradingService):
Raises:
GradingServiceError: something went wrong with the connection.
"""
op
=
lambda
:
self
.
session
.
get
(
self
.
get_next_url
,
return
self
.
get
(
self
.
get_next_url
,
allow_redirects
=
False
,
params
=
{
'location'
:
location
,
'grader_id'
:
grader_id
})
try
:
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
def
save_grade
(
self
,
course_id
,
grader_id
,
submission_id
,
score
,
feedback
,
skipped
):
...
...
@@ -139,22 +123,15 @@ class StaffGradingService(GradingService):
Raises:
GradingServiceError if there's a problem connecting.
"""
try
:
data
=
{
'course_id'
:
course_id
,
'submission_id'
:
submission_id
,
'score'
:
score
,
'feedback'
:
feedback
,
'grader_id'
:
grader_id
,
'skipped'
:
skipped
}
op
=
lambda
:
self
.
session
.
post
(
self
.
save_grade_url
,
data
=
data
,
allow_redirects
=
False
)
r
=
self
.
_try_with_login
(
op
)
except
(
RequestException
,
ConnectionError
,
HTTPError
)
as
err
:
# reraise as promised GradingServiceError, but preserve stacktrace.
raise
GradingServiceError
,
str
(
err
),
sys
.
exc_info
()[
2
]
return
r
.
text
data
=
{
'course_id'
:
course_id
,
'submission_id'
:
submission_id
,
'score'
:
score
,
'feedback'
:
feedback
,
'grader_id'
:
grader_id
,
'skipped'
:
skipped
}
return
self
.
post
(
self
.
save_grade_url
,
data
=
data
,
allow_redirects
=
False
)
# don't initialize until staff_grading_service() is called--means that just
# importing this file doesn't create objects that may not have the right config
...
...
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