diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 36ef38475f..ddf605eb96 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -21,7 +21,7 @@ from xmodule.modulestore.django import modulestore from xmodule.contentstore.content import StaticContent from xmodule.tabs import PDFTextbookTabs -from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError, InsufficientSpecificationError +from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError from opaque_keys import InvalidKeyError from xmodule.modulestore.locations import Location, SlashSeparatedCourseKey diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index e583c7230a..ffc161c4b4 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -30,7 +30,6 @@ from xmodule.modulestore.xml_exporter import export_to_xml from .access import has_course_access -from .access import has_course_access from extract_tar import safetar_extractall from student import auth from student.roles import CourseInstructorRole, CourseStaffRole, GlobalStaff diff --git a/common/djangoapps/student/management/commands/anonymized_id_mapping.py b/common/djangoapps/student/management/commands/anonymized_id_mapping.py index 6552d88db2..363c3e74be 100644 --- a/common/djangoapps/student/management/commands/anonymized_id_mapping.py +++ b/common/djangoapps/student/management/commands/anonymized_id_mapping.py @@ -13,7 +13,6 @@ import csv from django.contrib.auth.models import User from django.core.management.base import BaseCommand, CommandError -from opaque_keys import InvalidKeyError from student.models import anonymous_id_for_user from xmodule.modulestore.locations import SlashSeparatedCourseKey diff --git a/common/djangoapps/student/management/commands/create_random_users.py b/common/djangoapps/student/management/commands/create_random_users.py index 465077afec..000ebd2ac1 100644 --- a/common/djangoapps/student/management/commands/create_random_users.py +++ b/common/djangoapps/student/management/commands/create_random_users.py @@ -1,16 +1,18 @@ -## -## A script to create some dummy users - +""" +A script to create some dummy users +""" from django.core.management.base import BaseCommand from student.models import CourseEnrollment - +from opaque_keys import InvalidKeyError +from xmodule.modulestore.keys import CourseKey +from xmodule.modulestore.locations import SlashSeparatedCourseKey from student.views import _do_create_account, get_random_post_override -def create(n, course_key): - """Create n users, enrolling them in course_key if it's not None""" - for i in range(n): - (user, user_profile, _) = _do_create_account(get_random_post_override()) +def create(num, course_key): + """Create num users, enrolling them in course_key if it's not None""" + for idx in range(num): + (user, user_profile, __) = _do_create_account(get_random_post_override()) if course_key is not None: CourseEnrollment.enroll(user, course_key) @@ -31,7 +33,7 @@ Examples: print Command.help return - n = int(args[0]) + num = int(args[0]) if len(args) == 2: try: @@ -41,4 +43,4 @@ Examples: else: course_key = None - create(n, course_key) + create(num, course_key) diff --git a/common/djangoapps/student/management/commands/get_grades.py b/common/djangoapps/student/management/commands/get_grades.py index bbbbd3453d..a3857e8e9e 100644 --- a/common/djangoapps/student/management/commands/get_grades.py +++ b/common/djangoapps/student/management/commands/get_grades.py @@ -1,3 +1,7 @@ +""" +Management command to generate a list of grades for +all students that are enrolled in a course. +""" from courseware import grades, courses from certificates.models import GeneratedCertificate from django.test.client import RequestFactory diff --git a/common/djangoapps/student/roles.py b/common/djangoapps/student/roles.py index cd69ed385d..89043b2c3a 100644 --- a/common/djangoapps/student/roles.py +++ b/common/djangoapps/student/roles.py @@ -7,7 +7,6 @@ from abc import ABCMeta, abstractmethod from django.contrib.auth.models import User from student.models import CourseAccessRole -from xmodule_django.models import CourseKeyField class AccessRole(object): diff --git a/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py index 0f04298685..69405c2e65 100644 --- a/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py +++ b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py @@ -10,7 +10,6 @@ import urllib from xmodule.modulestore.exceptions import InvalidLocationError, ItemNotFoundError from xmodule.modulestore.locator import BlockUsageLocator, CourseLocator from xmodule.modulestore.locations import SlashSeparatedCourseKey -from xmodule.modulestore.keys import UsageKey class LocMapperStore(object): diff --git a/lms/djangoapps/bulk_email/forms.py b/lms/djangoapps/bulk_email/forms.py index f62d28e03b..43fda78fe9 100644 --- a/lms/djangoapps/bulk_email/forms.py +++ b/lms/djangoapps/bulk_email/forms.py @@ -11,7 +11,6 @@ from bulk_email.models import CourseEmailTemplate, COURSE_EMAIL_MESSAGE_BODY_TAG from opaque_keys import InvalidKeyError from xmodule.modulestore import XML_MODULESTORE_TYPE from xmodule.modulestore.django import modulestore -from opaque_keys import InvalidKeyError from xmodule.modulestore.keys import CourseKey from xmodule.modulestore.locations import SlashSeparatedCourseKey diff --git a/lms/djangoapps/certificates/management/commands/cert_whitelist.py b/lms/djangoapps/certificates/management/commands/cert_whitelist.py index 0aa7d81ab7..a11d0c27d6 100644 --- a/lms/djangoapps/certificates/management/commands/cert_whitelist.py +++ b/lms/djangoapps/certificates/management/commands/cert_whitelist.py @@ -1,3 +1,7 @@ +""" +Management command which sets or gets the certificate whitelist for a given +user/course +""" from django.core.management.base import BaseCommand, CommandError from optparse import make_option from opaque_keys import InvalidKeyError @@ -56,7 +60,7 @@ class Command(BaseCommand): try: course = CourseKey.from_string(course_id) except InvalidKeyError: - log.warning("Course id %s could not be parsed as a CourseKey; falling back to SSCK.from_dep_str", course_id) + print("Course id {} could not be parsed as a CourseKey; falling back to SSCK.from_dep_str".format(course_id)) course = SlashSeparatedCourseKey.from_deprecated_string(course_id) if options['add'] and options['del']: diff --git a/lms/djangoapps/certificates/management/commands/ungenerated_certs.py b/lms/djangoapps/certificates/management/commands/ungenerated_certs.py index 0a86c102c2..81c3e47f43 100644 --- a/lms/djangoapps/certificates/management/commands/ungenerated_certs.py +++ b/lms/djangoapps/certificates/management/commands/ungenerated_certs.py @@ -1,3 +1,7 @@ +""" +Management command to find all students that need certificates for +courses that have finished, and put their cert requests on the queue. +""" from django.core.management.base import BaseCommand, CommandError from certificates.models import certificate_status_for_student from certificates.queue import XQueueCertInterface @@ -73,7 +77,7 @@ class Command(BaseCommand): try: course = CourseKey.from_string(options['course']) except InvalidKeyError: - log.warning("Course id %s could not be parsed as a CourseKey; falling back to SSCK.from_dep_str", course_id) + print("Course id {} could not be parsed as a CourseKey; falling back to SSCK.from_dep_str".format(options['course'])) course = SlashSeparatedCourseKey.from_deprecated_string(options['course']) ended_courses = [course] else: diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index 2007046e33..cb471dd79c 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -113,7 +113,12 @@ class StudentModuleHistory(models.Model): max_grade = models.FloatField(null=True, blank=True) @receiver(post_save, sender=StudentModule) - def save_history(sender, instance, **kwargs): # pylint: disable=no-self-argument + def save_history(sender, instance, **kwargs): # pylint: disable=no-self-argument, unused-argument + """ + Checks the instance's module_type, and creates & saves a + StudentModuleHistory entry if the module_type is one that + we save. + """ if instance.module_type in StudentModuleHistory.HISTORY_SAVING_TYPES: history_entry = StudentModuleHistory(student_module=instance, version=None, diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 75aaa516f7..4e332c91a8 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -22,7 +22,6 @@ from xmodule.video_module.transcripts_utils import ( TranscriptException, TranscriptsGenerationException, ) -from xmodule.modulestore.mongo.base import MongoModuleStore from xmodule.modulestore.locations import AssetLocation SRT_content = textwrap.dedent(""" diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 5fc16f7bb7..c7df0ca3fc 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -47,7 +47,6 @@ from opaque_keys import InvalidKeyError from microsite_configuration import microsite from xmodule.modulestore.locations import SlashSeparatedCourseKey -from xmodule.modulestore.keys import UsageKey log = logging.getLogger("edx.courseware") diff --git a/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py b/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py index 92a82e7946..3650aab05c 100644 --- a/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py +++ b/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py @@ -1,3 +1,6 @@ +""" +Management command to seed default permissions and roles. +""" from django.core.management.base import BaseCommand, CommandError from django_comment_common.utils import seed_permissions_roles from xmodule.modulestore.locations import SlashSeparatedCourseKey diff --git a/lms/djangoapps/instructor/management/commands/compute_grades.py b/lms/djangoapps/instructor/management/commands/compute_grades.py index 41289f1a61..8479474872 100644 --- a/lms/djangoapps/instructor/management/commands/compute_grades.py +++ b/lms/djangoapps/instructor/management/commands/compute_grades.py @@ -1,8 +1,8 @@ #!/usr/bin/python -# -# django management command: dump grades to csv files -# for use by batch processes - +""" +django management command: dump grades to csv files +for use by batch processes +""" from instructor.offline_gradecalc import offline_grade_calculation from courseware.courses import get_course_by_id from xmodule.modulestore.django import modulestore @@ -37,7 +37,7 @@ class Command(BaseCommand): except InvalidKeyError: course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) try: - course = get_course_by_id(course_key) + _course = get_course_by_id(course_key) except Exception as err: print "-----------------------------------------------------------------------------" print "Sorry, cannot find course with id {}".format(course_id) diff --git a/lms/djangoapps/instructor/management/commands/dump_grades.py b/lms/djangoapps/instructor/management/commands/dump_grades.py index 7312de05a6..a2a68fb21a 100644 --- a/lms/djangoapps/instructor/management/commands/dump_grades.py +++ b/lms/djangoapps/instructor/management/commands/dump_grades.py @@ -1,8 +1,8 @@ #!/usr/bin/python -# -# django management command: dump grades to csv files -# for use by batch processes - +""" +django management command: dump grades to csv files +for use by batch processes +""" import csv from instructor.views.legacy import get_student_grade_summary_data @@ -52,7 +52,9 @@ class Command(BaseCommand): try: course = get_course_by_id(course_key) - except Exception as err: + # Ok with catching general exception here because this is run as a management command + # and the exception is exposed right away to the user. + except Exception as err: # pylint: disable=broad-except print "-----------------------------------------------------------------------------" print "Sorry, cannot find course with id {}".format(course_id) print "Got exception {}".format(err) diff --git a/lms/djangoapps/instructor/management/commands/openended_post.py b/lms/djangoapps/instructor/management/commands/openended_post.py index a2a28ee07a..b3e6251cca 100644 --- a/lms/djangoapps/instructor/management/commands/openended_post.py +++ b/lms/djangoapps/instructor/management/commands/openended_post.py @@ -6,7 +6,6 @@ from django.core.management.base import BaseCommand from optparse import make_option from xmodule.modulestore.django import modulestore -from xmodule.modulestore.keys import UsageKey from xmodule.modulestore.locations import SlashSeparatedCourseKey from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild from xmodule.open_ended_grading_classes.open_ended_module import OpenEndedModule diff --git a/lms/djangoapps/instructor/management/commands/openended_stats.py b/lms/djangoapps/instructor/management/commands/openended_stats.py index 0ff3157b74..fef4fe73e4 100644 --- a/lms/djangoapps/instructor/management/commands/openended_stats.py +++ b/lms/djangoapps/instructor/management/commands/openended_stats.py @@ -9,7 +9,6 @@ from optparse import make_option from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore -from xmodule.modulestore.keys import UsageKey from xmodule.modulestore.locations import SlashSeparatedCourseKey from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild diff --git a/lms/djangoapps/instructor/offline_gradecalc.py b/lms/djangoapps/instructor/offline_gradecalc.py index 02b46534e4..9c77bc276e 100644 --- a/lms/djangoapps/instructor/offline_gradecalc.py +++ b/lms/djangoapps/instructor/offline_gradecalc.py @@ -1,10 +1,11 @@ -# ======== Offline calculation of grades ============================================================================= -# -# Computing grades of a large number of students can take a long time. These routines allow grades to -# be computed offline, by a batch process (eg cronjob). -# -# The grades are stored in the OfflineComputedGrade table of the courseware model. +""" +======== Offline calculation of grades ============================================================= +Computing grades of a large number of students can take a long time. These routines allow grades to +be computed offline, by a batch process (eg cronjob). + +The grades are stored in the OfflineComputedGrade table of the courseware model. +""" import json import time @@ -49,7 +50,7 @@ def offline_grade_calculation(course_key): gradeset = grades.grade(student, request, course, keep_raw_scores=True) gs = enc.encode(gradeset) - ocg, created = models.OfflineComputedGrade.objects.get_or_create(user=student, course_id=course_key) + ocg, _created = models.OfflineComputedGrade.objects.get_or_create(user=student, course_id=course_key) ocg.gradeset = gs ocg.save() print "%s done" % student # print statement used because this is run by a management command diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index 1a3ea1e377..45db5ed5a7 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -13,7 +13,6 @@ from nose.tools import raises from mock import Mock, patch from django.conf import settings from django.test.utils import override_settings -from django.conf import settings from django.core.urlresolvers import reverse from django.http import HttpRequest, HttpResponse from django_comment_common.models import FORUM_ROLE_COMMUNITY_TA, Role diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index 4ce954ae2a..ddc0c69329 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -9,7 +9,6 @@ from courseware.models import StudentModule from django.conf import settings from django.test import TestCase from django.test.utils import override_settings -from django.test.client import RequestFactory from student.tests.factories import UserFactory from xmodule.modulestore.tests.factories import CourseFactory from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE @@ -27,7 +26,6 @@ from xmodule.modulestore.locations import SlashSeparatedCourseKey from submissions import api as sub_api from student.models import anonymous_id_for_user -from .test_tools import msk_from_problem_urlname class TestSettableEnrollmentState(TestCase): diff --git a/lms/djangoapps/instructor/tests/test_legacy_gradebook.py b/lms/djangoapps/instructor/tests/test_legacy_gradebook.py index 522e0dac2f..fddeef7772 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_gradebook.py +++ b/lms/djangoapps/instructor/tests/test_legacy_gradebook.py @@ -11,7 +11,6 @@ from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE from capa.tests.response_xml_factory import StringResponseXMLFactory from courseware.tests.factories import StudentModuleFactory from xmodule.modulestore import Location -from xmodule.modulestore.locations import SlashSeparatedCourseKey from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/instructor/tests/test_legacy_reset.py b/lms/djangoapps/instructor/tests/test_legacy_reset.py index 9a7112ed0f..a6a6beaecb 100644 --- a/lms/djangoapps/instructor/tests/test_legacy_reset.py +++ b/lms/djangoapps/instructor/tests/test_legacy_reset.py @@ -16,7 +16,6 @@ from courseware.models import StudentModule from submissions import api as sub_api from student.models import anonymous_id_for_user -from .test_tools import msk_from_problem_urlname @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) diff --git a/lms/djangoapps/notes/api.py b/lms/djangoapps/notes/api.py index b8bc4f5402..d782d7543c 100644 --- a/lms/djangoapps/notes/api.py +++ b/lms/djangoapps/notes/api.py @@ -148,7 +148,7 @@ def create(request, course_key): return ApiResponse(http_response=response, data=None) -def read(request, course_key, note_id): +def read(request, course_key, note_id): # pylint: disable=unused-argument (course_key) ''' Returns a single annotation object. ''' @@ -163,7 +163,7 @@ def read(request, course_key, note_id): return ApiResponse(http_response=HttpResponse(), data=note.as_dict()) -def update(request, course_key, note_id): +def update(request, course_key, note_id): # pylint: disable=unused-argument (course_key) ''' Updates an annotation object and returns a 303 with the read location. ''' @@ -247,7 +247,7 @@ def search(request, course_key): return ApiResponse(http_response=HttpResponse(), data=result) -def root(request, course_key): +def root(request, course_key): # pylint: disable=unused-argument (course_key, request) ''' Returns version information about the API. ''' diff --git a/lms/djangoapps/psychometrics/management/commands/init_psychometrics.py b/lms/djangoapps/psychometrics/management/commands/init_psychometrics.py index c94c4abb82..c61eabfb68 100644 --- a/lms/djangoapps/psychometrics/management/commands/init_psychometrics.py +++ b/lms/djangoapps/psychometrics/management/commands/init_psychometrics.py @@ -7,7 +7,6 @@ import json from courseware.models import StudentModule from track.models import TrackingLog from psychometrics.models import PsychometricData -from xmodule.modulestore.keys import UsageKey from django.conf import settings from django.core.management.base import BaseCommand