From ab97902c5badf668243a8c6bd1194326905a23a7 Mon Sep 17 00:00:00 2001 From: Ali-D-Akbar Date: Tue, 15 Dec 2020 14:52:47 +0500 Subject: [PATCH 1/6] PROD-2118 --- .../js/capa/drag_and_drop/base_image.js | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/common/static/js/capa/drag_and_drop/base_image.js b/common/static/js/capa/drag_and_drop/base_image.js index c9114f86c7..a06f13f3e1 100644 --- a/common/static/js/capa/drag_and_drop/base_image.js +++ b/common/static/js/capa/drag_and_drop/base_image.js @@ -1,21 +1,14 @@ (function(requirejs, require, define) { - define([], function() { + define(['edx-ui-toolkit/js/utils/html-utils'], function(HtmlUtils) { return BaseImage; function BaseImage(state) { var $baseImageElContainer; - $baseImageElContainer = $( - '
' - ); + $baseImageElContainer = $(HtmlUtils.joinHtml( + HtmlUtils.HTML('
') + ).toString()); state.baseImageEl = $('', { alt: gettext('Drop target image') @@ -38,12 +31,13 @@ state.baseImageLoaded = true; }); state.baseImageEl.error(function() { + var errorMsg = HtmlUtils.joinHtml( + HtmlUtils.HTML(''), + HtmlUtils.HTML('ERROR: Image "'), state.config.baseImage, HtmlUtils.HTML('" was not found!'), + HtmlUtils.HTML('') + ); console.log('ERROR: Image "' + state.config.baseImage + '" was not found!'); - $baseImageElContainer.html( - '' + - 'ERROR: Image "' + state.config.baseImage + '" was not found!' + - '' - ); + HtmlUtils.setHtml($baseImageElContainer, errorMsg); $baseImageElContainer.appendTo(state.containerEl); }); } From 3c414041904e4e67945d62c68d3b015a54b6ab37 Mon Sep 17 00:00:00 2001 From: Ali-D-Akbar Date: Tue, 15 Dec 2020 15:58:08 +0500 Subject: [PATCH 2/6] PROD-2116 --- common/lib/capa/capa/templates/imageinput.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/lib/capa/capa/templates/imageinput.html b/common/lib/capa/capa/templates/imageinput.html index ca9cfafce8..0d6c0d5f6b 100644 --- a/common/lib/capa/capa/templates/imageinput.html +++ b/common/lib/capa/capa/templates/imageinput.html @@ -1,3 +1,4 @@ +<%page expression_filter="h"/>
<%include file="status_span.html" args="status=status, status_id=id"/> From 1847bee0ad6b84a00a94f3a609d0d65e15420e5e Mon Sep 17 00:00:00 2001 From: Ali-D-Akbar Date: Tue, 15 Dec 2020 16:01:07 +0500 Subject: [PATCH 3/6] PROD-2084 --- lms/static/js/instructor_dashboard/student_admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/static/js/instructor_dashboard/student_admin.js b/lms/static/js/instructor_dashboard/student_admin.js index 083475f879..54b773faaa 100644 --- a/lms/static/js/instructor_dashboard/student_admin.js +++ b/lms/static/js/instructor_dashboard/student_admin.js @@ -153,7 +153,7 @@ delete_module: false }; successMessage = gettext("Success! Problem attempts reset for problem '<%- problem_id %>' and student '<%- student_id %>'."); // eslint-disable-line max-len - errorMessage = gettext("Error resetting problem attempts for problem '<%= problem_id %>' and student '<%- student_id %>'. Make sure that the problem and student identifiers are complete and correct."); // eslint-disable-line max-len + errorMessage = gettext("Error resetting problem attempts for problem '<%- problem_id %>' and student '<%- student_id %>'. Make sure that the problem and student identifiers are complete and correct."); // eslint-disable-line max-len fullSuccessMessage = _.template(successMessage)({ problem_id: problemToReset, student_id: uniqStudentIdentifier From afb31f80498249893671cff18c6cf92ae540be0e Mon Sep 17 00:00:00 2001 From: Ali-D-Akbar Date: Tue, 15 Dec 2020 16:38:25 +0500 Subject: [PATCH 4/6] PROD-1993 --- cms/templates/js/due-date-editor.underscore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cms/templates/js/due-date-editor.underscore b/cms/templates/js/due-date-editor.underscore index 38cf3dac50..68bab6618b 100644 --- a/cms/templates/js/due-date-editor.underscore +++ b/cms/templates/js/due-date-editor.underscore @@ -1,12 +1,12 @@
  • - +
  • - +
  • @@ -14,9 +14,9 @@ From d6f6dad9a9ebfc80029a779f2ec4afaf50ce3e34 Mon Sep 17 00:00:00 2001 From: Ali-D-Akbar Date: Mon, 28 Dec 2020 14:47:04 +0500 Subject: [PATCH 5/6] PROD-2205 --- common/lib/symmath/symmath/formula.py | 6 +- common/lib/symmath/symmath/symmath_check.py | 74 ++++++++++++--------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/common/lib/symmath/symmath/formula.py b/common/lib/symmath/symmath/formula.py index e82d361d7c..edc4ad580a 100644 --- a/common/lib/symmath/symmath/formula.py +++ b/common/lib/symmath/symmath/formula.py @@ -32,6 +32,8 @@ from sympy.physics.quantum.state import Ket from sympy.printing.latex import LatexPrinter from sympy.printing.str import StrPrinter +from openedx.core.djangolib.markup import HTML + log = logging.getLogger(__name__) log.warning("Dark code. Needs review before enabling in prod.") @@ -90,8 +92,8 @@ def to_latex(expr): #return '%s{}{}' % (xs[1:-1]) if expr_s[0] == '$': - return '[mathjax]%s[/mathjax]
    ' % (expr_s[1:-1]) # for sympy v6 # xss-lint: disable=python-interpolate-html - return '[mathjax]%s[/mathjax]
    ' % (expr_s) # for sympy v7 # xss-lint: disable=python-interpolate-html + return HTML('[mathjax]{expression}[/mathjax]
    ').format(expression=expr_s[1:-1]) # for sympy v6 + return HTML('[mathjax]{expression}[/mathjax]
    ').format(expression=expr_s) # for sympy v7 def my_evalf(expr, chop=False): diff --git a/common/lib/symmath/symmath/symmath_check.py b/common/lib/symmath/symmath/symmath_check.py index cc43c32a2f..5a1a2171a7 100644 --- a/common/lib/symmath/symmath/symmath_check.py +++ b/common/lib/symmath/symmath/symmath_check.py @@ -12,6 +12,10 @@ import logging import traceback +from markupsafe import escape + +from openedx.core.djangolib.markup import HTML + from .formula import * log = logging.getLogger(__name__) @@ -49,8 +53,9 @@ def symmath_check_simple(expect, ans, adict={}, symtab=None, extra_options=None) ) except Exception as err: return {'ok': False, - 'msg': 'Error %s
    Failed in evaluating check(%s,%s)' % (err, expect, ans) - } + 'msg': HTML('Error {err}
    Failed in evaluating check({expect},{ans})').format( + err=err, expect=expect, ans=ans + )} return ret #----------------------------------------------------------------------------- @@ -94,22 +99,28 @@ def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym= try: xgiven = my_sympify(given, normphase, matrix, do_qubit=do_qubit, abcsym=abcsym, symtab=symtab) except Exception as err: - return {'ok': False, 'msg': 'Error %s
    in evaluating your expression "%s"' % (err, given)} + return {'ok': False, 'msg': HTML('Error {err}
    in evaluating your expression "{given}"').format( + err=err, given=given + )} try: xexpect = my_sympify(expect, normphase, matrix, do_qubit=do_qubit, abcsym=abcsym, symtab=symtab) except Exception as err: - return {'ok': False, 'msg': 'Error %s
    in evaluating OUR expression "%s"' % (err, expect)} + return {'ok': False, 'msg': HTML('Error {err}
    in evaluating OUR expression "{expect}"').format( + err=err, expect=expect + )} if 'autonorm' in flags: # normalize trace of matrices try: xgiven /= xgiven.trace() except Exception as err: - return {'ok': False, 'msg': 'Error %s
    in normalizing trace of your expression %s' % (err, to_latex(xgiven))} + return {'ok': False, 'msg': HTML('Error {err}
    in normalizing trace of your expression {xgiven}'). + format(err=err, xgiven=to_latex(xgiven))} try: xexpect /= xexpect.trace() except Exception as err: - return {'ok': False, 'msg': 'Error %s
    in normalizing trace of OUR expression %s' % (err, to_latex(xexpect))} + return {'ok': False, 'msg': HTML('Error {err}
    in normalizing trace of OUR expression {xexpect}'). + format(err=err, xexpect=to_latex(xexpect))} msg = 'Your expression was evaluated as ' + to_latex(xgiven) # msg += '
    Expected ' + to_latex(xexpect) @@ -145,7 +156,7 @@ def check(expect, given, numerical=False, matrix=False, normphase=False, abcsym= def make_error_message(msg): # msg = msg.replace('

    ','

    ').replace('

    ','

    ') - msg = '
    %s
    ' % msg + msg = HTML('
    {msg}
    ').format(msg=msg) return msg @@ -210,7 +221,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None try: fexpect = my_sympify(str(expect), matrix=do_matrix, do_qubit=do_qubit) except Exception as err: - msg += '

    Error %s in parsing OUR expected answer "%s"

    ' % (err, expect) + msg += HTML('

    Error {err} in parsing OUR expected answer "{expect}"

    ').format(err=err, expect=expect) return {'ok': False, 'msg': make_error_message(msg)} ###### Sympy input ####### @@ -226,18 +237,19 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None if is_within_tolerance(fexpect, fans, threshold): return {'ok': True, 'msg': msg} else: - msg += '

    You entered: %s

    ' % to_latex(fans) + msg += HTML('

    You entered: {fans}

    ').format(fans=to_latex(fans)) return {'ok': False, 'msg': msg} if do_numerical: # numerical answer expected - force numerical comparison if is_within_tolerance(fexpect, fans, threshold): return {'ok': True, 'msg': msg} else: - msg += '

    You entered: %s (note that a numerical answer is expected)

    ' % to_latex(fans) + msg += HTML('

    You entered: {fans} (note that a numerical answer is expected)

    ').\ + format(fans=to_latex(fans)) return {'ok': False, 'msg': msg} if fexpect == fans: - msg += '

    You entered: %s

    ' % to_latex(fans) + msg += HTML('

    You entered: {fans}

    ').format(fans=to_latex(fans)) return {'ok': True, 'msg': msg} ###### PMathML input ###### @@ -255,20 +267,18 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None # if DEBUG: msg += '

    mmlans=%s' % repr(mmlans).replace('<','<') try: fsym = f.sympy - msg += '

    You entered: %s

    ' % to_latex(f.sympy) + msg += HTML('

    You entered: {sympy}

    ').format(sympy=to_latex(f.sympy)) except Exception as err: log.exception("Error evaluating expression '%s' as a valid equation", ans) - msg += "

    Error in evaluating your expression '%s' as a valid equation

    " % (ans) + msg += HTML("

    Error in evaluating your expression '{ans}' as a valid equation

    ").format(ans=ans) if "Illegal math" in str(err): - msg += "

    Illegal math expression

    " + msg += HTML("

    Illegal math expression

    ") if DEBUG: - msg += 'Error: %s' % str(err).replace('<', '<') - msg += '
    ' - msg += '

    DEBUG messages:

    ' - msg += "

    %s

    " % traceback.format_exc() - msg += '

    cmathml=

    %s

    ' % f.cmathml.replace('<', '<') - msg += '

    pmathml=

    %s

    ' % mmlans.replace('<', '<') - msg += '
    ' + msg += HTML('Error: {err}

    DEBUG messages:

    {format_exc}

    ' + '

    cmathml=

    {cmathml}

    pmathml=

    {pmathml}


    ').format( + err=escape(str(err)), format_exc=traceback.format_exc(), cmathml=escape(f.cmathml), + pmathml=escape(mmlans) + ) return {'ok': False, 'msg': make_error_message(msg)} # do numerical comparison with expected @@ -277,9 +287,9 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None if abs(abs(fsym - fexpect) / fexpect) < threshold: return {'ok': True, 'msg': msg} return {'ok': False, 'msg': msg} - msg += "

    Expecting a numerical answer!

    " - msg += "

    given = %s

    " % repr(ans) - msg += "

    fsym = %s

    " % repr(fsym) + msg += HTML("

    Expecting a numerical answer!

    given = {ans}

    fsym = {fsym}

    ").format( + ans=repr(ans), fsym=repr(fsym) + ) # msg += "

    cmathml =

    %s

    " % str(f.cmathml).replace('<','<') return {'ok': False, 'msg': make_error_message(msg)} @@ -297,12 +307,12 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None if abs(dm.vec().norm().evalf()) < threshold: return {'ok': True, 'msg': msg} except sympy.ShapeError: - msg += "

    Error - your input vector or matrix has the wrong dimensions" + msg += HTML("

    Error - your input vector or matrix has the wrong dimensions") return {'ok': False, 'msg': make_error_message(msg)} except Exception as err: - msg += "

    Error %s in comparing expected (a list) and your answer

    " % str(err).replace('<', '<') + msg += HTML("

    Error %s in comparing expected (a list) and your answer

    ").format(escape(str(err))) if DEBUG: - msg += "

    %s
    " % traceback.format_exc() + msg += HTML("

    {format_exc}
    ").format(format_exc=traceback.format_exc()) return {'ok': False, 'msg': make_error_message(msg)} #diff = (fexpect-fsym).simplify() @@ -314,15 +324,13 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None diff = None if DEBUG: - msg += '
    ' - msg += '

    DEBUG messages:

    ' - msg += "

    Got: %s

    " % repr(fsym) + msg += HTML('

    DEBUG messages:

    Got: {fsym}

    Expecting: {fexpect}

    ')\ + .format(fsym=repr(fsym), fexpect=repr(fexpect).replace('**', '^').replace('hat(I)', 'hat(i)')) # msg += "

    Got: %s" % str([type(x) for x in fsym.atoms()]).replace('<','<') - msg += "

    Expecting: %s

    " % repr(fexpect).replace('**', '^').replace('hat(I)', 'hat(i)') # msg += "

    Expecting: %s" % str([type(x) for x in fexpect.atoms()]).replace('<','<') if diff: - msg += "

    Difference: %s

    " % to_latex(diff) - msg += '
    ' + msg += HTML("

    Difference: {diff}

    ").format(diff=to_latex(diff)) + msg += HTML('
    ') # Used to return more keys: 'ex': fexpect, 'got': fsym return {'ok': False, 'msg': msg} From 533ef0d20e4e829acd4f2f581bbdf627b0b826e7 Mon Sep 17 00:00:00 2001 From: Ali-D-Akbar Date: Mon, 28 Dec 2020 17:11:27 +0500 Subject: [PATCH 6/6] PROD-2248 --- .../templates/static_templates/contact.html | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/common/test/test_sites/test_site/templates/static_templates/contact.html b/common/test/test_sites/test_site/templates/static_templates/contact.html index 3cd9120e9a..1eec8a2d29 100644 --- a/common/test/test_sites/test_site/templates/static_templates/contact.html +++ b/common/test/test_sites/test_site/templates/static_templates/contact.html @@ -4,6 +4,8 @@ <%! from django.utils.translation import ugettext as _ from django.urls import reverse + +from openedx.core.djangolib.markup import HTML, Text %> <%block name="title">${_("Contact {platform_name}").format(platform_name=settings.PLATFORM_NAME)} @@ -25,39 +27,40 @@ from django.urls import reverse

    ${_("We are always seeking feedback to improve our courses. If you are an enrolled student and have any questions, feedback, suggestions, or any other issues specific to a particular class, please post on the discussion forums of that class.")}

    ${_("General Inquiries and Feedback")}

    -

    ${_('If you have a general question about {platform_name} please email {email}. To see if your question has already been answered, visit our {faq_link_start}FAQ page{faq_link_end}. You can also join the discussion on our {fb_link_start}facebook page{fb_link_end}. Though we may not have a chance to respond to every email, we take all feedback into consideration.').format( +

    ${Text(_('If you have a general question about {platform_name} please email {email}. To see if your question has already been answered, visit our {faq_link_start}FAQ page{faq_link_end}. You can also join the discussion on our {fb_link_start}facebook page{fb_link_end}. Though we may not have a chance to respond to every email, we take all feedback into consideration.')).format( platform_name=settings.PLATFORM_NAME, - email='{contact_email}'.format(contact_email=settings.CONTACT_EMAIL), - faq_link_start=''.format(url=reverse('faq_edx')), - faq_link_end='', - fb_link_start='', - fb_link_end='' + email=HTML('{contact_email}').format(contact_email=settings.CONTACT_EMAIL), + faq_link_start=HTML('').format(url=reverse('faq_edx')), + faq_link_end=HTML(''), + fb_link_start=HTML(''), + fb_link_end=HTML('') )}

    ${_("Technical Inquiries and Feedback")}

    -

    ${_('If you have suggestions/feedback about the overall {platform_name} platform, or are facing general technical issues with the platform (e.g., issues with email addresses and passwords), you can reach us at {tech_email}. For technical questions, please make sure you are using a current version of Firefox or Chrome, and include browser and version in your e-mail, as well as screenshots or other pertinent details. If you find a bug or other issues, you can reach us at the following: {bug_email}.').format( +

    ${Text(_('If you have suggestions/feedback about the overall {platform_name} platform, or are facing general technical issues with the platform (e.g., issues with email addresses and passwords), you can reach us at {tech_email}. For technical questions, please make sure you are using a current version of Firefox or Chrome, and include browser and version in your e-mail, as well as screenshots or other pertinent details. If you find a bug or other issues, you can reach us at the following: {bug_email}.')).format( platform_name=settings.PLATFORM_NAME, - tech_email='{tech_support_email}'.format(tech_support_email=settings.TECH_SUPPORT_EMAIL), - bug_email='{bugs_email}'.format(bugs_email=settings.BUGS_EMAIL) + tech_email=HTML('{tech_support_email}').format(tech_support_email=settings.TECH_SUPPORT_EMAIL), + bug_email=HTML('{bugs_email}').format(bugs_email=settings.BUGS_EMAIL) )}

    ${_("Media")}

    -

    ${_('Please visit our {link_start}media/press page{link_end} for more information. For any media or press inquiries, please email {email}.').format( - link_start=''.format(url=reverse('faq_edx')), - link_end='', - email='{email}'.format(email="press@edx.org"), +

    ${Text(_('Please visit our {link_start}media/press page{link_end} for more information. For any media or press inquiries, please email {email}.')).format( + link_start=HTML('').format(url=reverse('faq_edx')), + link_end=HTML(''), + email=HTML('{email}').format(email="press@edx.org"), )}

    ${_("Universities")}

    -

    ${_('If you are a university wishing to collaborate or you have questions about {platform_name}, please email {email}.'.format( +

    ${Text(_('If you are a university wishing to collaborate or you have questions about {platform_name}, please email {email}.')).format( platform_name="edX", - email='{email}'.format( + email=HTML('{email}').format( email="university@edx.org" ) - ))}

    + )}

    ${_("Accessibility")}

    -

    ${_('{platform_name} strives to create an innovative online-learning platform that promotes accessibility for everyone, including students with disabilities. We are dedicated to improving the accessibility of the platform and welcome your comments or questions at {email}.'.format(platform_name="EdX", email='{email}'.format(email="accessibility@edx.org")))}

    +

    ${Text(_('{platform_name} strives to create an innovative online-learning platform that promotes accessibility for everyone, including students with disabilities. We are dedicated to improving the accessibility of the platform and welcome your comments or questions at {email}.')).format( + platform_name="EdX", email=HTML('{email}').format(email="accessibility@edx.org"))}