From 300f7f13a6908fc958c8c9a4948c1a8167595096 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Tue, 3 Sep 2013 13:35:04 -0400 Subject: [PATCH] fix pep8 and pylint errors Conflicts: cms/djangoapps/contentstore/views/course.py common/lib/xmodule/xmodule/tests/test_combined_open_ended.py lms/envs/common.py --- .../management/commands/check_course.py | 1 - cms/djangoapps/contentstore/views/course.py | 85 ++++++++++--------- common/lib/capa/capa/inputtypes.py | 55 ++++++------ .../xmodule/tests/test_combined_open_ended.py | 18 ++-- lms/envs/common.py | 14 +-- 5 files changed, 93 insertions(+), 80 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/check_course.py b/cms/djangoapps/contentstore/management/commands/check_course.py index 13ac6af50c..541f5dee75 100644 --- a/cms/djangoapps/contentstore/management/commands/check_course.py +++ b/cms/djangoapps/contentstore/management/commands/check_course.py @@ -60,4 +60,3 @@ class Command(BaseCommand): for item in queried_discussion_items: if item.location.url() not in discussion_items: print 'Found dangling discussion module = {0}'.format(item.location.url()) - diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 939286a765..772dfd2778 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -124,29 +124,33 @@ def create_new_course(request): pass if existing_course is not None: return JsonResponse({ - 'ErrMsg': _('There is already a course defined with the same ' - 'organization, course number, and course run. Please ' - 'change either organization or course number to be ' - 'unique.'), - 'OrgErrMsg': _('Please change either the organization or ' - 'course number so that it is unique.'), - 'CourseErrMsg': _('Please change either the organization or ' - 'course number so that it is unique.'), + 'ErrMsg': _('There is already a course defined with the same ' + 'organization, course number, and course run. Please ' + 'change either organization or course number to be ' + 'unique.'), + 'OrgErrMsg': _('Please change either the organization or ' + 'course number so that it is unique.'), + 'CourseErrMsg': _('Please change either the organization or ' + 'course number so that it is unique.'), }) - course_search_location = ['i4x', dest_location.org, dest_location.course, - 'course', None + course_search_location = [ + 'i4x', + dest_location.org, + dest_location.course, + 'course', + None ] courses = modulestore().get_items(course_search_location) if len(courses) > 0: return JsonResponse({ - 'ErrMsg': _('There is already a course defined with the same ' - 'organization and course number. Please ' - 'change at least one field to be unique.'), - 'OrgErrMsg': _('Please change either the organization or ' - 'course number so that it is unique.'), - 'CourseErrMsg': _('Please change either the organization or ' - 'course number so that it is unique.'), + 'ErrMsg': _('There is already a course defined with the same ' + 'organization and course number. Please ' + 'change at least one field to be unique.'), + 'OrgErrMsg': _('Please change either the organization or ' + 'course number so that it is unique.'), + 'CourseErrMsg': _('Please change either the organization or ' + 'course number so that it is unique.'), }) # instantiate the CourseDescriptor and then persist it @@ -156,15 +160,15 @@ def create_new_course(request): else: metadata = {'display_name': display_name} modulestore('direct').create_and_save_xmodule( - dest_location, - metadata=metadata + dest_location, + metadata=metadata ) new_course = modulestore('direct').get_item(dest_location) # clone a default 'about' overview module as well dest_about_location = dest_location.replace( - category='about', - name='overview' + category='about', + name='overview' ) overview_template = AboutDescriptor.get_template('overview.yaml') modulestore('direct').create_and_save_xmodule( @@ -203,13 +207,16 @@ def course_info(request, org, course, name, provided_id=None): # get current updates location = Location(['i4x', org, course, 'course_info', "updates"]) - return render_to_response('course_info.html', { - 'context_course': course_module, - 'url_base': "/" + org + "/" + course + "/", - 'course_updates': json.dumps(get_course_updates(location)), - 'handouts_location': Location(['i4x', org, course, 'course_info', 'handouts']).url(), - 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(location) + '/'}) - + return render_to_response( + 'course_info.html', + { + 'context_course': course_module, + 'url_base': "/" + org + "/" + course + "/", + 'course_updates': json.dumps(get_course_updates(location)), + 'handouts_location': Location(['i4x', org, course, 'course_info', 'handouts']).url(), + 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(location) + '/' + } + ) @expect_json @require_http_methods(("GET", "POST", "PUT", "DELETE")) @@ -245,7 +252,7 @@ def course_info_updates(request, org, course, provided_id=None): content_type="text/plain" ) # can be either and sometimes django is rewriting one to the other: - elif request.method in ('POST', 'PUT'): + elif request.method in ('POST', 'PUT'): try: return JsonResponse(update_course_updates(location, request.POST, provided_id)) except: @@ -380,7 +387,7 @@ def course_grader_updates(request, org, course, name, grader_index=None): if request.method == 'GET': # Cannot just do a get w/o knowing the course name :-( return JsonResponse(CourseGradingModel.fetch_grader( - Location(location), grader_index + Location(location), grader_index )) elif request.method == "DELETE": # ??? Should this return anything? Perhaps success fail? @@ -388,8 +395,8 @@ def course_grader_updates(request, org, course, name, grader_index=None): return JsonResponse() else: # post or put, doesn't matter. return JsonResponse(CourseGradingModel.update_grader_from_json( - Location(location), - request.POST + Location(location), + request.POST )) @@ -411,8 +418,8 @@ def course_advanced_updates(request, org, course, name): return JsonResponse(CourseMetadata.fetch(location)) elif request.method == 'DELETE': return JsonResponse(CourseMetadata.delete_key( - location, - json.loads(request.body) + location, + json.loads(request.body) )) else: # NOTE: request.POST is messed up because expect_json @@ -479,9 +486,9 @@ def course_advanced_updates(request, org, course, name): filter_tabs = False try: return JsonResponse(CourseMetadata.update_from_json( - location, - request_body, - filter_tabs=filter_tabs + location, + request_body, + filter_tabs=filter_tabs )) except (TypeError, ValueError) as err: return HttpResponseBadRequest( @@ -585,8 +592,8 @@ def textbook_index(request, org, course, name): # MongoKeyValueStore before we update the mongo datastore. course_module.save() store.update_metadata( - course_module.location, - own_metadata(course_module) + course_module.location, + own_metadata(course_module) ) return JsonResponse(course_module.pdf_textbooks) else: diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index d27893d44d..58a3ed8b12 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -208,10 +208,10 @@ class InputTypeBase(object): # end up in a partially-initialized state. loaded = {} to_render = set() - for a in self.get_attributes(): - loaded[a.name] = a.parse_from_xml(self.xml) - if a.render: - to_render.add(a.name) + for attribute in self.get_attributes(): + loaded[attribute.name] = attribute.parse_from_xml(self.xml) + if attribute.render: + to_render.add(attribute.name) self.loaded_attributes = loaded self.to_render = to_render @@ -493,17 +493,17 @@ class JSInput(InputTypeBase): """ Register the attributes. """ - return [Attribute('params', None), # extra iframe params - Attribute('html_file', None), - Attribute('gradefn', "gradefn"), - Attribute('get_statefn', None), # Function to call in iframe - # to get current state. - Attribute('set_statefn', None), # Function to call iframe to - # set state - Attribute('width', "400"), # iframe width - Attribute('height', "300")] # iframe height - - + return [ + Attribute('params', None), # extra iframe params + Attribute('html_file', None), + Attribute('gradefn', "gradefn"), + Attribute('get_statefn', None), # Function to call in iframe + # to get current state. + Attribute('set_statefn', None), # Function to call iframe to + # set state + Attribute('width', "400"), # iframe width + Attribute('height', "300") # iframe height + ] def _extra_context(self): context = { @@ -514,7 +514,6 @@ class JSInput(InputTypeBase): return context - registry.register(JSInput) #----------------------------------------------------------------------------- @@ -1048,8 +1047,8 @@ class ChemicalEquationInput(InputTypeBase): try: result['preview'] = chemcalc.render_to_html(formula) - except pyparsing.ParseException as p: - result['error'] = u"Couldn't parse formula: {0}".format(p.msg) + except pyparsing.ParseException as err: + result['error'] = u"Couldn't parse formula: {0}".format(err.msg) except Exception: # this is unexpected, so log log.warning( @@ -1189,15 +1188,19 @@ class DragAndDropInput(InputTypeBase): 'can_reuse': smth}. """ tag_attrs = dict() - tag_attrs['draggable'] = {'id': Attribute._sentinel, - 'label': "", 'icon': "", - 'can_reuse': ""} + tag_attrs['draggable'] = { + 'id': Attribute._sentinel, + 'label': "", 'icon': "", + 'can_reuse': "" + } - tag_attrs['target'] = {'id': Attribute._sentinel, - 'x': Attribute._sentinel, - 'y': Attribute._sentinel, - 'w': Attribute._sentinel, - 'h': Attribute._sentinel} + tag_attrs['target'] = { + 'id': Attribute._sentinel, + 'x': Attribute._sentinel, + 'y': Attribute._sentinel, + 'w': Attribute._sentinel, + 'h': Attribute._sentinel + } dic = dict() diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py index 8a32f7e822..4eadca110c 100644 --- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -23,9 +23,11 @@ from xmodule.combined_open_ended_module import CombinedOpenEndedModule from xmodule.modulestore import Location from xmodule.tests import get_test_system, test_util_open_ended from xmodule.progress import Progress -from xmodule.tests.test_util_open_ended import (MockQueryDict, DummyModulestore, TEST_STATE_SA_IN, +from xmodule.tests.test_util_open_ended import ( + MockQueryDict, DummyModulestore, TEST_STATE_SA_IN, MOCK_INSTANCE_STATE, TEST_STATE_SA, TEST_STATE_AI, TEST_STATE_AI2, TEST_STATE_AI2_INVALID, - TEST_STATE_SINGLE, TEST_STATE_PE_SINGLE) + TEST_STATE_SINGLE, TEST_STATE_PE_SINGLE +) import capa.xqueue_interface as xqueue_interface @@ -69,7 +71,7 @@ class OpenEndedChildTest(unittest.TestCase): 'peer_grader_count': 1, 'min_to_calibrate': 3, 'max_to_calibrate': 6, - } + } } definition = Mock() descriptor = Mock() @@ -192,7 +194,7 @@ class OpenEndedModuleTest(unittest.TestCase): 'peer_grader_count': 1, 'min_to_calibrate': 3, 'max_to_calibrate': 6, - } + } } oeparam = etree.XML(''' @@ -553,7 +555,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): descriptor, static_data=self.static_data, metadata=self.metadata, - instance_state={'task_states' : TEST_STATE_SA}) + instance_state={'task_states': TEST_STATE_SA}) combinedoe = CombinedOpenEndedV1Module(self.test_system, self.location, @@ -561,7 +563,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): descriptor, static_data=self.static_data, metadata=self.metadata, - instance_state={'task_states' : TEST_STATE_SA_IN}) + instance_state={'task_states': TEST_STATE_SA_IN}) def test_get_score_realistic(self): @@ -605,7 +607,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): descriptor = Mock(data=definition) instance_state = {'task_states': task_state, 'graded': True} if task_number is not None: - instance_state.update({'current_task_number' : task_number}) + instance_state.update({'current_task_number': task_number}) combinedoe = CombinedOpenEndedV1Module(self.test_system, self.location, definition, @@ -711,7 +713,7 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore): #Simulate a student saving an answer html = module.handle_ajax("get_html", {}) - module.handle_ajax("save_answer", {"student_answer": self.answer, "can_upload_files" : False, "student_file" : None}) + module.handle_ajax("save_answer", {"student_answer": self.answer, "can_upload_files": False, "student_file": None}) html = module.handle_ajax("get_html", {}) #Mock a student submitting an assessment diff --git a/lms/envs/common.py b/lms/envs/common.py index 9d886f8dc1..4e70f3ade1 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -290,12 +290,14 @@ WIKI_ENABLED = False ### COURSE_DEFAULT = '6.002x_Fall_2012' -COURSE_SETTINGS = {'6.002x_Fall_2012': {'number': '6.002x', - 'title': 'Circuits and Electronics', - 'xmlpath': '6002x/', - 'location': 'i4x://edx/6002xs12/course/6.002x_Fall_2012', - } - } +COURSE_SETTINGS = { + '6.002x_Fall_2012': { + 'number': '6.002x', + 'title': 'Circuits and Electronics', + 'xmlpath': '6002x/', + 'location': 'i4x://edx/6002xs12/course/6.002x_Fall_2012', + } +} # IP addresses that are allowed to reload the course, etc. # TODO (vshnayder): Will probably need to change as we get real access control in.