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
878d3eff
Commit
878d3eff
authored
Nov 06, 2017
by
John Eskew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split signals.py from tasks.py file.
parent
6e7cba28
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
59 deletions
+71
-59
lms/djangoapps/lti_provider/apps.py
+1
-1
lms/djangoapps/lti_provider/signals.py
+69
-0
lms/djangoapps/lti_provider/tasks.py
+1
-58
No files found.
lms/djangoapps/lti_provider/apps.py
View file @
878d3eff
...
...
@@ -13,4 +13,4 @@ class LtiProviderConfig(AppConfig):
def
ready
(
self
):
# Import the tasks module to ensure that signal handlers are registered.
from
.
import
task
s
# pylint: disable=unused-import
from
.
import
signal
s
# pylint: disable=unused-import
lms/djangoapps/lti_provider/signals.py
0 → 100644
View file @
878d3eff
"""
Signals handlers for the lti_provider Django app.
"""
from
__future__
import
absolute_import
import
logging
from
django.conf
import
settings
from
django.dispatch
import
receiver
import
lti_provider.outcomes
as
outcomes
from
lms.djangoapps.grades.signals.signals
import
PROBLEM_WEIGHTED_SCORE_CHANGED
from
lti_provider.views
import
parse_course_and_usage_keys
from
xmodule.modulestore.django
import
modulestore
from
.tasks
import
send_composite_outcome
,
send_leaf_outcome
log
=
logging
.
getLogger
(
__name__
)
def
increment_assignment_versions
(
course_key
,
usage_key
,
user_id
):
"""
Update the version numbers for all assignments that are affected by a score
change event. Returns a list of all affected assignments.
"""
problem_descriptor
=
modulestore
()
.
get_item
(
usage_key
)
# Get all assignments involving the current problem for which the campus LMS
# is expecting a grade. There may be many possible graded assignments, if
# a problem has been added several times to a course at different
# granularities (such as the unit or the vertical).
assignments
=
outcomes
.
get_assignments_for_problem
(
problem_descriptor
,
user_id
,
course_key
)
for
assignment
in
assignments
:
assignment
.
version_number
+=
1
assignment
.
save
()
return
assignments
@receiver
(
PROBLEM_WEIGHTED_SCORE_CHANGED
)
def
score_changed_handler
(
sender
,
**
kwargs
):
# pylint: disable=unused-argument
"""
Consume signals that indicate score changes. See the definition of
PROBLEM_WEIGHTED_SCORE_CHANGED for a description of the signal.
"""
points_possible
=
kwargs
.
get
(
'weighted_possible'
,
None
)
points_earned
=
kwargs
.
get
(
'weighted_earned'
,
None
)
user_id
=
kwargs
.
get
(
'user_id'
,
None
)
course_id
=
kwargs
.
get
(
'course_id'
,
None
)
usage_id
=
kwargs
.
get
(
'usage_id'
,
None
)
if
None
not
in
(
points_earned
,
points_possible
,
user_id
,
course_id
):
course_key
,
usage_key
=
parse_course_and_usage_keys
(
course_id
,
usage_id
)
assignments
=
increment_assignment_versions
(
course_key
,
usage_key
,
user_id
)
for
assignment
in
assignments
:
if
assignment
.
usage_key
==
usage_key
:
send_leaf_outcome
.
delay
(
assignment
.
id
,
points_earned
,
points_possible
)
else
:
send_composite_outcome
.
apply_async
(
(
user_id
,
course_id
,
assignment
.
id
,
assignment
.
version_number
),
countdown
=
settings
.
LTI_AGGREGATE_SCORE_PASSBACK_DELAY
)
else
:
log
.
error
(
"Outcome Service: Required signal parameter is None. "
"points_possible:
%
s, points_earned:
%
s, user_id:
%
s, "
"course_id:
%
s, usage_id:
%
s"
,
points_possible
,
points_earned
,
user_id
,
course_id
,
usage_id
)
lms/djangoapps/lti_provider/tasks.py
View file @
878d3eff
...
...
@@ -4,73 +4,16 @@ Asynchronous tasks for the LTI provider app.
import
logging
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.dispatch
import
receiver
from
opaque_keys.edx.keys
import
CourseKey
import
lti_provider.outcomes
as
outcomes
from
lms
import
CELERY_APP
from
lms.djangoapps.grades.course_grade_factory
import
CourseGradeFactory
from
lms.djangoapps.grades.signals.signals
import
PROBLEM_WEIGHTED_SCORE_CHANGED
from
lti_provider.models
import
GradedAssignment
from
lti_provider.views
import
parse_course_and_usage_keys
from
xmodule.modulestore.django
import
modulestore
log
=
logging
.
getLogger
(
"edx.lti_provider"
)
@receiver
(
PROBLEM_WEIGHTED_SCORE_CHANGED
)
def
score_changed_handler
(
sender
,
**
kwargs
):
# pylint: disable=unused-argument
"""
Consume signals that indicate score changes. See the definition of
PROBLEM_WEIGHTED_SCORE_CHANGED for a description of the signal.
"""
points_possible
=
kwargs
.
get
(
'weighted_possible'
,
None
)
points_earned
=
kwargs
.
get
(
'weighted_earned'
,
None
)
user_id
=
kwargs
.
get
(
'user_id'
,
None
)
course_id
=
kwargs
.
get
(
'course_id'
,
None
)
usage_id
=
kwargs
.
get
(
'usage_id'
,
None
)
if
None
not
in
(
points_earned
,
points_possible
,
user_id
,
course_id
):
course_key
,
usage_key
=
parse_course_and_usage_keys
(
course_id
,
usage_id
)
assignments
=
increment_assignment_versions
(
course_key
,
usage_key
,
user_id
)
for
assignment
in
assignments
:
if
assignment
.
usage_key
==
usage_key
:
send_leaf_outcome
.
delay
(
assignment
.
id
,
points_earned
,
points_possible
)
else
:
send_composite_outcome
.
apply_async
(
(
user_id
,
course_id
,
assignment
.
id
,
assignment
.
version_number
),
countdown
=
settings
.
LTI_AGGREGATE_SCORE_PASSBACK_DELAY
)
else
:
log
.
error
(
"Outcome Service: Required signal parameter is None. "
"points_possible:
%
s, points_earned:
%
s, user_id:
%
s, "
"course_id:
%
s, usage_id:
%
s"
,
points_possible
,
points_earned
,
user_id
,
course_id
,
usage_id
)
def
increment_assignment_versions
(
course_key
,
usage_key
,
user_id
):
"""
Update the version numbers for all assignments that are affected by a score
change event. Returns a list of all affected assignments.
"""
problem_descriptor
=
modulestore
()
.
get_item
(
usage_key
)
# Get all assignments involving the current problem for which the campus LMS
# is expecting a grade. There may be many possible graded assignments, if
# a problem has been added several times to a course at different
# granularities (such as the unit or the vertical).
assignments
=
outcomes
.
get_assignments_for_problem
(
problem_descriptor
,
user_id
,
course_key
)
for
assignment
in
assignments
:
assignment
.
version_number
+=
1
assignment
.
save
()
return
assignments
log
=
logging
.
getLogger
(
__name__
)
@CELERY_APP.task
(
name
=
'lti_provider.tasks.send_composite_outcome'
)
...
...
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