From 573116073ebfee835c582ba10bcbb5c6566ef975 Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Tue, 30 Apr 2013 11:16:14 -0400 Subject: [PATCH 01/29] Add error message when factorial given non-integral value --- common/lib/capa/capa/responsetypes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 5b1b46d858..3301731929 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1851,6 +1851,13 @@ class FormulaResponse(LoncapaResponse): 'formularesponse: undefined variable in given=%s' % given) raise StudentInputError( "Invalid input: " + uv.message + " not permitted in answer") + except ValueError as ve: + # This is thrown when fact() or factorial() is used in a formularesponse answer + # that tests on negative and/or non-integer inputs + log.debug( + 'formularesponse: factorial function used in response that tests negative and/or non-integer inputs. given={0}'.format(given)) + raise StudentInputError( + "factorial function not permitted in answer for this problem. Provided answer was: {0}".format(given)) except Exception as err: # traceback.print_exc() log.debug('formularesponse: error %s in formula' % err) From 95a224fceaf71c9e5a6b8b88636f11dc8ea5bddb Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Tue, 30 Apr 2013 11:21:20 -0400 Subject: [PATCH 02/29] Fix pep8 violations --- common/lib/capa/capa/responsetypes.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 3301731929..49f6ee1bee 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1147,9 +1147,9 @@ def sympy_check2(): messages = [] for input_dict in input_list: correct.append('correct' - if input_dict['ok'] else 'incorrect') + if input_dict['ok'] else 'incorrect') msg = (self.clean_message_html(input_dict['msg']) - if 'msg' in input_dict else None) + if 'msg' in input_dict else None) messages.append(msg) # Otherwise, we do not recognize the dictionary @@ -1174,7 +1174,7 @@ def sympy_check2(): for k in range(len(idset)): npoints = (self.maxpoints[idset[k]] - if correct[k] == 'correct' else 0) + if correct[k] == 'correct' else 0) correct_map.set(idset[k], correct[k], msg=messages[k], npoints=npoints) return correct_map @@ -1990,7 +1990,6 @@ class ImageResponse(LoncapaResponse): self.ielements = self.inputfields self.answer_ids = [ie.get('id') for ie in self.ielements] - def get_score(self, student_answers): correct_map = CorrectMap() expectedset = self.get_mapped_answers() @@ -2059,7 +2058,7 @@ class ImageResponse(LoncapaResponse): rectangles (dict) - a map of inputs to the defined rectangle for that input regions (dict) - a map of inputs to the defined region for that input ''' - answers = ( + answers = ( dict([(ie.get('id'), ie.get( 'rectangle')) for ie in self.ielements]), dict([(ie.get('id'), ie.get('regions')) for ie in self.ielements])) @@ -2081,8 +2080,6 @@ class ImageResponse(LoncapaResponse): answers[ie_id] = (ie.get('rectangle'), ie.get('regions')) return answers - - #----------------------------------------------------------------------------- From 2cb3af1e3531693a3c254cb8375979735ea3b573 Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Wed, 1 May 2013 10:53:22 -0400 Subject: [PATCH 03/29] Only throw factorial-related exception on factorial raised exception --- common/lib/capa/capa/responsetypes.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 49f6ee1bee..b06a62ffc6 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1852,12 +1852,18 @@ class FormulaResponse(LoncapaResponse): raise StudentInputError( "Invalid input: " + uv.message + " not permitted in answer") except ValueError as ve: - # This is thrown when fact() or factorial() is used in a formularesponse answer - # that tests on negative and/or non-integer inputs - log.debug( - 'formularesponse: factorial function used in response that tests negative and/or non-integer inputs. given={0}'.format(given)) - raise StudentInputError( - "factorial function not permitted in answer for this problem. Provided answer was: {0}".format(given)) + if 'factorial' in ve.message: + # This is thrown when fact() or factorial() is used in a formularesponse answer + # that tests on negative and/or non-integer inputs + # ve.message will be: `factorial() only accepts integral values` or `factorial() not defined for negative values` + log.debug( + 'formularesponse: factorial function used in response that tests negative and/or non-integer inputs. given={0}'.format(given)) + raise StudentInputError( + "factorial function not permitted in answer for this problem. Provided answer was: {0}".format(given)) + # If non-factorial related ValueError thrown, handle it the same as any other Exception + log.debug('formularesponse: error {0} in formula'.format(ve)) + raise StudentInputError("Invalid input: Could not parse '%s' as a formula" % + cgi.escape(given)) except Exception as err: # traceback.print_exc() log.debug('formularesponse: error %s in formula' % err) From 7c972ebf6e6dd22ca3dfd78d07975491544a69b3 Mon Sep 17 00:00:00 2001 From: Steve Strassmann Date: Thu, 2 May 2013 09:29:27 -0400 Subject: [PATCH 04/29] fix date interpolation --- cms/static/js/base.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 3a51d797ec..49a70a87fd 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -845,8 +845,11 @@ function saveSetSectionScheduleDate(e) { data: JSON.stringify({ 'id': id, 'metadata': {'start': start}}) }).success(function () { var $thisSection = $('.courseware-section[data-id="' + id + '"]'); - var format = gettext('Will Release: %(date)s at $(time)s UTC'); - var willReleaseAt = interpolate(format, [input_date, input_time], true); + var format = gettext('Will Release: %(date)s at %(time)s UTC'); + var willReleaseAt = interpolate(format, + {'date': input_date, + 'time': input_time}, + true); $thisSection.find('.section-published-date').html( '' + willReleaseAt + '' + ' Date: Thu, 2 May 2013 09:31:53 -0400 Subject: [PATCH 05/29] tabbing --- cms/static/js/base.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 49a70a87fd..4aae7fc2af 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -843,19 +843,19 @@ function saveSetSectionScheduleDate(e) { dataType: "json", contentType: "application/json", data: JSON.stringify({ 'id': id, 'metadata': {'start': start}}) - }).success(function () { + }).success(function () { var $thisSection = $('.courseware-section[data-id="' + id + '"]'); var format = gettext('Will Release: %(date)s at %(time)s UTC'); - var willReleaseAt = interpolate(format, - {'date': input_date, + var willReleaseAt = interpolate(format, + {'date': input_date, 'time': input_time}, - true); + true); $thisSection.find('.section-published-date').html( - '' + willReleaseAt + '' + - '' + + '' + willReleaseAt + '' + + '' + gettext('Edit') + ''); $thisSection.find('.section-published-date').animate({ 'background-color': 'rgb(182,37,104)' From c9a80ded2511a33177a3b28d0fdbfb50699f386f Mon Sep 17 00:00:00 2001 From: Steve Strassmann Date: Thu, 2 May 2013 10:59:02 -0400 Subject: [PATCH 06/29] formatted using sublime/formatjs --- cms/static/js/base.js | 264 +++++++++++++++++++++++------------------- 1 file changed, 145 insertions(+), 119 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 4aae7fc2af..ad81963b0f 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -10,7 +10,7 @@ var $newComponentTypePicker; var $newComponentTemplatePickers; var $newComponentButton; -$(document).ready(function () { +$(document).ready(function() { $body = $('body'); $modal = $('.history-modal'); $modalCover = $('