From f81c21902eb0e8d026612b052557142ce1527153 Mon Sep 17 00:00:00 2001 From: Andy Armstrong Date: Thu, 25 May 2017 10:48:27 -0400 Subject: [PATCH] Add isort to edx-platform LEARNER-1168 --- .isort.cfg | 4 + lms/djangoapps/courseware/views/views.py | 110 ++++++++---------- openedx/features/course_bookmarks/urls.py | 2 +- openedx/features/course_experience/urls.py | 2 +- openedx/features/course_experience/utils.py | 3 +- .../course_experience/views/course_dates.py | 3 +- .../course_experience/views/course_home.py | 10 +- .../course_experience/views/course_outline.py | 4 +- .../course_experience/views/course_updates.py | 4 +- .../views/welcome_message.py | 4 +- openedx/features/enterprise_support/api.py | 21 ++-- requirements/edx/development.txt | 1 + 12 files changed, 83 insertions(+), 85 deletions(-) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000000..cb72885281 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,4 @@ +[settings] +indent=' ' +line_length=120 +multi_line_output=3 diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 32bbe36e3f..423e211626 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -4,41 +4,66 @@ Courseware views functions import json import logging import urllib -import waffle from collections import OrderedDict, namedtuple from datetime import datetime import analytics +import waffle from django.conf import settings from django.contrib.auth.decorators import login_required -from django.contrib.auth.models import User, AnonymousUser -from django.core.exceptions import PermissionDenied - -from django.core.urlresolvers import reverse +from django.contrib.auth.models import AnonymousUser, User from django.core.context_processors import csrf +from django.core.exceptions import PermissionDenied +from django.core.urlresolvers import reverse from django.db import transaction from django.db.models import Q -from django.http import ( - Http404, - HttpResponse, - HttpResponseBadRequest, - HttpResponseForbidden, - QueryDict, -) +from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, QueryDict from django.shortcuts import redirect from django.utils.decorators import method_decorator from django.utils.timezone import UTC from django.utils.translation import ugettext as _ from django.views.decorators.cache import cache_control from django.views.decorators.csrf import ensure_csrf_cookie -from django.views.decorators.http import require_GET, require_POST, require_http_methods +from django.views.decorators.http import require_GET, require_http_methods, require_POST from django.views.generic import View -from eventtracking import tracker from ipware.ip import get_ip from markupsafe import escape from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey from rest_framework import status +from web_fragments.fragment import Fragment + +import shoppingcart +import survey.utils +import survey.views +from certificates import api as certs_api +from certificates.models import CertificateStatuses +from commerce.utils import EcommerceService +from course_modes.models import CourseMode +from courseware.access import has_access, has_ccx_coach_role +from courseware.access_response import StartDateError +from courseware.access_utils import in_preview_mode, is_course_open_for_learner +from courseware.courses import ( + get_course, + get_course_by_id, + get_course_overview_with_access, + get_course_with_access, + get_courses, + get_current_child, + get_permission_for_course_about, + get_studio_url, + sort_by_announcement, + sort_by_start_date +) +from courseware.date_summary import VerifiedUpgradeDeadlineDate +from courseware.masquerade import setup_masquerade +from courseware.model_data import FieldDataCache +from courseware.models import BaseStudentModuleHistory, StudentModule +from courseware.url_helpers import get_redirect_url +from courseware.user_state_client import DjangoXBlockUserStateClient +from edxmako.shortcuts import marketing_link, render_to_response, render_to_string +from enrollment.api import add_enrollment +from eventtracking import tracker from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException from lms.djangoapps.ccx.utils import prep_course_for_grading from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, Redirect @@ -46,75 +71,42 @@ from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory from lms.djangoapps.instructor.enrollment import uses_shib from lms.djangoapps.instructor.views.api import require_global_staff from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification - -import shoppingcart -import survey.utils -import survey.views -from certificates import api as certs_api -from certificates.models import CertificateStatuses -from openedx.core.djangoapps.models.course_details import CourseDetails -from openedx.core.djangoapps.plugin_api.views import EdxFragmentView -from commerce.utils import EcommerceService -from enrollment.api import add_enrollment -from course_modes.models import CourseMode -from courseware.access import has_access, has_ccx_coach_role -from courseware.access_response import StartDateError -from courseware.access_utils import in_preview_mode, is_course_open_for_learner -from courseware.courses import ( - get_courses, - get_course, - get_course_by_id, - get_course_overview_with_access, - get_course_with_access, - get_current_child, - get_permission_for_course_about, - get_studio_url, - sort_by_announcement, - sort_by_start_date, -) -from courseware.date_summary import VerifiedUpgradeDeadlineDate -from courseware.masquerade import setup_masquerade -from courseware.model_data import FieldDataCache -from courseware.models import StudentModule, BaseStudentModuleHistory -from courseware.url_helpers import get_redirect_url -from courseware.user_state_client import DjangoXBlockUserStateClient -from edxmako.shortcuts import render_to_response, render_to_string, marketing_link from openedx.core.djangoapps.catalog.utils import get_programs, get_programs_with_type from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.coursetalk.helpers import inject_coursetalk_keys_into_context from openedx.core.djangoapps.credit.api import ( get_credit_requirement_status, - is_user_eligible_for_credit, - is_credit_course + is_credit_course, + is_user_eligible_for_credit ) -from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration +from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.monitoring_utils import set_custom_metrics_for_course_key +from openedx.core.djangoapps.plugin_api.views import EdxFragmentView +from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender +from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.features.course_experience import ( - course_home_url_name, UNIFIED_COURSE_EXPERIENCE_FLAG, UNIFIED_COURSE_VIEW_FLAG, + course_home_url_name ) -from openedx.features.enterprise_support.api import data_sharing_consent_required from openedx.features.course_experience.views.course_dates import CourseDatesFragmentView +from openedx.features.enterprise_support.api import data_sharing_consent_required from shoppingcart.utils import is_shopping_cart_enabled -from student.models import UserTestGroup, CourseEnrollment +from student.models import CourseEnrollment, UserTestGroup from survey.utils import must_answer_survey from util.cache import cache, cache_if_anonymous from util.date_utils import strftime_localized from util.db import outer_atomic from util.milestones_helpers import get_prerequisite_courses_display -from util.views import _record_feedback_in_zendesk -from util.views import ensure_valid_course_key, ensure_valid_usage_key +from util.views import _record_feedback_in_zendesk, ensure_valid_course_key, ensure_valid_usage_key from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem from xmodule.tabs import CourseTabList from xmodule.x_module import STUDENT_VIEW -from web_fragments.fragment import Fragment from ..entrance_exams import user_can_skip_entrance_exam -from ..module_render import get_module_for_descriptor, get_module, get_module_by_usage_id +from ..module_render import get_module, get_module_by_usage_id, get_module_for_descriptor log = logging.getLogger("edx.courseware") diff --git a/openedx/features/course_bookmarks/urls.py b/openedx/features/course_bookmarks/urls.py index 789579e27d..667e3613cb 100644 --- a/openedx/features/course_bookmarks/urls.py +++ b/openedx/features/course_bookmarks/urls.py @@ -4,7 +4,7 @@ Defines URLs for the course experience. from django.conf.urls import url -from views.course_bookmarks import CourseBookmarksView, CourseBookmarksFragmentView +from views.course_bookmarks import CourseBookmarksFragmentView, CourseBookmarksView urlpatterns = [ url( diff --git a/openedx/features/course_experience/urls.py b/openedx/features/course_experience/urls.py index 8057c52b56..42372fb9f8 100644 --- a/openedx/features/course_experience/urls.py +++ b/openedx/features/course_experience/urls.py @@ -4,7 +4,7 @@ Defines URLs for the course experience. from django.conf.urls import url -from views.course_home import CourseHomeView, CourseHomeFragmentView +from views.course_home import CourseHomeFragmentView, CourseHomeView from views.course_outline import CourseOutlineFragmentView from views.course_updates import CourseUpdatesFragmentView, CourseUpdatesView from views.welcome_message import WelcomeMessageFragmentView diff --git a/openedx/features/course_experience/utils.py b/openedx/features/course_experience/utils.py index bb95600317..14f07d479e 100644 --- a/openedx/features/course_experience/utils.py +++ b/openedx/features/course_experience/utils.py @@ -1,9 +1,10 @@ """ Common utilities for the course experience, including course outline. """ +from opaque_keys.edx.keys import CourseKey + from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.course_blocks.utils import get_student_module_as_dict -from opaque_keys.edx.keys import CourseKey from openedx.core.lib.cache_utils import memoized from xmodule.modulestore.django import modulestore diff --git a/openedx/features/course_experience/views/course_dates.py b/openedx/features/course_experience/views/course_dates.py index ccb2287543..c95d25f35b 100644 --- a/openedx/features/course_experience/views/course_dates.py +++ b/openedx/features/course_experience/views/course_dates.py @@ -4,8 +4,9 @@ Fragment for rendering the course dates sidebar. from django.template.loader import render_to_string from opaque_keys.edx.keys import CourseKey from web_fragments.fragment import Fragment + +from courseware.courses import get_course_date_blocks, get_course_with_access from openedx.core.djangoapps.plugin_api.views import EdxFragmentView -from courseware.courses import get_course_with_access, get_course_date_blocks class CourseDatesFragmentView(EdxFragmentView): diff --git a/openedx/features/course_experience/views/course_home.py b/openedx/features/course_experience/views/course_home.py index c854a63a08..220a9f1355 100644 --- a/openedx/features/course_experience/views/course_home.py +++ b/openedx/features/course_experience/views/course_home.py @@ -8,18 +8,18 @@ from django.template.loader import render_to_string from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_control from django.views.decorators.csrf import ensure_csrf_cookie +from opaque_keys.edx.keys import CourseKey +from web_fragments.fragment import Fragment from courseware.courses import get_course_info_section, get_course_with_access from lms.djangoapps.courseware.views.views import CourseTabView -from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from util.views import ensure_valid_course_key -from web_fragments.fragment import Fragment -from .course_outline import CourseOutlineFragmentView -from .course_dates import CourseDatesFragmentView -from .welcome_message import WelcomeMessageFragmentView from ..utils import get_course_outline_block_tree +from .course_dates import CourseDatesFragmentView +from .course_outline import CourseOutlineFragmentView +from .welcome_message import WelcomeMessageFragmentView class CourseHomeView(CourseTabView): diff --git a/openedx/features/course_experience/views/course_outline.py b/openedx/features/course_experience/views/course_outline.py index 2c908a556e..1c653cdb4e 100644 --- a/openedx/features/course_experience/views/course_outline.py +++ b/openedx/features/course_experience/views/course_outline.py @@ -4,11 +4,11 @@ Views to show a course outline. from django.core.context_processors import csrf from django.template.loader import render_to_string +from opaque_keys.edx.keys import CourseKey +from web_fragments.fragment import Fragment from courseware.courses import get_course_overview_with_access -from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.plugin_api.views import EdxFragmentView -from web_fragments.fragment import Fragment from ..utils import get_course_outline_block_tree diff --git a/openedx/features/course_experience/views/course_updates.py b/openedx/features/course_experience/views/course_updates.py index 1f2aa5b8b6..a321ceb0a3 100644 --- a/openedx/features/course_experience/views/course_updates.py +++ b/openedx/features/course_experience/views/course_updates.py @@ -8,13 +8,13 @@ from django.core.urlresolvers import reverse from django.template.loader import render_to_string from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_control +from opaque_keys.edx.keys import CourseKey +from web_fragments.fragment import Fragment from courseware.courses import get_course_info_section, get_course_with_access from lms.djangoapps.courseware.views.views import CourseTabView -from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.plugin_api.views import EdxFragmentView from openedx.features.course_experience import default_course_url_name -from web_fragments.fragment import Fragment class CourseUpdatesView(CourseTabView): diff --git a/openedx/features/course_experience/views/welcome_message.py b/openedx/features/course_experience/views/welcome_message.py index 8709bea2f7..71215f91a3 100644 --- a/openedx/features/course_experience/views/welcome_message.py +++ b/openedx/features/course_experience/views/welcome_message.py @@ -3,11 +3,11 @@ View logic for handling course welcome messages. """ from django.template.loader import render_to_string +from opaque_keys.edx.keys import CourseKey +from web_fragments.fragment import Fragment from courseware.courses import get_course_info_section_module, get_course_with_access -from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.plugin_api.views import EdxFragmentView -from web_fragments.fragment import Fragment class WelcomeMessageFragmentView(EdxFragmentView): diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index fc6af499e8..a5c57b12c3 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -1,11 +1,11 @@ """ APIs providing support for enterprise functionality. """ -from functools import wraps import hashlib import logging -import six +from functools import wraps +import six from django.conf import settings from django.contrib.auth.models import User from django.core.cache import cache @@ -14,9 +14,15 @@ from django.shortcuts import redirect from django.template.loader import render_to_string from django.utils.http import urlencode from django.utils.translation import ugettext as _ -from slumber.exceptions import HttpClientError, HttpServerError - from edx_rest_api_client.client import EdxRestApiClient +from requests.exceptions import ConnectionError, Timeout +from slumber.exceptions import HttpClientError, HttpServerError, SlumberBaseException + +from openedx.core.djangoapps.api_admin.utils import course_discovery_api_client +from openedx.core.djangoapps.catalog.models import CatalogIntegration +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.lib.token_utils import JwtBuilder + try: from enterprise import utils as enterprise_utils from enterprise.models import EnterpriseCourseEnrollment, EnterpriseCustomer @@ -24,13 +30,6 @@ try: from enterprise.utils import consent_necessary_for_course except ImportError: pass -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from slumber.exceptions import SlumberBaseException -from requests.exceptions import ConnectionError, Timeout -from openedx.core.djangoapps.api_admin.utils import course_discovery_api_client - -from openedx.core.lib.token_utils import JwtBuilder -from openedx.core.djangoapps.catalog.models import CatalogIntegration CONSENT_FAILED_PARAMETER = 'consent_failed' diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index e7d763d7b6..4d81b28025 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -5,6 +5,7 @@ # Python libraries to install directly from github / PyPi click==3.3 +isort==4.2.5 # Third-party: -e git+https://github.com/doctoryes/code_block_timer.git@f3d0629f086bcc649c3c77f4bc5b9c2c8172c3bf#egg=code_block_timer