INCR-137: Run python-modernize at common/djangoapps/static_replace (#20481)

This commit is contained in:
Amit
2019-05-09 16:36:45 +03:00
committed by Jeremy Bowman
parent d4cbcfd5d5
commit 9e2397a60a
7 changed files with 20 additions and 10 deletions

View File

@@ -1,5 +1,9 @@
from __future__ import absolute_import
import logging
import re
import six
from six import text_type
from django.contrib.staticfiles.storage import staticfiles_storage
from django.contrib.staticfiles import finders
@@ -8,7 +12,6 @@ from django.conf import settings
from xmodule.contentstore.content import StaticContent
from opaque_keys.edx.locator import AssetLocator
from six import text_type
log = logging.getLogger(__name__)
XBLOCK_STATIC_RESOURCE_PREFIX = '/static/xblock'
@@ -113,7 +116,7 @@ def process_static_urls(text, replacement_function, data_dir=None):
# works for actual static assets and for magical course asset URLs....
full_url = prefix + rest
starts_with_static_url = full_url.startswith(unicode(settings.STATIC_URL))
starts_with_static_url = full_url.startswith(six.text_type(settings.STATIC_URL))
starts_with_prefix = full_url.startswith(XBLOCK_STATIC_RESOURCE_PREFIX)
contains_prefix = XBLOCK_STATIC_RESOURCE_PREFIX in full_url
if starts_with_prefix or (starts_with_static_url and contains_prefix):

View File

@@ -2,6 +2,8 @@
Django admin page for AssetBaseUrlConfig, which allows you to set the base URL
that gets prepended to asset URLs in order to serve them from, say, a CDN.
"""
from __future__ import absolute_import
from config_models.admin import ConfigurationModelAdmin
from django.contrib import admin

View File

@@ -2,7 +2,7 @@
Django management command to clear the 'staticfiles' Django cache
"""
from __future__ import print_function
from __future__ import absolute_import, print_function
from django.core.management.base import BaseCommand
from django.core.cache import caches

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import django.db.models.deletion
from django.conf import settings

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import django.db.models.deletion
from django.conf import settings

View File

@@ -2,6 +2,11 @@
Models for static_replace
"""
from __future__ import absolute_import
import six
from six.moves import map
from config_models.models import ConfigurationModel
from django.db.models.fields import TextField
@@ -30,7 +35,7 @@ class AssetBaseUrlConfig(ConfigurationModel):
return '<AssetBaseUrlConfig(base_url={})>'.format(self.get_base_url())
def __unicode__(self):
return unicode(repr(self))
return six.text_type(repr(self))
class AssetExcludedExtensionsConfig(ConfigurationModel):
@@ -53,10 +58,10 @@ class AssetExcludedExtensionsConfig(ConfigurationModel):
def get_excluded_extensions(cls):
"""Gets the excluded file extensions when canonicalizing static asset paths"""
add_period = lambda x: '.' + x
return map(add_period, cls.current().excluded_extensions.split())
return list(map(add_period, cls.current().excluded_extensions.split()))
def __repr__(self):
return '<AssetExcludedExtensionsConfig(extensions={})>'.format(self.get_excluded_extensions())
def __unicode__(self):
return unicode(repr(self))
return six.text_type(repr(self))

View File

@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
"""Tests for static_replace"""
from __future__ import print_function
from __future__ import absolute_import, print_function
import re
from cStringIO import StringIO
from urlparse import parse_qsl, urlparse, urlunparse
from six.moves.urllib.parse import parse_qsl, urlparse, urlunparse
import ddt
import pytest