diff --git a/lms/djangoapps/branding/__init__.py b/lms/djangoapps/branding/__init__.py index e467d96ef4..21725f3322 100644 --- a/lms/djangoapps/branding/__init__.py +++ b/lms/djangoapps/branding/__init__.py @@ -7,9 +7,11 @@ This module provides functions to retrieve basic branded parts such as the site visible courses, university name and logo. """ -from django.conf import settings +from __future__ import absolute_import +from django.conf import settings from opaque_keys.edx.keys import CourseKey + from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/lms/djangoapps/branding/admin.py b/lms/djangoapps/branding/admin.py index 851f57eca5..8bd6e28dba 100644 --- a/lms/djangoapps/branding/admin.py +++ b/lms/djangoapps/branding/admin.py @@ -1,4 +1,6 @@ """Django admin pages for branding configuration. """ +from __future__ import absolute_import + from config_models.admin import ConfigurationModelAdmin from django.contrib import admin diff --git a/lms/djangoapps/branding/api.py b/lms/djangoapps/branding/api.py index 4309f048e3..3b0dd63a2f 100644 --- a/lms/djangoapps/branding/api.py +++ b/lms/djangoapps/branding/api.py @@ -12,8 +12,11 @@ are consistent across the LMS and other sites (such as the marketing site and blog). """ +from __future__ import absolute_import + import logging +import six from django.conf import settings from django.contrib.staticfiles.storage import staticfiles_storage from django.urls import reverse @@ -23,12 +26,6 @@ from branding.models import BrandingApiConfig from edxmako.shortcuts import marketing_link from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -try: - from urllib import urlencode - import urlparse -except ImportError: - from urllib.parse import urlencode # pylint: disable=ungrouped-imports - import urllib.parse as urlparse log = logging.getLogger("edx.footer") EMPTY_URL = '#' @@ -166,10 +163,10 @@ def _footer_social_links(): links.append( { "name": social_name, - "title": unicode(display.get("title", "")), + "title": six.text_type(display.get("title", "")), "url": settings.SOCIAL_MEDIA_FOOTER_URLS.get(social_name, "#"), "icon-class": display.get("icon", ""), - "action": unicode(display.get("action", "")).format(platform_name=platform_name), + "action": six.text_type(display.get("action", "")).format(platform_name=platform_name), } ) return links @@ -322,7 +319,7 @@ def _add_enterprise_marketing_footer_query_params(url): if params: return "{url}/?{params}".format( url=url, - params=urlencode(params), + params=six.moves.urllib.parse.urlencode(params), ) return url @@ -475,7 +472,7 @@ def _absolute_url(is_secure, url_path): """ site_name = configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME) parts = ("https" if is_secure else "http", site_name, url_path, '', '', '') - return urlparse.urlunparse(parts) + return six.moves.urllib.parse.urlunparse(parts) # pylint: disable=too-many-function-args def _absolute_url_staticfile(is_secure, name): @@ -494,7 +491,7 @@ def _absolute_url_staticfile(is_secure, name): # In production, the static files URL will be an absolute # URL pointing to a CDN. If this happens, we can just # return the URL. - if urlparse.urlparse(url_path).netloc: + if six.moves.urllib.parse.urlparse(url_path).netloc: return url_path # For local development, the returned URL will be relative, diff --git a/lms/djangoapps/branding/api_urls.py b/lms/djangoapps/branding/api_urls.py index 83044bcca3..e2f492c23e 100644 --- a/lms/djangoapps/branding/api_urls.py +++ b/lms/djangoapps/branding/api_urls.py @@ -2,6 +2,8 @@ Branding API endpoint urls. """ +from __future__ import absolute_import + from django.conf.urls import url from branding.views import footer diff --git a/lms/djangoapps/branding/migrations/0001_initial.py b/lms/djangoapps/branding/migrations/0001_initial.py index 7b2b9d8362..3ec2ec5684 100644 --- a/lms/djangoapps/branding/migrations/0001_initial.py +++ b/lms/djangoapps/branding/migrations/0001_initial.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +from __future__ import absolute_import from django.db import migrations, models import django.db.models.deletion from django.conf import settings diff --git a/lms/djangoapps/branding/models.py b/lms/djangoapps/branding/models.py index 26607c3918..5bb1a70743 100644 --- a/lms/djangoapps/branding/models.py +++ b/lms/djangoapps/branding/models.py @@ -5,6 +5,8 @@ Includes: BrandingInfoConfig: A ConfigurationModel for managing how Video Module will use Branding. """ +from __future__ import absolute_import + import json from config_models.models import ConfigurationModel diff --git a/lms/djangoapps/branding/tests/test_api.py b/lms/djangoapps/branding/tests/test_api.py index 1cea4e9980..1a9f49055b 100644 --- a/lms/djangoapps/branding/tests/test_api.py +++ b/lms/djangoapps/branding/tests/test_api.py @@ -1,19 +1,16 @@ # encoding: utf-8 """Tests of Branding API """ -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals import mock from django.conf import settings -from django.urls import reverse from django.test import TestCase from django.test.utils import override_settings +from django.urls import reverse from branding.api import _footer_business_links, get_footer, get_home_url, get_logo_url from edxmako.shortcuts import marketing_link - -from openedx.core.djangoapps.site_configuration.tests.test_util import ( - with_site_configuration, -) +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration test_config_disabled_contact_us = { # pylint: disable=invalid-name "CONTACT_US_ENABLE": False, diff --git a/lms/djangoapps/branding/tests/test_models.py b/lms/djangoapps/branding/tests/test_models.py index ee7499cb31..b0b1c30ef5 100644 --- a/lms/djangoapps/branding/tests/test_models.py +++ b/lms/djangoapps/branding/tests/test_models.py @@ -1,6 +1,8 @@ """ Tests for the Video Branding configuration. """ +from __future__ import absolute_import + from django.core.exceptions import ValidationError from django.test import TestCase diff --git a/lms/djangoapps/branding/tests/test_page.py b/lms/djangoapps/branding/tests/test_page.py index 0d826ab4a0..164dce826e 100644 --- a/lms/djangoapps/branding/tests/test_page.py +++ b/lms/djangoapps/branding/tests/test_page.py @@ -1,14 +1,17 @@ """ Tests for branding page """ +from __future__ import absolute_import + import datetime +import six from django.conf import settings from django.contrib.auth.models import AnonymousUser -from django.urls import reverse from django.http import HttpResponseRedirect 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 @@ -127,7 +130,7 @@ class PreRequisiteCourseCatalog(ModuleStoreTestCase, LoginEnrollmentTestCase, Mi emit_signals=True, ) - pre_requisite_courses = [unicode(pre_requisite_course.id)] + pre_requisite_courses = [six.text_type(pre_requisite_course.id)] # for this failure to occur, the enrollment window needs to be in the past course = CourseFactory.create( diff --git a/lms/djangoapps/branding/tests/test_views.py b/lms/djangoapps/branding/tests/test_views.py index de8f1f993d..912a523737 100644 --- a/lms/djangoapps/branding/tests/test_views.py +++ b/lms/djangoapps/branding/tests/test_views.py @@ -1,14 +1,16 @@ # encoding: utf-8 """Tests of Branding API views. """ +from __future__ import absolute_import + import json -import urllib import ddt import mock +import six from django.conf import settings from django.contrib.auth.models import User -from django.urls import reverse from django.test import TestCase +from django.urls import reverse from branding.models import BrandingApiConfig from openedx.core.djangoapps.dark_lang.models import DarkLangConfig @@ -256,7 +258,7 @@ class TestFooter(CacheIsolationTestCase): if params is not None: url = u"{url}?{params}".format( url=url, - params=urllib.urlencode(params) + params=six.moves.urllib.parse.urlencode(params) ) return self.client.get(url, HTTP_ACCEPT=accepts) diff --git a/lms/djangoapps/branding/views.py b/lms/djangoapps/branding/views.py index 67735445c1..8b6ebd1380 100644 --- a/lms/djangoapps/branding/views.py +++ b/lms/djangoapps/branding/views.py @@ -1,14 +1,16 @@ """Views for the branding app. """ -import logging -import urllib +from __future__ import absolute_import +import logging + +import six from django.conf import settings from django.contrib.staticfiles.storage import staticfiles_storage from django.core.cache import cache -from django.urls import reverse from django.db import transaction from django.http import Http404, HttpResponse from django.shortcuts import redirect +from django.urls import reverse from django.utils import translation from django.utils.translation.trans_real import get_supported_language_variant from django.views.decorators.cache import cache_control @@ -273,7 +275,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=urllib.urlencode(cache_params)) + cache_key = u"branding.footer.{params}.html".format(params=six.moves.urllib.parse.urlencode(cache_params)) content = cache.get(cache_key) if content is None: @@ -286,7 +288,7 @@ def footer(request): elif 'application/json' in accepts: cache_key = u"branding.footer.{params}.json".format( - params=urllib.urlencode({ + params=six.moves.urllib.parse.urlencode({ 'language': language, 'is_secure': request.is_secure(), })