From 573116073ebfee835c582ba10bcbb5c6566ef975 Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Tue, 30 Apr 2013 11:16:14 -0400 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 b344976fe79cc124e1fd7aeb323bd59ec3b89cd5 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 3 May 2013 15:08:28 -0400 Subject: [PATCH 4/4] Making linters happier --- cms/urls.py | 10 ++++---- common/djangoapps/heartbeat/urls.py | 2 +- .../django_comment_client/base/urls.py | 4 +--- .../django_comment_client/forum/urls.py | 3 +-- lms/djangoapps/django_comment_client/urls.py | 2 +- lms/djangoapps/simplewiki/urls.py | 24 +++++++++---------- lms/urls.py | 12 ++++------ 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/cms/urls.py b/cms/urls.py index 30d9ccbf56..3b91eceb44 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -6,7 +6,7 @@ from . import one_time_startup # from django.contrib import admin # admin.autodiscover() -urlpatterns = ('', +urlpatterns = ('', # nopep8 url(r'^$', 'contentstore.views.howitworks', name='homepage'), url(r'^listing', 'contentstore.views.index', name='index'), url(r'^edit/(?P.*?)$', 'contentstore.views.edit_unit', name='edit_unit'), @@ -118,17 +118,17 @@ urlpatterns += ( # static/proof-of-concept views url(r'^ux-alerts$', 'contentstore.views.ux_alerts', name='ux-alerts') - ) +) js_info_dict = { 'domain': 'djangojs', 'packages': ('cms',), - } +} urlpatterns += ( # Serve catalog of localized strings to be rendered by Javascript url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), - ) +) if settings.ENABLE_JASMINE: @@ -140,5 +140,3 @@ urlpatterns = patterns(*urlpatterns) # Custom error pages handler404 = 'contentstore.views.render_404' handler500 = 'contentstore.views.render_500' - - diff --git a/common/djangoapps/heartbeat/urls.py b/common/djangoapps/heartbeat/urls.py index 6049374dac..3f45a95dd2 100644 --- a/common/djangoapps/heartbeat/urls.py +++ b/common/djangoapps/heartbeat/urls.py @@ -1,5 +1,5 @@ from django.conf.urls import * -urlpatterns = patterns('', +urlpatterns = patterns('', # nopep8 url(r'^$', 'heartbeat.views.heartbeat', name='heartbeat'), ) diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py index 92826a18ae..5a43030565 100644 --- a/lms/djangoapps/django_comment_client/base/urls.py +++ b/lms/djangoapps/django_comment_client/base/urls.py @@ -1,8 +1,6 @@ from django.conf.urls.defaults import url, patterns -import django_comment_client.base.views - -urlpatterns = patterns('django_comment_client.base.views', +urlpatterns = patterns('django_comment_client.base.views', # nopep8 url(r'upload$', 'upload', name='upload'), url(r'users/(?P\w+)/update_moderator_status$', 'update_moderator_status', name='update_moderator_status'), url(r'threads/tags/autocomplete$', 'tags_autocomplete', name='tags_autocomplete'), diff --git a/lms/djangoapps/django_comment_client/forum/urls.py b/lms/djangoapps/django_comment_client/forum/urls.py index 1e676dee87..863267fde9 100644 --- a/lms/djangoapps/django_comment_client/forum/urls.py +++ b/lms/djangoapps/django_comment_client/forum/urls.py @@ -1,7 +1,6 @@ from django.conf.urls.defaults import url, patterns -import django_comment_client.forum.views -urlpatterns = patterns('django_comment_client.forum.views', +urlpatterns = patterns('django_comment_client.forum.views', # nopep8 url(r'users/(?P\w+)/followed$', 'followed_threads', name='followed_threads'), url(r'users/(?P\w+)$', 'user_profile', name='user_profile'), url(r'^(?P[\w\-.]+)/threads/(?P\w+)$', 'single_thread', name='single_thread'), diff --git a/lms/djangoapps/django_comment_client/urls.py b/lms/djangoapps/django_comment_client/urls.py index a9fc86c363..98700da4ab 100644 --- a/lms/djangoapps/django_comment_client/urls.py +++ b/lms/djangoapps/django_comment_client/urls.py @@ -1,6 +1,6 @@ from django.conf.urls.defaults import url, patterns, include -urlpatterns = patterns('', +urlpatterns = patterns('', # nopep8 url(r'forum/?', include('django_comment_client.forum.urls')), url(r'', include('django_comment_client.base.urls')), ) diff --git a/lms/djangoapps/simplewiki/urls.py b/lms/djangoapps/simplewiki/urls.py index cf243e0bd3..629b753654 100644 --- a/lms/djangoapps/simplewiki/urls.py +++ b/lms/djangoapps/simplewiki/urls.py @@ -4,16 +4,16 @@ namespace_regex = r"[a-zA-Z\d._-]+" article_slug = r'/(?P' + namespace_regex + r'/[a-zA-Z\d_-]*)' namespace = r'/(?P' + namespace_regex + r')' -urlpatterns = patterns('', - url(r'^$', 'simplewiki.views.root_redirect', name='wiki_root'), - url(r'^view' + article_slug, 'simplewiki.views.view', name='wiki_view'), - url(r'^view_revision/(?P[0-9]+)' + article_slug, 'simplewiki.views.view_revision', name='wiki_view_revision'), - url(r'^edit' + article_slug, 'simplewiki.views.edit', name='wiki_edit'), - url(r'^create' + article_slug, 'simplewiki.views.create', name='wiki_create'), - url(r'^history' + article_slug + r'(?:/(?P[0-9]+))?$', 'simplewiki.views.history', name='wiki_history'), - url(r'^search_related' + article_slug, 'simplewiki.views.search_add_related', name='search_related'), - url(r'^random/?$', 'simplewiki.views.random_article', name='wiki_random'), - url(r'^revision_feed' + namespace + r'/(?P[0-9]+)?$', 'simplewiki.views.revision_feed', name='wiki_revision_feed'), - url(r'^search' + namespace + r'?$', 'simplewiki.views.search_articles', name='wiki_search_articles'), - url(r'^list' + namespace + r'?$', 'simplewiki.views.search_articles', name='wiki_list_articles'), # Just an alias for the search, but you usually don't submit a search term +urlpatterns = patterns('', # nopep8 + url(r'^$', 'simplewiki.views.root_redirect', name='wiki_root'), + url(r'^view' + article_slug, 'simplewiki.views.view', name='wiki_view'), + url(r'^view_revision/(?P[0-9]+)' + article_slug, 'simplewiki.views.view_revision', name='wiki_view_revision'), + url(r'^edit' + article_slug, 'simplewiki.views.edit', name='wiki_edit'), + url(r'^create' + article_slug, 'simplewiki.views.create', name='wiki_create'), + url(r'^history' + article_slug + r'(?:/(?P[0-9]+))?$', 'simplewiki.views.history', name='wiki_history'), + url(r'^search_related' + article_slug, 'simplewiki.views.search_add_related', name='search_related'), + url(r'^random/?$', 'simplewiki.views.random_article', name='wiki_random'), + url(r'^revision_feed' + namespace + r'/(?P[0-9]+)?$', 'simplewiki.views.revision_feed', name='wiki_revision_feed'), + url(r'^search' + namespace + r'?$', 'simplewiki.views.search_articles', name='wiki_search_articles'), + url(r'^list' + namespace + r'?$', 'simplewiki.views.search_articles', name='wiki_list_articles'), # Just an alias for the search, but you usually don't submit a search term ) diff --git a/lms/urls.py b/lms/urls.py index 082004c1be..126d68c73e 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -2,7 +2,6 @@ from django.conf import settings from django.conf.urls import patterns, include, url from django.contrib import admin from django.conf.urls.static import static -from django.views.generic import RedirectView from . import one_time_startup @@ -10,10 +9,9 @@ import django.contrib.auth.views # Uncomment the next two lines to enable the admin: if settings.DEBUG: - from django.contrib import admin admin.autodiscover() -urlpatterns = ('', +urlpatterns = ('', # nopep8 # certificate view url(r'^update_certificate$', 'certificates.views.update_certificate'), @@ -299,12 +297,12 @@ if settings.COURSEWARE_ENABLED: 'courseware.views.news', name="news"), url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/discussion/', include('django_comment_client.urls')) - ) + ) urlpatterns += ( # This MUST be the last view in the courseware--it's a catch-all for custom tabs. url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/(?P[^/]+)/$', 'courseware.views.static_tab', name="static_tab"), - ) + ) if settings.MITX_FEATURES.get('ENABLE_STUDENT_HISTORY_VIEW'): urlpatterns += ( @@ -346,13 +344,13 @@ if settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION'): url(r'^migrate/reload/(?P[^/]+)/(?P[^/]+)$', 'lms_migration.migrate.manage_modulestores'), url(r'^gitreload$', 'lms_migration.migrate.gitreload'), url(r'^gitreload/(?P[^/]+)$', 'lms_migration.migrate.gitreload'), - ) + ) if settings.MITX_FEATURES.get('ENABLE_SQL_TRACKING_LOGS'): urlpatterns += ( url(r'^event_logs$', 'track.views.view_tracking_log'), url(r'^event_logs/(?P.+)$', 'track.views.view_tracking_log'), - ) + ) # FoldIt views urlpatterns += (