diff --git a/lms/djangoapps/course_wiki/editors.py b/lms/djangoapps/course_wiki/editors.py index 33f878f2fd..83de77179c 100644 --- a/lms/djangoapps/course_wiki/editors.py +++ b/lms/djangoapps/course_wiki/editors.py @@ -27,7 +27,7 @@ class CodeMirrorWidget(forms.Widget): } if attrs: default_attrs.update(attrs) - super(CodeMirrorWidget, self).__init__(default_attrs) # lint-amnesty, pylint: disable=super-with-arguments + super().__init__(default_attrs) def render(self, name, value, attrs=None, renderer=None): if value is None: @@ -57,7 +57,7 @@ class CodeMirror(BaseEditor): def get_widget(self, instance=None): # lint-amnesty, pylint: disable=unused-argument return CodeMirrorWidget() - class AdminMedia(object): # pylint: disable=missing-class-docstring + class AdminMedia: # pylint: disable=missing-class-docstring css = { 'all': ("wiki/markitup/skins/simple/style.css", "wiki/markitup/sets/admin/style.css",) @@ -67,7 +67,7 @@ class CodeMirror(BaseEditor): "wiki/markitup/sets/admin/set.js", ) - class Media(object): + class Media: css = { 'all': ("js/vendor/CodeMirror/codemirror.css",) } diff --git a/lms/djangoapps/course_wiki/middleware.py b/lms/djangoapps/course_wiki/middleware.py index fd37146ee3..4a04f3cd9d 100644 --- a/lms/djangoapps/course_wiki/middleware.py +++ b/lms/djangoapps/course_wiki/middleware.py @@ -1,13 +1,12 @@ """Middleware for course_wiki""" +from urllib.parse import urlparse from django.conf import settings from django.core.exceptions import PermissionDenied from django.http import Http404 from django.shortcuts import redirect from django.utils.deprecation import MiddlewareMixin -from six import text_type -from six.moves.urllib.parse import urlparse from wiki.models import reverse from lms.djangoapps.courseware.access import has_access @@ -35,7 +34,7 @@ class WikiAccessMiddleware(MiddlewareMixin): # See if we are able to view the course. If we are, redirect to it try: get_course_overview_with_access(request.user, 'load', course_id) - return redirect("/courses/{course_id}/wiki/{path}".format(course_id=text_type(course_id), path=wiki_path)) # lint-amnesty, pylint: disable=line-too-long + return redirect("/courses/{course_id}/wiki/{path}".format(course_id=str(course_id), path=wiki_path)) # lint-amnesty, pylint: disable=line-too-long except Http404: # Even though we came from the course, we can't see it. So don't worry about it. pass @@ -58,7 +57,7 @@ class WikiAccessMiddleware(MiddlewareMixin): if course_id: # This is a /courses/org/name/run/wiki request - course_path = "/courses/{}".format(text_type(course_id)) + course_path = "/courses/{}".format(str(course_id)) # HACK: django-wiki monkeypatches the reverse function to enable # urls to be rewritten reverse._transform_url = lambda url: course_path + url # pylint: disable=protected-access @@ -71,7 +70,7 @@ class WikiAccessMiddleware(MiddlewareMixin): # clearing the referrer will cause process_response not to redirect # back to a non-existent course request.META['HTTP_REFERER'] = '' - return redirect('/wiki/{}'.format(wiki_path)) + return redirect(f'/wiki/{wiki_path}') if not course.allow_public_wiki_access: is_enrolled = CourseEnrollment.is_enrolled(request.user, course.id) @@ -79,10 +78,10 @@ class WikiAccessMiddleware(MiddlewareMixin): if not (is_enrolled or is_staff): # if a user is logged in, but not authorized to see a page, # we'll redirect them to the course about page - return redirect('about_course', text_type(course_id)) + return redirect('about_course', str(course_id)) # If we need enterprise data sharing consent for this course, then redirect to the form. - consent_url = get_enterprise_consent_url(request, text_type(course_id)) + consent_url = get_enterprise_consent_url(request, str(course_id)) if consent_url: return redirect(consent_url) diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py index 701bea8316..74533ab25c 100755 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_video.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # TODO: Is this file still used? If so it should be refactored and tests added. # pylint: disable=line-too-long, invalid-name -u""" +""" Embeds web videos using URLs. For instance, if a URL to an youtube video is found in the text submitted to markdown and it isn't enclosed in parenthesis like a normal link in markdown, then the URL will be swapped with a embedded @@ -164,7 +164,7 @@ class VideoExtension(markdown.Extension): # lint-amnesty, pylint: disable=missi } # Override defaults with user settings - super(VideoExtension, self).__init__(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments + super().__init__(**kwargs) def add_inline(self, md, name, klass, re): # pylint: disable=invalid-name """Adds the inline link""" @@ -256,8 +256,7 @@ class Yahoo(markdown.inlinepatterns.Pattern): # lint-amnesty, pylint: disable=m obj = flash_object(url, width, height) param = etree.Element('param') param.set('name', 'flashVars') - param.set('value', "id=%s&vid=%s" % (m.group('yahooid'), - m.group('yahoovid'))) + param.set('value', "id={}&vid={}".format(m.group('yahooid'), m.group('yahoovid'))) obj.append(param) return obj diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py index e1dc0c188e..139566864f 100644 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # lint-amnesty, pylint: disable=missing-module-docstring - - +# lint-amnesty, pylint: disable=missing-module-docstring from wiki.core.plugins import registry as plugin_registry from wiki.core.plugins.base import BasePlugin diff --git a/lms/djangoapps/course_wiki/tab.py b/lms/djangoapps/course_wiki/tab.py index 8a970ec995..17d06a680e 100644 --- a/lms/djangoapps/course_wiki/tab.py +++ b/lms/djangoapps/course_wiki/tab.py @@ -30,4 +30,4 @@ class WikiTab(EnrolledTab): return False if course.allow_public_wiki_access: return True - return super(WikiTab, cls).is_enabled(course, user=user) + return super().is_enabled(course, user=user) diff --git a/lms/djangoapps/course_wiki/tests/test_access.py b/lms/djangoapps/course_wiki/tests/test_access.py index 1b9e52787a..6647fe158d 100644 --- a/lms/djangoapps/course_wiki/tests/test_access.py +++ b/lms/djangoapps/course_wiki/tests/test_access.py @@ -18,7 +18,7 @@ from xmodule.modulestore.tests.factories import CourseFactory class TestWikiAccessBase(ModuleStoreTestCase): """Base class for testing wiki access.""" def setUp(self): - super(TestWikiAccessBase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.wiki = get_or_create_root() @@ -54,7 +54,7 @@ class TestWikiAccessBase(ModuleStoreTestCase): class TestWikiAccess(TestWikiAccessBase): """Test wiki access for course staff.""" def setUp(self): - super(TestWikiAccess, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.course_310b = CourseFactory.create(org='org', number='310b', display_name='Course') self.course_310b_staff = self.create_staff_for_course(self.course_310b) @@ -114,7 +114,7 @@ class TestWikiAccess(TestWikiAccessBase): class TestWikiAccessForStudent(TestWikiAccessBase): """Test access for students.""" def setUp(self): - super(TestWikiAccessForStudent, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.student = UserFactory.create() @@ -129,7 +129,7 @@ class TestWikiAccessForStudent(TestWikiAccessBase): class TestWikiAccessForNumericalCourseNumber(TestWikiAccessBase): """Test staff has access if course number is numerical and wiki slug has an underscore appended.""" def setUp(self): - super(TestWikiAccessForNumericalCourseNumber, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.course_200 = CourseFactory.create(org='org', number='200', display_name='Course') self.course_200_staff = self.create_staff_for_course(self.course_200) @@ -148,7 +148,7 @@ class TestWikiAccessForNumericalCourseNumber(TestWikiAccessBase): class TestWikiAccessForOldFormatCourseStaffGroups(TestWikiAccessBase): """Test staff has access if course group has old format.""" def setUp(self): - super(TestWikiAccessForOldFormatCourseStaffGroups, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.course_math101c = CourseFactory.create(org='org', number='math101c', display_name='Course') Group.objects.get_or_create(name='instructor_math101c') diff --git a/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py b/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py index a843c6d524..a6e95a18d9 100644 --- a/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py +++ b/lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py @@ -20,7 +20,7 @@ class TestComprehensiveTheming(ModuleStoreTestCase): def setUp(self): """Test setup.""" - super(TestComprehensiveTheming, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.wiki = get_or_create_root() diff --git a/lms/djangoapps/course_wiki/tests/test_middleware.py b/lms/djangoapps/course_wiki/tests/test_middleware.py index 37faa66efb..c42ac316db 100644 --- a/lms/djangoapps/course_wiki/tests/test_middleware.py +++ b/lms/djangoapps/course_wiki/tests/test_middleware.py @@ -17,7 +17,7 @@ class TestWikiAccessMiddleware(ModuleStoreTestCase): def setUp(self): """Test setup.""" - super(TestWikiAccessMiddleware, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.wiki = get_or_create_root() diff --git a/lms/djangoapps/course_wiki/tests/test_tab.py b/lms/djangoapps/course_wiki/tests/test_tab.py index 73c84f5581..5af61e5dd6 100644 --- a/lms/djangoapps/course_wiki/tests/test_tab.py +++ b/lms/djangoapps/course_wiki/tests/test_tab.py @@ -16,7 +16,7 @@ class WikiTabTestCase(ModuleStoreTestCase): """Test cases for Wiki Tab.""" def setUp(self): - super(WikiTabTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.course = CourseFactory.create() self.instructor = AdminFactory.create() self.user = UserFactory() diff --git a/lms/djangoapps/course_wiki/tests/tests.py b/lms/djangoapps/course_wiki/tests/tests.py index 2da31239a0..667c5977ee 100644 --- a/lms/djangoapps/course_wiki/tests/tests.py +++ b/lms/djangoapps/course_wiki/tests/tests.py @@ -3,10 +3,8 @@ Tests for course wiki """ -import six +from unittest.mock import patch from django.urls import reverse -from mock import patch -from six import text_type from lms.djangoapps.courseware.tests.tests import LoginEnrollmentTestCase from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired @@ -20,7 +18,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas """ def setUp(self): - super(WikiRedirectTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.toy = CourseFactory.create(org='edX', course='toy', display_name='2012_Fall') # Create two accounts @@ -49,7 +47,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas self.enroll(self.toy) - referer = reverse("progress", kwargs={'course_id': text_type(self.toy.id)}) + referer = reverse("progress", kwargs={'course_id': str(self.toy.id)}) destination = reverse("wiki:get", kwargs={'path': 'some/fake/wiki/page/'}) redirected_to = referer.replace("progress", "wiki/some/fake/wiki/page/") @@ -78,7 +76,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas self.enroll(self.toy) - referer = reverse("progress", kwargs={'course_id': text_type(self.toy.id)}) + referer = reverse("progress", kwargs={'course_id': str(self.toy.id)}) destination = reverse("wiki:get", kwargs={'path': 'some/fake/wiki/page/'}) resp = self.client.get(destination, HTTP_REFERER=referer) @@ -90,8 +88,8 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas The user must be enrolled in the course to see the page. """ - course_wiki_home = reverse('course_wiki', kwargs={'course_id': text_type(course.id)}) - referer = reverse("progress", kwargs={'course_id': text_type(course.id)}) + course_wiki_home = reverse('course_wiki', kwargs={'course_id': str(course.id)}) + referer = reverse("progress", kwargs={'course_id': str(course.id)}) resp = self.client.get(course_wiki_home, follow=True, HTTP_REFERER=referer) @@ -103,7 +101,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas assert resp.status_code == 200 self.has_course_navigator(resp) - self.assertContains(resp, u'

{}

'.format(course.display_name_with_default)) + self.assertContains(resp, f'

{course.display_name_with_default}

') def has_course_navigator(self, resp): """ @@ -123,7 +121,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas self.create_course_page(self.toy) course_wiki_page = reverse('wiki:get', kwargs={'path': self.toy.wiki_slug + '/'}) - referer = reverse("courseware", kwargs={'course_id': text_type(self.toy.id)}) + referer = reverse("courseware", kwargs={'course_id': str(self.toy.id)}) resp = self.client.get(course_wiki_page, follow=True, HTTP_REFERER=referer) @@ -143,7 +141,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas self.login(self.student, self.password) course_wiki_page = reverse('wiki:get', kwargs={'path': self.toy.wiki_slug + '/'}) - referer = reverse("courseware", kwargs={'course_id': text_type(self.toy.id)}) + referer = reverse("courseware", kwargs={'course_id': str(self.toy.id)}) # When not enrolled, we should get a 302 resp = self.client.get(course_wiki_page, follow=False, HTTP_REFERER=referer) @@ -152,7 +150,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas # and end up at the course about page resp = self.client.get(course_wiki_page, follow=True, HTTP_REFERER=referer) target_url, __ = resp.redirect_chain[-1] - assert target_url.endswith(reverse('about_course', args=[text_type(self.toy.id)])) + assert target_url.endswith(reverse('about_course', args=[str(self.toy.id)])) @patch.dict("django.conf.settings.FEATURES", {'ALLOW_WIKI_ROOT_ACCESS': True}) def test_redirect_when_not_logged_in(self): @@ -185,9 +183,9 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas course = 'a-very-long-course-name' display_name = 'very-long-display-name' # This is how wiki_slug is generated in cms/djangoapps/contentstore/views/course.py. - wiki_slug = "{0}.{1}.{2}".format(org, course, display_name) + wiki_slug = f"{org}.{course}.{display_name}" - assert len(((org + course) + display_name)) == 65 + assert len((org + course) + display_name) == 65 # sanity check course = CourseFactory.create(org=org, course=course, display_name=display_name, wiki_slug=wiki_slug) @@ -197,7 +195,7 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas self.create_course_page(course) course_wiki_page = reverse('wiki:get', kwargs={'path': course.wiki_slug + '/'}) - referer = reverse("courseware", kwargs={'course_id': text_type(course.id)}) + referer = reverse("courseware", kwargs={'course_id': str(course.id)}) resp = self.client.get(course_wiki_page, follow=True, HTTP_REFERER=referer) assert resp.status_code == 200 @@ -218,12 +216,12 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas # However, for private wikis, enrolled users must pass through the consent gate # (Unenrolled users are redirected to course/about) - course_id = six.text_type(course.id) + course_id = str(course.id) self.login(self.student, self.password) self.enroll(course) for (url, status_code) in ( (reverse('course_wiki', kwargs={'course_id': course_id}), 302), - ('/courses/{}/wiki/'.format(course_id), 200), + (f'/courses/{course_id}/wiki/', 200), ): self.verify_consent_required(self.client, url, status_code=status_code) # lint-amnesty, pylint: disable=no-value-for-parameter diff --git a/lms/djangoapps/course_wiki/views.py b/lms/djangoapps/course_wiki/views.py index c824e854e9..0236b1a932 100644 --- a/lms/djangoapps/course_wiki/views.py +++ b/lms/djangoapps/course_wiki/views.py @@ -77,7 +77,7 @@ def course_wiki_redirect(request, course_id, wiki_path=""): content = Text( # Translators: this string includes wiki markup. Leave the ** and the _ alone. - _(u"This is the wiki for **{organization}**'s _{course_name}_.") + _("This is the wiki for **{organization}**'s _{course_name}_.") ).format( organization=course.display_org_with_default, course_name=course.display_name_with_default, @@ -115,7 +115,7 @@ def get_or_create_root(): pass starting_content = "\n".join(( - _(u"Welcome to the {platform_name} Wiki").format( + _("Welcome to the {platform_name} Wiki").format( platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), ), "===", diff --git a/lms/djangoapps/coursewarehistoryextended/apps.py b/lms/djangoapps/coursewarehistoryextended/apps.py index 2491566ce7..56592bae49 100644 --- a/lms/djangoapps/coursewarehistoryextended/apps.py +++ b/lms/djangoapps/coursewarehistoryextended/apps.py @@ -3,4 +3,4 @@ from django.apps import AppConfig class CoursewareHistoryExtendedConfig(AppConfig): - name = u'lms.djangoapps.coursewarehistoryextended' + name = 'lms.djangoapps.coursewarehistoryextended' diff --git a/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py b/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py index 353f04a338..12687dd7aa 100644 --- a/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py +++ b/lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import datetime from django.db import migrations, models diff --git a/lms/djangoapps/coursewarehistoryextended/migrations/0002_force_studentmodule_index.py b/lms/djangoapps/coursewarehistoryextended/migrations/0002_force_studentmodule_index.py index 6580482016..0470b37d4a 100644 --- a/lms/djangoapps/coursewarehistoryextended/migrations/0002_force_studentmodule_index.py +++ b/lms/djangoapps/coursewarehistoryextended/migrations/0002_force_studentmodule_index.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - - - from django.db import migrations, models @@ -14,6 +10,6 @@ class Migration(migrations.Migration): operations = [ migrations.AlterIndexTogether( name='studentmodulehistoryextended', - index_together=set([('student_module',)]), + index_together={('student_module',)}, ), ] diff --git a/lms/djangoapps/coursewarehistoryextended/models.py b/lms/djangoapps/coursewarehistoryextended/models.py index e9ca7e25f2..59d1002b40 100644 --- a/lms/djangoapps/coursewarehistoryextended/models.py +++ b/lms/djangoapps/coursewarehistoryextended/models.py @@ -14,17 +14,14 @@ ASSUMPTIONS: modules have unique IDs, even across different module_types """ -import six from django.db import models from django.db.models.signals import post_delete, post_save from django.dispatch import receiver -from django.utils.encoding import python_2_unicode_compatible from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField -@python_2_unicode_compatible class StudentModuleHistoryExtended(BaseStudentModuleHistory): """Keeps a complete history of state changes for a given XModule for a given Student. Right now, we restrict this to problems so that the table doesn't @@ -33,7 +30,7 @@ class StudentModuleHistoryExtended(BaseStudentModuleHistory): This new extended CSMH has a larger primary key that won't run out of space so quickly.""" - class Meta(object): + class Meta: app_label = 'coursewarehistoryextended' get_latest_by = "created" index_together = ['student_module'] @@ -67,4 +64,4 @@ class StudentModuleHistoryExtended(BaseStudentModuleHistory): StudentModuleHistoryExtended.objects.filter(student_module=instance).all().delete() def __str__(self): - return six.text_type(repr(self)) + return str(repr(self)) diff --git a/lms/djangoapps/coursewarehistoryextended/tests.py b/lms/djangoapps/coursewarehistoryextended/tests.py index dc2faecab6..a1e6fa5759 100644 --- a/lms/djangoapps/coursewarehistoryextended/tests.py +++ b/lms/djangoapps/coursewarehistoryextended/tests.py @@ -8,11 +8,11 @@ backend tables. import json from unittest import skipUnless +from unittest.mock import patch from django.conf import settings from django.db import connections from django.test import TestCase -from mock import patch from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule, StudentModuleHistory from lms.djangoapps.courseware.tests.factories import StudentModuleFactory, course_id, location @@ -25,7 +25,7 @@ class TestStudentModuleHistoryBackends(TestCase): databases = {alias for alias in connections} # lint-amnesty, pylint: disable=unnecessary-comprehension def setUp(self): - super(TestStudentModuleHistoryBackends, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() for record in (1, 2, 3): # This will store into CSMHE via the post_save signal csm = StudentModuleFactory.create(module_state_key=location('usage_id'),