Merge branch 'master' into feature/will/move_correct_mark_for_multiple_choice
This commit is contained in:
@@ -111,7 +111,7 @@ class DragAndDrop(object):
|
||||
Returns: bool.
|
||||
'''
|
||||
for draggable in self.excess_draggables:
|
||||
if not self.excess_draggables[draggable]:
|
||||
if self.excess_draggables[draggable]:
|
||||
return False # user answer has more draggables than correct answer
|
||||
|
||||
# Number of draggables in user_groups may be differ that in
|
||||
@@ -304,8 +304,13 @@ class DragAndDrop(object):
|
||||
|
||||
user_answer = json.loads(user_answer)
|
||||
|
||||
# check if we have draggables that are not in correct answer:
|
||||
self.excess_draggables = {}
|
||||
# This dictionary will hold a key for each draggable the user placed on
|
||||
# the image. The value is True if that draggable is not mentioned in any
|
||||
# correct_answer entries. If the draggable is mentioned in at least one
|
||||
# correct_answer entry, the value is False.
|
||||
# default to consider every user answer excess until proven otherwise.
|
||||
self.excess_draggables = dict((users_draggable.keys()[0],True)
|
||||
for users_draggable in user_answer['draggables'])
|
||||
|
||||
# create identical data structures from user answer and correct answer
|
||||
for i in xrange(0, len(correct_answer)):
|
||||
@@ -322,11 +327,8 @@ class DragAndDrop(object):
|
||||
self.user_groups[groupname].append(draggable_name)
|
||||
self.user_positions[groupname]['user'].append(
|
||||
draggable_dict[draggable_name])
|
||||
self.excess_draggables[draggable_name] = True
|
||||
else:
|
||||
self.excess_draggables[draggable_name] = \
|
||||
self.excess_draggables.get(draggable_name, False)
|
||||
|
||||
# proved that this is not excess
|
||||
self.excess_draggables[draggable_name] = False
|
||||
|
||||
def grade(user_input, correct_answer):
|
||||
""" Creates DragAndDrop instance from user_input and correct_answer and
|
||||
|
||||
@@ -46,6 +46,18 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
|
||||
correct_answer = {'1': 't1', 'name_with_icon': 't2'}
|
||||
self.assertTrue(draganddrop.grade(user_input, correct_answer))
|
||||
|
||||
def test_expect_no_actions_wrong(self):
|
||||
user_input = '{"draggables": [{"1": "t1"}, \
|
||||
{"name_with_icon": "t2"}]}'
|
||||
correct_answer = []
|
||||
self.assertFalse(draganddrop.grade(user_input, correct_answer))
|
||||
|
||||
def test_expect_no_actions_right(self):
|
||||
user_input = '{"draggables": []}'
|
||||
correct_answer = []
|
||||
self.assertTrue(draganddrop.grade(user_input, correct_answer))
|
||||
|
||||
|
||||
def test_targets_false(self):
|
||||
user_input = '{"draggables": [{"1": "t1"}, \
|
||||
{"name_with_icon": "t2"}]}'
|
||||
|
||||
@@ -4,7 +4,47 @@ class @Rubric
|
||||
@initialize: (location) ->
|
||||
$('.rubric').data("location", location)
|
||||
$('input[class="score-selection"]').change @tracking_callback
|
||||
# set up the hotkeys
|
||||
$(window).unbind('keydown', @keypress_callback)
|
||||
$(window).keydown @keypress_callback
|
||||
# display the 'current' carat
|
||||
@categories = $('.rubric-category')
|
||||
@category = $(@categories.first())
|
||||
@category.prepend('> ')
|
||||
@category_index = 0
|
||||
|
||||
|
||||
@keypress_callback: (event) =>
|
||||
# don't try to do this when user is typing in a text input
|
||||
if $(event.target).is('input, textarea')
|
||||
return
|
||||
# for when we select via top row
|
||||
if event.which >= 48 and event.which <= 57
|
||||
selected = event.which - 48
|
||||
# for when we select via numpad
|
||||
else if event.which >= 96 and event.which <= 105
|
||||
selected = event.which - 96
|
||||
# we don't want to do anything since we haven't pressed a number
|
||||
else
|
||||
return
|
||||
|
||||
# if we actually have a current category (not past the end)
|
||||
if(@category_index <= @categories.length)
|
||||
# find the valid selections for this category
|
||||
inputs = $("input[name='score-selection-#{@category_index}']")
|
||||
max_score = inputs.length - 1
|
||||
|
||||
if selected > max_score or selected < 0
|
||||
return
|
||||
inputs.filter("input[value=#{selected}]").click()
|
||||
|
||||
# move to the next category
|
||||
old_category_text = @category.html().substring(5)
|
||||
@category.html(old_category_text)
|
||||
@category_index++
|
||||
@category = $(@categories[@category_index])
|
||||
@category.prepend('> ')
|
||||
|
||||
@tracking_callback: (event) ->
|
||||
target_selection = $(event.target).val()
|
||||
# chop off the beginning of the name so that we can get the number of the category
|
||||
@@ -49,6 +89,7 @@ class @CombinedOpenEnded
|
||||
constructor: (element) ->
|
||||
@element=element
|
||||
@reinitialize(element)
|
||||
$(window).keydown @keydown_handler
|
||||
|
||||
reinitialize: (element) ->
|
||||
@wrapper=$(element).find('section.xmodule_CombinedOpenEndedModule')
|
||||
@@ -306,6 +347,7 @@ class @CombinedOpenEnded
|
||||
if response.success
|
||||
@rubric_wrapper.html(response.rubric_html)
|
||||
@rubric_wrapper.show()
|
||||
Rubric.initialize(@location)
|
||||
@answer_area.html(response.student_response)
|
||||
@child_state = 'assessing'
|
||||
@find_assessment_elements()
|
||||
@@ -318,6 +360,11 @@ class @CombinedOpenEnded
|
||||
else
|
||||
@errors_area.html(@out_of_sync_message)
|
||||
|
||||
keydown_handler: (e) =>
|
||||
# only do anything when the key pressed is the 'enter' key
|
||||
if e.which == 13 && @child_state == 'assessing' && Rubric.check_complete()
|
||||
@save_assessment(e)
|
||||
|
||||
save_assessment: (event) =>
|
||||
event.preventDefault()
|
||||
if @child_state == 'assessing' && Rubric.check_complete()
|
||||
|
||||
@@ -210,6 +210,9 @@ class @PeerGradingProblem
|
||||
@calibration_interstitial_page_button = $('.calibration-interstitial-page-button')
|
||||
@flag_student_checkbox = $('.flag-checkbox')
|
||||
@answer_unknown_checkbox = $('.answer-unknown-checkbox')
|
||||
|
||||
$(window).keydown @keydown_handler
|
||||
|
||||
@collapse_question()
|
||||
|
||||
Collapsible.setCollapsibles(@content_panel)
|
||||
@@ -251,9 +254,6 @@ class @PeerGradingProblem
|
||||
fetch_submission_essay: () =>
|
||||
@backend.post('get_next_submission', {location: @location}, @render_submission)
|
||||
|
||||
gentle_alert: (msg) =>
|
||||
@grading_message.fadeIn()
|
||||
@grading_message.html("<p>" + msg + "</p>")
|
||||
|
||||
construct_data: () ->
|
||||
data =
|
||||
@@ -337,6 +337,14 @@ class @PeerGradingProblem
|
||||
@show_submit_button()
|
||||
@grade = Rubric.get_total_score()
|
||||
|
||||
keydown_handler: (event) =>
|
||||
if event.which == 13 && @submit_button.is(':visible')
|
||||
if @calibration
|
||||
@submit_calibration_essay()
|
||||
else
|
||||
@submit_grade()
|
||||
|
||||
|
||||
|
||||
|
||||
##########
|
||||
@@ -473,6 +481,10 @@ class @PeerGradingProblem
|
||||
# And now hook up an event handler again
|
||||
$("input[class='score-selection']").change @graded_callback
|
||||
|
||||
gentle_alert: (msg) =>
|
||||
@grading_message.fadeIn()
|
||||
@grading_message.html("<p>" + msg + "</p>")
|
||||
|
||||
collapse_question: () =>
|
||||
@prompt_container.slideToggle()
|
||||
@prompt_container.toggleClass('open')
|
||||
|
||||
Reference in New Issue
Block a user