diff --git a/common/djangoapps/database_fixups/migrations/0001_initial.py b/common/djangoapps/database_fixups/migrations/0001_initial.py index f15f8abf54..f1843bca4d 100644 --- a/common/djangoapps/database_fixups/migrations/0001_initial.py +++ b/common/djangoapps/database_fixups/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations, models # We used to have a uniqueness constraint on auth_user.email: diff --git a/common/djangoapps/edxmako/__init__.py b/common/djangoapps/edxmako/__init__.py index 4becc66631..29b1342ded 100644 --- a/common/djangoapps/edxmako/__init__.py +++ b/common/djangoapps/edxmako/__init__.py @@ -16,7 +16,7 @@ LOOKUP = {} from .paths import add_lookup, clear_lookups, lookup_template, save_lookups # lint-amnesty, pylint: disable=wrong-import-position -class Engines(object): +class Engines: """ Aliases for the available template engines. Note that the preview engine is only configured for cms. diff --git a/common/djangoapps/edxmako/makoloader.py b/common/djangoapps/edxmako/makoloader.py index cf3048dc17..f51dcf36b4 100644 --- a/common/djangoapps/edxmako/makoloader.py +++ b/common/djangoapps/edxmako/makoloader.py @@ -52,7 +52,7 @@ class MakoLoader: # In order to allow dynamic template overrides, we need to cache templates based on their absolute paths # rather than relative paths, overriding templates would have same relative paths. - module_directory = self.module_directory.rstrip("/") + "/{dir_hash}/".format(dir_hash=hash(origin.name)) + module_directory = self.module_directory.rstrip("/") + f"/{hash(origin.name)}/" if source.startswith("## mako\n"): # This is a mako template diff --git a/common/djangoapps/edxmako/shortcuts.py b/common/djangoapps/edxmako/shortcuts.py index f51b538aa7..012db3f653 100644 --- a/common/djangoapps/edxmako/shortcuts.py +++ b/common/djangoapps/edxmako/shortcuts.py @@ -93,11 +93,11 @@ def marketing_link(name): try: return reverse(link_map[name]) except NoReverseMatch: - log.debug(u"Cannot find corresponding link for name: %s", name) + log.debug("Cannot find corresponding link for name: %s", name) set_custom_attribute('unresolved_marketing_link', name) return '#' else: - log.debug(u"Cannot find corresponding link for name: %s", name) + log.debug("Cannot find corresponding link for name: %s", name) return '#' @@ -143,15 +143,12 @@ def marketing_link_context_processor(request): settings.MKTG_URLS ) - return dict( # lint-amnesty, pylint: disable=consider-using-dict-comprehension - [ - ("MKTG_URL_" + k, marketing_link(k)) - for k in ( - six.viewkeys(settings.MKTG_URL_LINK_MAP) | - six.viewkeys(marketing_urls) - ) - ] - ) + return { + "MKTG_URL_" + k: marketing_link(k) + for k in ( + settings.MKTG_URL_LINK_MAP.keys() | marketing_urls.keys() + ) + } def render_to_string(template_name, dictionary, namespace='main', request=None): diff --git a/common/djangoapps/edxmako/template.py b/common/djangoapps/edxmako/template.py index 2fde67a055..855a2714b8 100644 --- a/common/djangoapps/edxmako/template.py +++ b/common/djangoapps/edxmako/template.py @@ -27,7 +27,7 @@ KEY_CSRF_TOKENS = ('csrf_token', 'csrf') UNKNOWN_SOURCE = '' -class Template(object): +class Template: """ This bridges the gap between a Mako template and a Django template. It can be rendered like it is a Django template because the arguments are transformed diff --git a/common/djangoapps/status/models.py b/common/djangoapps/status/models.py index d10937ae46..165dad41c1 100644 --- a/common/djangoapps/status/models.py +++ b/common/djangoapps/status/models.py @@ -34,7 +34,7 @@ class GlobalStatusMessage(ConfigurationModel): def full_message(self, course_key): """ Returns the full status message, including any course-specific status messages. """ - cache_key = "status_message.{course_id}".format(course_id=str(course_key)) + cache_key = f"status_message.{str(course_key)}" if cache.get(cache_key): return cache.get(cache_key) diff --git a/common/djangoapps/student/management/commands/transfer_students.py b/common/djangoapps/student/management/commands/transfer_students.py index 2f865df766..3d17047786 100644 --- a/common/djangoapps/student/management/commands/transfer_students.py +++ b/common/djangoapps/student/management/commands/transfer_students.py @@ -66,7 +66,7 @@ class Command(TrackedCommand): mode = enrollment.mode old_is_active = enrollment.is_active CourseEnrollment.unenroll(user, source_key, skip_refund=True) - print('Unenrolled {} from {}'.format(user.username, str(source_key))) + print(f'Unenrolled {user.username} from {str(source_key)}') for dest_key in dest_keys: if CourseEnrollment.is_enrolled(user, dest_key): diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 0bd47028ba..fa5d7fc47a 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -421,7 +421,7 @@ def get_potentially_retired_user_by_username(username): # We should have, at most, a retired username and an active one with a username # differing only by case. If there are more we need to disambiguate them by hand. - raise Exception('Expected 1 or 2 Users, received {}'.format(str(potential_users))) + raise Exception(f'Expected 1 or 2 Users, received {str(potential_users)}') def get_potentially_retired_user_by_username_and_hash(username, hashed_username): @@ -898,7 +898,7 @@ class Registration(models.Model): db_table = "auth_registration" user = models.OneToOneField(User, on_delete=models.CASCADE) - activation_key = models.CharField((u'activation key'), max_length=32, unique=True, db_index=True) + activation_key = models.CharField(('activation key'), max_length=32, unique=True, db_index=True) activation_timestamp = models.DateTimeField(default=None, null=True, blank=True) def register(self, user): @@ -913,7 +913,7 @@ class Registration(models.Model): self.activation_timestamp = datetime.utcnow() self.save() USER_ACCOUNT_ACTIVATED.send_robust(self.__class__, user=self.user) - log.info(u'User %s (%s) account is successfully activated.', self.user.username, self.user.email) + log.info('User %s (%s) account is successfully activated.', self.user.username, self.user.email) class PendingNameChange(DeletableByUserValue, models.Model): @@ -1807,7 +1807,7 @@ class CourseEnrollment(models.Model): enrollments = [(str(e[0]).lower(), e[1].lower()) for e in enrollments] enrollments = sorted(enrollments, key=lambda e: e[0]) hash_elements = [user.username] - hash_elements += ['{course_id}={mode}'.format(course_id=e[0], mode=e[1]) for e in enrollments] + hash_elements += [f'{e[0]}={e[1]}' for e in enrollments] status_hash = hashlib.md5('&'.join(hash_elements).encode('utf-8')).hexdigest() # The hash is cached indefinitely. It will be invalidated when the user enrolls/unenrolls. diff --git a/common/djangoapps/student/tests/test_models.py b/common/djangoapps/student/tests/test_models.py index b9b553147b..b514b27539 100644 --- a/common/djangoapps/student/tests/test_models.py +++ b/common/djangoapps/student/tests/test_models.py @@ -1,9 +1,9 @@ # lint-amnesty, pylint: disable=missing-module-docstring import datetime import hashlib +from unittest import mock import ddt -import mock import pytz from crum import set_current_request from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user @@ -98,7 +98,7 @@ class CourseEnrollmentTests(SharedModuleStoreTestCase): # lint-amnesty, pylint: enrollments = CourseEnrollment.enrollments_for_user(self.user).order_by(Lower('course_id')) hash_elements = [self.user.username] hash_elements += [ - '{course_id}={mode}'.format(course_id=str(enrollment.course_id).lower(), mode=enrollment.mode.lower()) for + f'{str(enrollment.course_id).lower()}={enrollment.mode.lower()}' for enrollment in enrollments] expected = hashlib.md5('&'.join(hash_elements).encode('utf-8')).hexdigest() assert CourseEnrollment.generate_enrollment_status_hash(self.user) == expected diff --git a/common/djangoapps/student/tests/test_refunds.py b/common/djangoapps/student/tests/test_refunds.py index 6ecf47d397..aa100ef2ad 100644 --- a/common/djangoapps/student/tests/test_refunds.py +++ b/common/djangoapps/student/tests/test_refunds.py @@ -197,7 +197,7 @@ class RefundableTest(SharedModuleStoreTestCase): """ Order with mutiple refunds will not throw 500 error when dashboard page will access.""" now = datetime.now(pytz.UTC).replace(microsecond=0) order_date = now + timedelta(days=1) - expected_content = '{{"date_placed": "{date}"}}'.format(date=order_date.strftime(ECOMMERCE_DATE_FORMAT)) + expected_content = f'{{"date_placed": "{order_date.strftime(ECOMMERCE_DATE_FORMAT)}"}}' httpretty.register_uri( httpretty.GET, diff --git a/common/djangoapps/student/tests/test_verification_status.py b/common/djangoapps/student/tests/test_verification_status.py index f03ae609ee..5ba896f508 100644 --- a/common/djangoapps/student/tests/test_verification_status.py +++ b/common/djangoapps/student/tests/test_verification_status.py @@ -388,7 +388,7 @@ class TestCourseVerificationStatus(UrlResetMixin, ModuleStoreTestCase): # Verify that the correct banner color is rendered self.assertContains( response, - "