refactor: ran pyupgrade on lms/djangoapps (#26523)
ran pyupgrade on course_Wiki, coursewarehistoryextended
This commit is contained in:
@@ -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",)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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'<h3 class="entry-title">{}</h3>'.format(course.display_name_with_default))
|
||||
self.assertContains(resp, f'<h3 class="entry-title">{course.display_name_with_default}</h3>')
|
||||
|
||||
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
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
"===",
|
||||
|
||||
@@ -3,4 +3,4 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoursewareHistoryExtendedConfig(AppConfig):
|
||||
name = u'lms.djangoapps.coursewarehistoryextended'
|
||||
name = 'lms.djangoapps.coursewarehistoryextended'
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -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',)},
|
||||
),
|
||||
]
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user