Skip to content
Snippets Groups Projects
Commit 4f6a6b57 authored by Awais Qureshi's avatar Awais Qureshi
Browse files

BOM-2375

Run Pyupgrade on static replace folder.
parent 789af8d4
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,10 @@
import logging
import re
import six
from django.conf import settings
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
from opaque_keys.edx.locator import AssetLocator
from six import text_type
from xmodule.contentstore.content import StaticContent
......@@ -39,7 +37,7 @@ def try_staticfiles_lookup(path):
try:
url = staticfiles_storage.url(path)
except Exception as err: # lint-amnesty, pylint: disable=broad-except
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
log.warning("staticfiles_storage couldn't find path {}: {}".format(
path, str(err)))
# Just return the original path; don't kill everything.
url = path
......@@ -85,7 +83,7 @@ def replace_course_urls(text, course_key):
returns: text with the links replaced
"""
course_id = text_type(course_key)
course_id = str(course_key)
def replace_course_url(match):
quote = match.group('quote')
......@@ -114,7 +112,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(six.text_type(settings.STATIC_URL))
starts_with_static_url = full_url.startswith(str(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):
......@@ -123,7 +121,7 @@ def process_static_urls(text, replacement_function, data_dir=None):
return replacement_function(original, prefix, quote, rest)
return re.sub(
_url_replace_regex(u'(?:{static_url}|/static/)(?!{data_dir})'.format(
_url_replace_regex('(?:{static_url}|/static/)(?!{data_dir})'.format(
static_url=settings.STATIC_URL,
data_dir=data_dir
)),
......@@ -192,7 +190,7 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
try:
exists_in_staticfiles_storage = staticfiles_storage.exists(rest)
except Exception as err: # lint-amnesty, pylint: disable=broad-except
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
log.warning("staticfiles_storage couldn't find path {}: {}".format(
rest, str(err)))
if exists_in_staticfiles_storage:
......@@ -220,7 +218,7 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
url = staticfiles_storage.url(course_path)
# And if that fails, assume that it's course content, and add manually data directory
except Exception as err: # lint-amnesty, pylint: disable=broad-except
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
log.warning("staticfiles_storage couldn't find path {}: {}".format(
rest, str(err)))
url = "".join([prefix, course_path])
......
......@@ -3,8 +3,8 @@ Django management command to clear the 'staticfiles' Django cache
"""
from django.core.management.base import BaseCommand
from django.core.cache import caches
from django.core.management.base import BaseCommand
class Command(BaseCommand):
......
# -*- coding: utf-8 -*-
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
......@@ -19,7 +16,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')),
('base_url', models.TextField(help_text=u'The alternative hostname to serve static assets from. Should be in the form of hostname[:port].', blank=True)),
('base_url', models.TextField(help_text='The alternative hostname to serve static assets from. Should be in the form of hostname[:port].', blank=True)),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
],
),
......
# -*- coding: utf-8 -*-
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
......@@ -20,7 +17,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')),
('excluded_extensions', models.TextField(default=u'html', help_text=u'The file extensions to exclude from canonicalization. No leading period required. Values should be space separated i.e. "html svg css"')),
('excluded_extensions', models.TextField(default='html', help_text='The file extensions to exclude from canonicalization. No leading period required. Values should be space separated i.e. "html svg css"')),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
],
),
......
......@@ -3,9 +3,6 @@ Models for static_replace
"""
import six
from six.moves import map
from config_models.models import ConfigurationModel
from django.db.models.fields import TextField
from django.utils.encoding import python_2_unicode_compatible
......@@ -19,12 +16,12 @@ class AssetBaseUrlConfig(ConfigurationModel):
.. no_pii:
"""
class Meta(object):
class Meta:
app_label = 'static_replace'
base_url = TextField(
blank=True,
help_text=u"The alternative hostname to serve static assets from. Should be in the form of hostname[:port]."
help_text="The alternative hostname to serve static assets from. Should be in the form of hostname[:port]."
)
@classmethod
......@@ -33,10 +30,10 @@ class AssetBaseUrlConfig(ConfigurationModel):
return cls.current().base_url
def __repr__(self):
return '<AssetBaseUrlConfig(base_url={})>'.format(self.get_base_url())
return f'<AssetBaseUrlConfig(base_url={self.get_base_url()})>'
def __str__(self):
return six.text_type(repr(self))
return str(repr(self))
@python_2_unicode_compatible
......@@ -47,12 +44,12 @@ class AssetExcludedExtensionsConfig(ConfigurationModel):
.. no_pii:
"""
class Meta(object):
class Meta:
app_label = 'static_replace'
excluded_extensions = TextField(
default=u'html',
help_text=u'The file extensions to exclude from canonicalization. No leading period required. ' +
default='html',
help_text='The file extensions to exclude from canonicalization. No leading period required. ' +
'Values should be space separated i.e. "html svg css"'
)
......@@ -63,7 +60,7 @@ class AssetExcludedExtensionsConfig(ConfigurationModel):
return list(map(add_period, cls.current().excluded_extensions.split()))
def __repr__(self):
return '<AssetExcludedExtensionsConfig(extensions={})>'.format(self.get_excluded_extensions())
return f'<AssetExcludedExtensionsConfig(extensions={self.get_excluded_extensions()})>'
def __str__(self):
return six.text_type(repr(self))
return str(repr(self))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment