Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-drag-and-drop-v2
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
OpenEdx
xblock-drag-and-drop-v2
Commits
6b2812d9
Commit
6b2812d9
authored
Apr 03, 2017
by
Sanford Student
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respects returning item to bank in assessment mode for TNL-6753
parent
34b145ad
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
10 deletions
+60
-10
drag_and_drop_v2/drag_and_drop_v2.py
+34
-10
drag_and_drop_v2/public/js/drag_and_drop.js
+7
-0
src/xblock-sdk
+1
-0
tests/unit/test_advanced.py
+18
-0
No files found.
drag_and_drop_v2/drag_and_drop_v2.py
View file @
6b2812d9
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# pylint: disable=C0302
#
""" Drag and Drop v2 XBlock """
...
...
@@ -694,22 +694,26 @@ class DragAndDropBlock(
raise
JsonHandlerError
(
409
,
self
.
i18n_service
.
gettext
(
"Max number of attempts reached"
))
item
=
self
.
_get_item_definition
(
item_attempt
[
'val'
])
is_correct
=
self
.
_is_attempt_correct
(
item_attempt
)
# State is always updated in assessment mode to store intermediate item positions
self
.
item_state
[
str
(
item
[
'id'
])]
=
self
.
_make_state_from_attempt
(
item_attempt
,
is_correct
)
self
.
_publish_item_dropped_event
(
item_attempt
,
is_correct
)
if
item_attempt
[
'zone'
]
is
None
:
del
self
.
item_state
[
str
(
item
[
'id'
])]
self
.
_publish_item_to_bank_event
(
item
[
'id'
],
is_correct
)
else
:
# State is always updated in assessment mode to store intermediate item positions
self
.
item_state
[
str
(
item
[
'id'
])]
=
self
.
_make_state_from_attempt
(
item_attempt
,
is_correct
)
self
.
_publish_item_dropped_event
(
item_attempt
,
is_correct
)
return
{}
def
_validate_drop_item
(
self
,
item
):
"""
Validates `drop_item` parameters
Validates `drop_item` parameters. Assessment mode allows returning
items to the bank, so validation is unnecessary.
"""
zone
=
self
.
_get_zone_by_uid
(
item
[
'zone'
])
if
not
zone
:
raise
JsonHandlerError
(
400
,
"Item zone data invalid."
)
if
self
.
mode
!=
Constants
.
ASSESSMENT_MODE
:
zone
=
self
.
_get_zone_by_uid
(
item
[
'zone'
])
if
not
zone
:
raise
JsonHandlerError
(
400
,
"Item zone data invalid."
)
@staticmethod
def
_make_state_from_attempt
(
attempt
,
correct
):
...
...
@@ -767,11 +771,31 @@ class DragAndDropBlock(
'is_correct'
:
is_correct
,
})
def
_publish_item_to_bank_event
(
self
,
item_id
,
is_correct
):
"""
Publishes event when item moved back to the bank in assessment mode.
"""
item
=
self
.
_get_item_definition
(
item_id
)
item_label
=
item
.
get
(
"displayName"
)
if
not
item_label
:
item_label
=
item
.
get
(
"imageURL"
)
self
.
runtime
.
publish
(
self
,
'edx.drag_and_drop_v2.item.dropped'
,
{
'item'
:
item_label
,
'item_id'
:
item
[
'id'
],
'location'
:
'item bank'
,
'location_id'
:
-
1
,
'is_correct'
:
is_correct
,
})
def
_is_attempt_correct
(
self
,
attempt
):
"""
Check if the item was placed correctly.
"""
correct_zones
=
self
.
get_item_zones
(
attempt
[
'val'
])
if
correct_zones
==
[]
and
attempt
[
'zone'
]
is
None
and
self
.
mode
==
Constants
.
ASSESSMENT_MODE
:
return
True
return
attempt
[
'zone'
]
in
correct_zones
def
_expand_static_url
(
self
,
url
):
...
...
drag_and_drop_v2/public/js/drag_and_drop.js
View file @
6b2812d9
...
...
@@ -1162,6 +1162,13 @@ function DragAndDropBlock(runtime, element, configuration) {
releaseGrabbedItems
();
delete
state
.
items
[
item_id
];
applyState
();
var
url
=
runtime
.
handlerUrl
(
element
,
'drop_item'
);
var
data
=
{
val
:
item_id
,
zone
:
null
};
$
.
post
(
url
,
JSON
.
stringify
(
data
),
'json'
)
}
});
}
...
...
xblock-sdk
@
0c987356
Subproject commit 0c987356cba5c5a7d47c98654e030ee4c3cb47c2
tests/unit/test_advanced.py
View file @
6b2812d9
...
...
@@ -859,6 +859,24 @@ class TestDragAndDropAssessmentData(AssessmentModeFixture, unittest.TestCase):
self
.
_do_attempt
()
self
.
assertEqual
(
self
.
block
.
raw_earned
,
expected_score
)
def
test_move_item_back_to_bank
(
self
):
self
.
assertFalse
(
self
.
block
.
completed
)
# precondition check
expected_score
=
3.0
/
5.0
self
.
_submit_solution
({
0
:
self
.
ZONE_1
,
1
:
self
.
ZONE_2
,
2
:
self
.
ZONE_2
,
3
:
self
.
ZONE_1
,
})
# would get a 0.8 score
self
.
_submit_solution
({
0
:
None
,
1
:
self
.
ZONE_2
,
2
:
self
.
ZONE_2
,
3
:
self
.
ZONE_1
,
})
# will get a 0.6 score
self
.
_do_attempt
()
self
.
assertEqual
(
self
.
block
.
raw_earned
,
expected_score
)
def
test_do_attempt_zero_score_with_all_decoys
(
self
):
published_grades
=
[]
...
...
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