* run python modernize

* run isort

* Fix imports
This commit is contained in:
Stu Young
2019-05-16 14:37:44 -04:00
committed by Douglas Hall
parent c0e3ab8e15
commit 175c3c6d03
11 changed files with 40 additions and 28 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -2,6 +2,8 @@
Branding API endpoint urls.
"""
from __future__ import absolute_import
from django.conf.urls import url
from branding.views import footer

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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(

View File

@@ -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)

View File

@@ -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(),
})