From cf10b29a3e0a4408a82f09f7d0db3da0b69f5a95 Mon Sep 17 00:00:00 2001 From: Usama Sadiq Date: Tue, 16 Mar 2021 14:30:46 +0500 Subject: [PATCH] refactor: ran pyupgrade on openedx/core/djangoapps/dark_lang (#26849) --- openedx/core/djangoapps/dark_lang/middleware.py | 2 +- .../core/djangoapps/dark_lang/migrations/0001_initial.py | 5 +---- .../dark_lang/migrations/0002_data__enable_on_install.py | 3 --- .../dark_lang/migrations/0003_auto_20180425_0359.py | 5 ++--- openedx/core/djangoapps/dark_lang/models.py | 8 ++++---- openedx/core/djangoapps/dark_lang/tests.py | 4 ++-- openedx/core/djangoapps/dark_lang/views.py | 4 ++-- 7 files changed, 12 insertions(+), 19 deletions(-) diff --git a/openedx/core/djangoapps/dark_lang/middleware.py b/openedx/core/djangoapps/dark_lang/middleware.py index 72ecb7f156..dd2e805166 100644 --- a/openedx/core/djangoapps/dark_lang/middleware.py +++ b/openedx/core/djangoapps/dark_lang/middleware.py @@ -126,7 +126,7 @@ class DarkLangMiddleware(MiddlewareMixin): fuzzy_code = self._fuzzy_match(lang.lower()) if fuzzy_code: # Formats lang and priority into a valid accept header fragment. - new_accept.append("{};q={}".format(fuzzy_code, priority)) + new_accept.append(f"{fuzzy_code};q={priority}") new_accept = ", ".join(new_accept) diff --git a/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py b/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py index 904f8bc7d3..6c8ab882e8 100644 --- a/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py +++ b/openedx/core/djangoapps/dark_lang/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - from django.db import migrations, models import django.db.models.deletion from django.conf import settings @@ -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')), - ('released_languages', models.TextField(help_text=u'A comma-separated list of language codes to release to the public.', blank=True)), + ('released_languages', models.TextField(help_text='A comma-separated list of language codes to release to the public.', 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')), ], options={ diff --git a/openedx/core/djangoapps/dark_lang/migrations/0002_data__enable_on_install.py b/openedx/core/djangoapps/dark_lang/migrations/0002_data__enable_on_install.py index 1c9dd79f56..f664bb8c8b 100644 --- a/openedx/core/djangoapps/dark_lang/migrations/0002_data__enable_on_install.py +++ b/openedx/core/djangoapps/dark_lang/migrations/0002_data__enable_on_install.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - # Converted from the original South migration 0002_enable_on_install.py # from django.db import migrations, models diff --git a/openedx/core/djangoapps/dark_lang/migrations/0003_auto_20180425_0359.py b/openedx/core/djangoapps/dark_lang/migrations/0003_auto_20180425_0359.py index 6ad7b2f6dc..9e3924b2d3 100644 --- a/openedx/core/djangoapps/dark_lang/migrations/0003_auto_20180425_0359.py +++ b/openedx/core/djangoapps/dark_lang/migrations/0003_auto_20180425_0359.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.12 on 2018-04-25 07:59 @@ -15,11 +14,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name='darklangconfig', name='beta_languages', - field=models.TextField(blank=True, help_text=u'A comma-separated list of language codes to release to the public as beta languages.'), + field=models.TextField(blank=True, help_text='A comma-separated list of language codes to release to the public as beta languages.'), ), migrations.AddField( model_name='darklangconfig', name='enable_beta_languages', - field=models.BooleanField(default=False, help_text=u'Enable partially supported languages to display in language drop down.'), + field=models.BooleanField(default=False, help_text='Enable partially supported languages to display in language drop down.'), ), ] diff --git a/openedx/core/djangoapps/dark_lang/models.py b/openedx/core/djangoapps/dark_lang/models.py index 2971fad7ae..009214b239 100644 --- a/openedx/core/djangoapps/dark_lang/models.py +++ b/openedx/core/djangoapps/dark_lang/models.py @@ -17,19 +17,19 @@ class DarkLangConfig(ConfigurationModel): """ released_languages = models.TextField( blank=True, - help_text=u"A comma-separated list of language codes to release to the public." + help_text="A comma-separated list of language codes to release to the public." ) enable_beta_languages = models.BooleanField( default=False, - help_text=u"Enable partially supported languages to display in language drop down." + help_text="Enable partially supported languages to display in language drop down." ) beta_languages = models.TextField( blank=True, - help_text=u"A comma-separated list of language codes to release to the public as beta languages." + help_text="A comma-separated list of language codes to release to the public as beta languages." ) def __str__(self): - return u"DarkLangConfig()" + return "DarkLangConfig()" @property def released_languages_list(self): diff --git a/openedx/core/djangoapps/dark_lang/tests.py b/openedx/core/djangoapps/dark_lang/tests.py index 6c3a4ff6c3..170df89236 100644 --- a/openedx/core/djangoapps/dark_lang/tests.py +++ b/openedx/core/djangoapps/dark_lang/tests.py @@ -4,12 +4,12 @@ Tests of DarkLangMiddleware import unittest +from unittest.mock import Mock import ddt from django.http import HttpRequest from django.test.client import Client from django.utils.translation import LANGUAGE_SESSION_KEY -from mock import Mock from openedx.core.djangoapps.dark_lang.middleware import DarkLangMiddleware from openedx.core.djangoapps.dark_lang.models import DarkLangConfig @@ -34,7 +34,7 @@ class DarkLangMiddlewareTests(CacheIsolationTestCase): Tests of DarkLangMiddleware """ def setUp(self): - super(DarkLangMiddlewareTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory.build(username='test', email='test@edx.org', password='test_password') self.user.save() self.client = Client() diff --git a/openedx/core/djangoapps/dark_lang/views.py b/openedx/core/djangoapps/dark_lang/views.py index d6b41a72fa..a2453fb1d0 100644 --- a/openedx/core/djangoapps/dark_lang/views.py +++ b/openedx/core/djangoapps/dark_lang/views.py @@ -58,7 +58,7 @@ class PreviewLanguageFragmentView(EdxFragmentView): """ if not self._user_can_preview_languages(request.user): raise Http404 - return super(PreviewLanguageFragmentView, self).get(request, *args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments + return super().get(request, *args, **kwargs) @method_decorator(login_required) def post(self, request, **kwargs): # lint-amnesty, pylint: disable=unused-argument @@ -94,7 +94,7 @@ class PreviewLanguageFragmentView(EdxFragmentView): set_user_preference(request.user, DARK_LANGUAGE_KEY, preview_language) PageLevelMessages.register_success_message( request, - _(u'Language set to {preview_language}').format( + _('Language set to {preview_language}').format( preview_language=preview_language ) )