BOM-2375
Run Pyupgrade on status folder.
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
@@ -14,6 +11,6 @@ class Migration(migrations.Migration):
|
||||
migrations.AlterField(
|
||||
model_name='globalstatusmessage',
|
||||
name='message',
|
||||
field=models.TextField(help_text=u'<p>The contents of this field will be displayed as a warning banner on all views.</p><p>To override the banner message for a specific course, refer to the Course Message configuration. Course Messages will only work if the global status message is enabled, so if you only want to add a banner to specific courses without adding a global status message, you should add a global status message with <strong>empty</strong> message text.</p><p>Finally, disable the global status message by adding another empty message with "enabled" unchecked.</p>', null=True, blank=True),
|
||||
field=models.TextField(help_text='<p>The contents of this field will be displayed as a warning banner on all views.</p><p>To override the banner message for a specific course, refer to the Course Message configuration. Course Messages will only work if the global status message is enabled, so if you only want to add a banner to specific courses without adding a global status message, you should add a global status message with <strong>empty</strong> message text.</p><p>Finally, disable the global status message by adding another empty message with "enabled" unchecked.</p>', null=True, blank=True),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -3,7 +3,6 @@ Store status messages in the database.
|
||||
"""
|
||||
|
||||
|
||||
import six
|
||||
from config_models.admin import ConfigurationModelAdmin
|
||||
from config_models.models import ConfigurationModel
|
||||
from django.contrib import admin
|
||||
@@ -25,17 +24,17 @@ class GlobalStatusMessage(ConfigurationModel):
|
||||
message = models.TextField(
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text=u'<p>The contents of this field will be displayed as a warning banner on all views.</p>'
|
||||
u'<p>To override the banner message for a specific course, refer to the Course Message configuration. ' # lint-amnesty, pylint: disable=line-too-long
|
||||
u'Course Messages will only work if the global status message is enabled, so if you only want to add '
|
||||
u'a banner to specific courses without adding a global status message, you should add a global status ' # lint-amnesty, pylint: disable=line-too-long
|
||||
u'message with <strong>empty</strong> message text.</p>'
|
||||
u'<p>Finally, disable the global status message by adding another empty message with "enabled" '
|
||||
u'unchecked.</p>')
|
||||
help_text='<p>The contents of this field will be displayed as a warning banner on all views.</p>'
|
||||
'<p>To override the banner message for a specific course, refer to the Course Message configuration. ' # lint-amnesty, pylint: disable=line-too-long
|
||||
'Course Messages will only work if the global status message is enabled, so if you only want to add '
|
||||
'a banner to specific courses without adding a global status message, you should add a global status ' # lint-amnesty, pylint: disable=line-too-long
|
||||
'message with <strong>empty</strong> message text.</p>'
|
||||
'<p>Finally, disable the global status message by adding another empty message with "enabled" '
|
||||
'unchecked.</p>')
|
||||
|
||||
def full_message(self, course_key):
|
||||
""" Returns the full status message, including any course-specific status messages. """
|
||||
cache_key = "status_message.{course_id}".format(course_id=six.text_type(course_key))
|
||||
cache_key = "status_message.{course_id}".format(course_id=str(course_key))
|
||||
if cache.get(cache_key):
|
||||
return cache.get(cache_key)
|
||||
|
||||
@@ -45,7 +44,7 @@ class GlobalStatusMessage(ConfigurationModel):
|
||||
course_home_message = self.coursemessage_set.get(course_key=course_key)
|
||||
# Don't override the message if course_home_message is blank.
|
||||
if course_home_message:
|
||||
msg = HTML(u"{} <br /> {}").format(HTML(msg), HTML(course_home_message.message))
|
||||
msg = HTML("{} <br /> {}").format(HTML(msg), HTML(course_home_message.message))
|
||||
except CourseMessage.DoesNotExist:
|
||||
# We don't have a course-specific message, so pass.
|
||||
pass
|
||||
@@ -53,7 +52,7 @@ class GlobalStatusMessage(ConfigurationModel):
|
||||
return msg
|
||||
|
||||
def __str__(self):
|
||||
return "{} - {} - {}".format(self.change_date, self.enabled, self.message)
|
||||
return f"{self.change_date} - {self.enabled} - {self.message}"
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
@@ -71,7 +70,7 @@ class CourseMessage(models.Model):
|
||||
message = models.TextField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return six.text_type(self.course_key)
|
||||
return str(self.course_key)
|
||||
|
||||
|
||||
admin.site.register(GlobalStatusMessage, ConfigurationModelAdmin)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Tests for setting and displaying the site status message. """
|
||||
|
||||
|
||||
@@ -21,7 +20,7 @@ class TestStatus(TestCase):
|
||||
"""Test that the get_site_status_msg function does the right thing"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestStatus, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
# Clear the cache between test runs.
|
||||
cache.clear()
|
||||
self.course_key = CourseLocator(org='TestOrg', course='TestCourse', run='TestRun')
|
||||
@@ -29,9 +28,9 @@ class TestStatus(TestCase):
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
||||
@ddt.data(
|
||||
("Test global message", "Test course message"),
|
||||
(u" Ŧɇsŧ sŧȺŧᵾs", u"Ṫëṡẗ ċöüṛṡë ṡẗäẗüṡ "),
|
||||
(u"", u"Ṫëṡẗ ċöüṛṡë ṡẗäẗüṡ "),
|
||||
(u" Ŧɇsŧ sŧȺŧᵾs", u""),
|
||||
(" Ŧɇsŧ sŧȺŧᵾs", "Ṫëṡẗ ċöüṛṡë ṡẗäẗüṡ "),
|
||||
("", "Ṫëṡẗ ċöüṛṡë ṡẗäẗüṡ "),
|
||||
(" Ŧɇsŧ sŧȺŧᵾs", ""),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_get_site_status_msg(self, test_global_message, test_course_message):
|
||||
@@ -50,7 +49,7 @@ class TestStatus(TestCase):
|
||||
global_message=msg, message=test_course_message, course_key=self.course_key
|
||||
)
|
||||
course_msg.save()
|
||||
assert get_site_status_msg(self.course_key) == u'{} <br /> {}'.format(test_global_message, test_course_message)
|
||||
assert get_site_status_msg(self.course_key) == f'{test_global_message} <br /> {test_course_message}'
|
||||
|
||||
msg = GlobalStatusMessage.objects.create(message="", enabled=False)
|
||||
msg.save()
|
||||
|
||||
Reference in New Issue
Block a user