Skip to content

Commit

Permalink
chore: get rid of edx_six - not needed anymore (#32555)
Browse files Browse the repository at this point in the history
* chore: get rid of edx_six - not needed anymore
* chore: remove reference to TODO that was completed.
  • Loading branch information
bradenmacdonald authored Jul 10, 2023
1 parent 7a89f2e commit 162175f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 71 deletions.
11 changes: 4 additions & 7 deletions cms/djangoapps/contentstore/tests/test_i18n.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Tests for validate Internationalization and XBlock i18n service.
"""


import gettext
from unittest import mock, skip

Expand All @@ -17,7 +15,6 @@
from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient
from cms.djangoapps.contentstore.views.preview import _prepare_runtime_for_preview
from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.lib.edx_six import get_gettext


class FakeTranslations(XBlockI18nService):
Expand Down Expand Up @@ -94,7 +91,7 @@ class wrap_ugettext_with_xyz: # pylint: disable=invalid-name

def __init__(self, module):
self.module = module
self.old_ugettext = get_gettext(module)
self.old_ugettext = module.gettext

def __enter__(self):
def new_ugettext(*args, **kwargs):
Expand Down Expand Up @@ -152,9 +149,9 @@ def test_message_catalog_translations(self):
with mock.patch('gettext.translation', return_value=_translator(domain='text', localedir=localedir,
languages=[get_language()])):
i18n_service = self.get_block_i18n_service(self.block)
self.assertEqual(get_gettext(i18n_service)('Hello'), 'Hello')
self.assertNotEqual(get_gettext(i18n_service)('Hello'), 'fr-hello-world')
self.assertNotEqual(get_gettext(i18n_service)('Hello'), 'es-hello-world')
self.assertEqual(i18n_service.gettext('Hello'), 'Hello')
self.assertNotEqual(i18n_service.gettext('Hello'), 'fr-hello-world')
self.assertNotEqual(i18n_service.gettext('Hello'), 'es-hello-world')

translation.activate("fr")
with mock.patch('gettext.translation', return_value=_translator(domain='text', localedir=localedir,
Expand Down
12 changes: 0 additions & 12 deletions openedx/core/lib/edx_six.py

This file was deleted.

7 changes: 3 additions & 4 deletions xmodule/capa/capa_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from xmodule.capa.safe_exec import safe_exec
from xmodule.capa.util import contextualize_text, convert_files_to_filenames, get_course_id_from_capa_block
from openedx.core.djangolib.markup import HTML, Text
from openedx.core.lib.edx_six import get_gettext
from xmodule.stringify import stringify_children

# extra things displayed after "show answers" is pressed
Expand Down Expand Up @@ -483,7 +482,7 @@ def get_grade_from_current_answers(self, student_answers):
# an earlier submission, so for now skip these entirely.
# TODO: figure out where to get file submissions when rescoring.
if 'filesubmission' in responder.allowed_inputfields and student_answers is None:
_ = get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
raise Exception(_("Cannot rescore problems with possible file submissions"))

# use 'student_answers' only if it is provided, and if it might contain a file
Expand Down Expand Up @@ -580,7 +579,7 @@ def generate_default_question_label():
question_nr = int(answer_id.split('_')[-2]) - 1
return _("Question {}").format(question_nr)

_ = get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
# Some questions define a prompt with this format: >>This is a prompt<<
try:
prompt = self.problem_data[answer_id].get('label')
Expand Down Expand Up @@ -693,7 +692,7 @@ def do_targeted_feedback(self, tree):
choice-level explanations shown to a student after submission.
Does nothing if there is no targeted-feedback attribute.
"""
_ = get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
# Note that the modifications has been done, avoiding problems if called twice.
if hasattr(self, 'has_targeted'):
return
Expand Down
29 changes: 14 additions & 15 deletions xmodule/capa/inputtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

from xmodule.capa.xqueue_interface import XQUEUE_TIMEOUT
from openedx.core.djangolib.markup import HTML, Text
from openedx.core.lib import edx_six
from xmodule.stringify import stringify_children

from . import xqueue_interface
Expand Down Expand Up @@ -327,7 +326,7 @@ def _get_render_context(self):
context = {
'id': self.input_id,
'value': self.value,
'status': Status(self.status, edx_six.get_gettext(self.capa_system.i18n)),
'status': Status(self.status, self.capa_system.i18n.gettext),
'msg': self.msg,
'response_data': self.response_data,
'STATIC_URL': self.capa_system.STATIC_URL,
Expand Down Expand Up @@ -459,7 +458,7 @@ def _extra_context(self):
"""
Return extra context.
"""
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
return {'default_option_text': _('Select an option')}

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -507,7 +506,7 @@ def setup(self):
self.html_input_type = "checkbox"
self.suffix = '[]'
else:
_ = edx_six.get_gettext(i18n)
_ = i18n.gettext
# Translators: 'ChoiceGroup' is an input type and should not be translated.
msg = _("ChoiceGroup: unexpected tag {tag_name}").format(tag_name=self.tag)
raise Exception(msg)
Expand Down Expand Up @@ -543,7 +542,7 @@ def extract_choices(element, i18n, text_only=False):
"""

choices = []
_ = edx_six.get_gettext(i18n)
_ = i18n.gettext

for choice in element:
if choice.tag == 'choice':
Expand Down Expand Up @@ -740,7 +739,7 @@ def setup(self):
Do some magic to handle queueing status (render as "queued" instead of "incomplete"),
pull queue_len from the msg field. (TODO: get rid of the queue_len hack).
"""
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
submitted_msg = _("Your files have been submitted. As soon as your submission is"
" graded, this message will be replaced with the grader's feedback.")
self.submitted_msg = submitted_msg
Expand Down Expand Up @@ -812,7 +811,7 @@ def setup_code_response_rendering(self):

def setup(self):
""" setup this input type """
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
submitted_msg = _("Your answer has been submitted. As soon as your submission is"
" graded, this message will be replaced with the grader's feedback.")
self.submitted_msg = submitted_msg
Expand All @@ -823,7 +822,7 @@ def _extra_context(self):
"""
Define queue_len, arial_label and code mirror exit message context variables
"""
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
return {
'queue_len': self.queue_len,
'aria_label': _('{programming_language} editor').format(
Expand Down Expand Up @@ -853,7 +852,7 @@ def setup(self):
"""
Handle matlab-specific parsing
"""
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext

submitted_msg = _("Submitted. As soon as a response is returned, "
"this message will be replaced by that feedback.")
Expand Down Expand Up @@ -936,7 +935,7 @@ def button_enabled(self):
def _extra_context(self):
""" Set up additional context variables"""

_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext

queue_msg = self.queue_msg
if len(self.queue_msg) > 0: # An empty string cannot be parsed as XML but is okay to include in the template.
Expand Down Expand Up @@ -985,7 +984,7 @@ def _plot_data(self, data):
dict - 'success' - whether or not we successfully queued this submission
- 'message' - message to be rendered in case of error
"""
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
# only send data if xqueue exists
if self.capa_system.xqueue is None:
return {'success': False, 'message': _('Cannot connect to the queue')}
Expand Down Expand Up @@ -1212,7 +1211,7 @@ def preview_chemcalc(self, data):
}
"""

_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
result = {'preview': '',
'error': ''}
try:
Expand Down Expand Up @@ -1296,7 +1295,7 @@ def preview_formcalc(self, get):
'request_start' : <time sent with request>
}
"""
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
result = {'preview': '',
'error': ''}

Expand Down Expand Up @@ -1681,7 +1680,7 @@ def setup(self):
elif self.tag == 'checkboxtextgroup':
self.html_input_type = "checkbox"
else:
_ = edx_six.get_gettext(self.capa_system.i18n)
_ = self.capa_system.i18n.gettext
msg = _("{input_type}: unexpected tag {tag_name}").format(
input_type="ChoiceTextGroup", tag_name=self.tag
)
Expand Down Expand Up @@ -1760,7 +1759,7 @@ def extract_choices(element, i18n):
]
"""

_ = edx_six.get_gettext(i18n)
_ = i18n.gettext
choices = []

for choice in element:
Expand Down
Loading

0 comments on commit 162175f

Please sign in to comment.