refac: ran pyupgrade on lms/djangoapps/branding (#26730)
This commit is contained in:
@@ -22,8 +22,8 @@ from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
from six.moves.urllib.parse import urljoin
|
||||
|
||||
from lms.djangoapps.branding.models import BrandingApiConfig
|
||||
from common.djangoapps.edxmako.shortcuts import marketing_link
|
||||
from lms.djangoapps.branding.models import BrandingApiConfig
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
|
||||
log = logging.getLogger("edx.footer")
|
||||
@@ -126,9 +126,9 @@ def _footer_copyright():
|
||||
return _(
|
||||
# Translators: 'edX' and 'Open edX' are trademarks of 'edX Inc.'.
|
||||
# Please do not translate any of these trademarks and company names.
|
||||
u"\u00A9 {org_name}. All rights reserved except where noted. "
|
||||
u"edX, Open edX and their respective logos are "
|
||||
u"registered trademarks of edX Inc."
|
||||
"\u00A9 {org_name}. All rights reserved except where noted. "
|
||||
"edX, Open edX and their respective logos are "
|
||||
"registered trademarks of edX Inc."
|
||||
).format(org_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME))
|
||||
|
||||
|
||||
@@ -165,10 +165,10 @@ def _footer_social_links():
|
||||
links.append(
|
||||
{
|
||||
"name": social_name,
|
||||
"title": six.text_type(display.get("title", "")),
|
||||
"title": str(display.get("title", "")),
|
||||
"url": settings.SOCIAL_MEDIA_FOOTER_URLS.get(social_name, "#"),
|
||||
"icon-class": display.get("icon", ""),
|
||||
"action": six.text_type(display.get("action", "")).format(platform_name=platform_name),
|
||||
"action": str(display.get("action", "")).format(platform_name=platform_name),
|
||||
}
|
||||
)
|
||||
return links
|
||||
@@ -215,7 +215,7 @@ def _build_support_form_url(full_path=False):
|
||||
|
||||
# Prepend with lms base_url if specified by `full_path`
|
||||
if full_path:
|
||||
contact_us_page = '{}{}'.format(settings.LMS_ROOT_URL, contact_us_page)
|
||||
contact_us_page = f'{settings.LMS_ROOT_URL}{contact_us_page}'
|
||||
|
||||
return contact_us_page
|
||||
|
||||
@@ -277,7 +277,7 @@ def _footer_navigation_links(language=settings.LANGUAGE_CODE):
|
||||
("about", (marketing_link("ABOUT"), _("About"))),
|
||||
("enterprise", (
|
||||
marketing_link("ENTERPRISE"),
|
||||
_(u"{platform_name} for Business").format(platform_name=platform_name)
|
||||
_("{platform_name} for Business").format(platform_name=platform_name)
|
||||
)),
|
||||
("blog", (marketing_link("BLOG"), _("Blog"))),
|
||||
("help-center", (_build_help_center_url(language), _("Help Center"))),
|
||||
@@ -353,7 +353,7 @@ def _footer_business_links(language=settings.LANGUAGE_CODE):
|
||||
("about", (marketing_link("ABOUT"), _("About"))),
|
||||
("enterprise", (
|
||||
_add_enterprise_marketing_footer_query_params(marketing_link("ENTERPRISE")),
|
||||
_(u"{platform_name} for Business").format(platform_name=platform_name)
|
||||
_("{platform_name} for Business").format(platform_name=platform_name)
|
||||
)),
|
||||
]
|
||||
|
||||
@@ -424,7 +424,7 @@ def _footer_mobile_links(is_secure):
|
||||
{
|
||||
"name": "apple",
|
||||
"title": _(
|
||||
u"Download the {platform_name} mobile app from the Apple App Store"
|
||||
"Download the {platform_name} mobile app from the Apple App Store"
|
||||
).format(platform_name=platform_name),
|
||||
"url": settings.MOBILE_STORE_URLS.get('apple', '#'),
|
||||
"image": _absolute_url_staticfile(is_secure, 'images/app/app_store_badge_135x40.svg'),
|
||||
@@ -432,7 +432,7 @@ def _footer_mobile_links(is_secure):
|
||||
{
|
||||
"name": "google",
|
||||
"title": _(
|
||||
u"Download the {platform_name} mobile app from Google Play"
|
||||
"Download the {platform_name} mobile app from Google Play"
|
||||
).format(platform_name=platform_name),
|
||||
"url": settings.MOBILE_STORE_URLS.get('google', '#'),
|
||||
"image": _absolute_url_staticfile(is_secure, 'images/app/google_play_badge_45.png'),
|
||||
@@ -586,7 +586,7 @@ def get_logo_url(is_secure=True):
|
||||
return _absolute_url_staticfile(is_secure=is_secure, name=logo_url_from_site_config)
|
||||
|
||||
if university:
|
||||
return staticfiles_storage.url('images/{uni}-on-edx-logo.png'.format(uni=university))
|
||||
return staticfiles_storage.url(f'images/{university}-on-edx-logo.png')
|
||||
|
||||
if brand_logo_url:
|
||||
return brand_logo_url
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
@@ -33,7 +29,7 @@ class Migration(migrations.Migration):
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')),
|
||||
('enabled', models.BooleanField(default=False, verbose_name='Enabled')),
|
||||
('configuration', models.TextField(help_text=u'JSON data of Configuration for Video Branding.')),
|
||||
('configuration', models.TextField(help_text='JSON data of Configuration for Video Branding.')),
|
||||
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
|
||||
],
|
||||
options={
|
||||
|
||||
@@ -33,7 +33,7 @@ class BrandingInfoConfig(ConfigurationModel):
|
||||
app_label = "branding"
|
||||
|
||||
configuration = TextField(
|
||||
help_text=u"JSON data of Configuration for Video Branding."
|
||||
help_text="JSON data of Configuration for Video Branding."
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
# encoding: utf-8
|
||||
"""Tests of Branding API """
|
||||
|
||||
|
||||
import mock
|
||||
from unittest import mock
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration
|
||||
|
||||
from ..api import _footer_business_links, get_footer, get_home_url, get_logo_url
|
||||
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration # lint-amnesty, pylint: disable=wrong-import-order
|
||||
|
||||
test_config_disabled_contact_us = { # pylint: disable=invalid-name
|
||||
"CONTACT_US_ENABLE": False,
|
||||
@@ -123,7 +124,7 @@ class TestFooter(TestCase):
|
||||
'connect_links': [
|
||||
{'url': 'https://edx.org/edx-blog', 'name': 'blog', 'title': 'Blog'},
|
||||
# pylint: disable=line-too-long
|
||||
{'url': '{base_url}/support/contact_us'.format(base_url=settings.LMS_ROOT_URL), 'name': 'contact', 'title': 'Contact Us'},
|
||||
{'url': f'{settings.LMS_ROOT_URL}/support/contact_us', 'name': 'contact', 'title': 'Contact Us'},
|
||||
{'url': 'https://example.support.edx.org/hc/en-us', 'name': 'help-center', 'title': 'Help Center'},
|
||||
{'url': 'https://edx.org/media-kit', 'name': 'media_kit', 'title': 'Media Kit'},
|
||||
{'url': 'https://edx.org/donate', 'name': 'donate', 'title': 'Donate'}
|
||||
@@ -138,8 +139,8 @@ class TestFooter(TestCase):
|
||||
'title': 'Accessibility Policy'},
|
||||
{'url': 'https://edx.org/sitemap', 'name': 'sitemap', 'title': 'Sitemap'},
|
||||
{'name': 'media_kit',
|
||||
'title': u'Media Kit',
|
||||
'url': u'https://edx.org/media-kit'}
|
||||
'title': 'Media Kit',
|
||||
'url': 'https://edx.org/media-kit'}
|
||||
],
|
||||
'social_links': [
|
||||
{'url': '#', 'action': 'Like \xe9dX on Facebook', 'name': 'facebook',
|
||||
|
||||
@@ -15,7 +15,7 @@ class BrandingInfoConfigTest(TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(BrandingInfoConfigTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.configuration_string = """{
|
||||
"CN": {
|
||||
"url": "http://www.xuetangx.com",
|
||||
|
||||
@@ -4,8 +4,8 @@ Tests for branding page
|
||||
|
||||
|
||||
import datetime
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.http import HttpResponseRedirect
|
||||
@@ -13,14 +13,13 @@ from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from milestones.tests.utils import MilestonesTestCaseMixin
|
||||
from mock import Mock, patch
|
||||
from pytz import UTC
|
||||
|
||||
from common.djangoapps.edxmako.shortcuts import render_to_response
|
||||
from common.djangoapps.util.milestones_helpers import set_prerequisite_courses
|
||||
from lms.djangoapps.branding.views import index
|
||||
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase
|
||||
from common.djangoapps.edxmako.shortcuts import render_to_response
|
||||
from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
|
||||
from common.djangoapps.util.milestones_helpers import set_prerequisite_courses
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
@@ -44,7 +43,7 @@ class AnonymousIndexPageTest(ModuleStoreTestCase):
|
||||
Tests that anonymous users can access the '/' page, Need courses with start date
|
||||
"""
|
||||
def setUp(self):
|
||||
super(AnonymousIndexPageTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.factory = RequestFactory()
|
||||
self.course = CourseFactory.create(
|
||||
days_early_for_beta=5,
|
||||
@@ -130,7 +129,7 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase, Mi
|
||||
emit_signals=True,
|
||||
)
|
||||
|
||||
pre_requisite_courses = [six.text_type(pre_requisite_course.id)]
|
||||
pre_requisite_courses = [str(pre_requisite_course.id)]
|
||||
|
||||
# for this failure to occur, the enrollment window needs to be in the past
|
||||
course = CourseFactory.create(
|
||||
@@ -161,7 +160,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase):
|
||||
ENABLED_SIGNALS = ['course_published']
|
||||
|
||||
def setUp(self):
|
||||
super(IndexPageCourseCardsSortingTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.starting_later = CourseFactory.create(
|
||||
org='MITx',
|
||||
number='1000',
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
# encoding: utf-8
|
||||
"""Tests of Branding API views. """
|
||||
|
||||
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from lms.djangoapps.branding.models import BrandingApiConfig
|
||||
from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
|
||||
from openedx.core.djangoapps.lang_pref.api import released_languages
|
||||
from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
|
||||
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@@ -127,7 +126,7 @@ class TestFooter(CacheIsolationTestCase):
|
||||
|
||||
@ddt.data(
|
||||
("en", "registered trademarks"),
|
||||
("eo", u"régïstéréd trädémärks"), # Dummy language string
|
||||
("eo", "régïstéréd trädémärks"), # Dummy language string
|
||||
("unknown", "registered trademarks"), # default to English
|
||||
)
|
||||
@ddt.unpack
|
||||
@@ -250,7 +249,7 @@ class TestFooter(CacheIsolationTestCase):
|
||||
url = reverse("branding_footer")
|
||||
|
||||
if params is not None:
|
||||
url = u"{url}?{params}".format(
|
||||
url = "{url}?{params}".format(
|
||||
url=url,
|
||||
params=six.moves.urllib.parse.urlencode(params)
|
||||
)
|
||||
@@ -264,13 +263,13 @@ class TestFooter(CacheIsolationTestCase):
|
||||
assert 'footer-language-selector' in content
|
||||
|
||||
# Verify the correct language is selected
|
||||
assert u'<option value="{}" selected="selected">'.format(selected_language) in content
|
||||
assert f'<option value="{selected_language}" selected="selected">' in content
|
||||
|
||||
# Verify the language choices
|
||||
for language in released_languages():
|
||||
if language.code == selected_language:
|
||||
continue
|
||||
assert u'<option value="{}">'.format(language.code) in content
|
||||
assert f'<option value="{language.code}">' in content
|
||||
|
||||
|
||||
class TestIndex(SiteMixin, TestCase):
|
||||
@@ -278,7 +277,7 @@ class TestIndex(SiteMixin, TestCase):
|
||||
|
||||
def setUp(self):
|
||||
""" Set up a user """
|
||||
super(TestIndex, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
|
||||
patcher = mock.patch("common.djangoapps.student.models.tracker")
|
||||
self.mock_tracker = patcher.start()
|
||||
|
||||
@@ -18,12 +18,12 @@ from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
|
||||
import lms.djangoapps.branding.api as branding_api
|
||||
import lms.djangoapps.courseware.views.views as courseware_views
|
||||
from common.djangoapps.student import views as student_views
|
||||
from common.djangoapps.edxmako.shortcuts import marketing_link, render_to_response
|
||||
from openedx.core.djangoapps.lang_pref.api import released_languages
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from common.djangoapps.student import views as student_views
|
||||
from common.djangoapps.util.cache import cache_if_anonymous
|
||||
from common.djangoapps.util.json_request import JsonResponse
|
||||
from openedx.core.djangoapps.lang_pref.api import released_languages
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -71,11 +71,11 @@ def index(request):
|
||||
return student_views.index(request, user=request.user)
|
||||
except NoReverseMatch:
|
||||
log.error(
|
||||
'https is not a registered namespace Request from {}'.format(domain),
|
||||
'request_site= {}'.format(request.site.__dict__),
|
||||
'enable_mktg_site= {}'.format(enable_mktg_site),
|
||||
'Auth Status= {}'.format(request.user.is_authenticated),
|
||||
'Request Meta= {}'.format(request.META)
|
||||
f'https is not a registered namespace Request from {domain}',
|
||||
f'request_site= {request.site.__dict__}',
|
||||
f'enable_mktg_site= {enable_mktg_site}',
|
||||
f'Auth Status= {request.user.is_authenticated}',
|
||||
f'Request Meta= {request.META}'
|
||||
)
|
||||
raise
|
||||
|
||||
@@ -286,7 +286,7 @@ def footer(request):
|
||||
}
|
||||
if include_language_selector:
|
||||
cache_params['language_selector_options'] = ','.join(sorted([lang.code for lang in released_languages()]))
|
||||
cache_key = u"branding.footer.{params}.html".format(params=six.moves.urllib.parse.urlencode(cache_params))
|
||||
cache_key = "branding.footer.{params}.html".format(params=six.moves.urllib.parse.urlencode(cache_params))
|
||||
|
||||
content = cache.get(cache_key)
|
||||
if content is None:
|
||||
@@ -298,7 +298,7 @@ def footer(request):
|
||||
return HttpResponse(content, status=200, content_type="text/html; charset=utf-8")
|
||||
|
||||
elif 'application/json' in accepts:
|
||||
cache_key = u"branding.footer.{params}.json".format(
|
||||
cache_key = "branding.footer.{params}.json".format(
|
||||
params=six.moves.urllib.parse.urlencode({
|
||||
'language': language,
|
||||
'is_secure': request.is_secure(),
|
||||
|
||||
Reference in New Issue
Block a user