CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.mit.edu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.4 KiB

  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2020 by The CAT-SOOP Developers <catsoop-dev@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. tutor.qtype_inherit("bigbox")
  17. _base_render_html = render_html
  18. _base_handle_submit = handle_submission
  19. defaults.update({"csq_soln": "", "csq_npoints": 1, "csq_show_check": False})
  20. def markdownify(context, text):
  21. return context["csm_language"]._md(text)
  22. def richtext_format(context, text, msg="Preview:"):
  23. out = "</br>%s<br/>" % msg
  24. out += (
  25. '<div style="background-color: #eeeeee;' 'padding:10px; border-radius:10px;">'
  26. )
  27. out += markdownify(context, text)
  28. out = out.replace("<script", "&lt;script")
  29. out = out.replace("</script", "&lt;script")
  30. out += (
  31. '<script type="text/javascript">'
  32. 'catsoop.render_all_math(document.getElementById("cs_qdiv_%s"), true);'
  33. "</script>"
  34. ) % context["csq_name"]
  35. out += "</div>"
  36. return out
  37. checktext = "Preview"
  38. def handle_check(submission, **info):
  39. last = submission.get(info["csq_name"])
  40. return richtext_format(info, last)
  41. def handle_submission(submissions, **info):
  42. o = _base_handle_submit(submissions, **info)
  43. o["msg"] = o.get("msg", "") + richtext_format(
  44. info, submissions[info["csq_name"]], msg="Submitted:"
  45. )
  46. return o
  47. def render_html(last_log, **info):
  48. out = _base_render_html(last_log, **info)
  49. help_url = "/".join([info["cs_url_root"], "_qtype", "richtext", "formatting.html"])
  50. out += (
  51. """<a onClick="window.open('%s', '_blank', """
  52. """'');" """
  53. """style="cursor:pointer; cursor:hand;">"""
  54. """Formatting Help</a>"""
  55. ) % help_url
  56. return out
  57. def answer_display(**info):
  58. out = "<b>Solution:</b><br/>&nbsp;<br/> %s" % (info["csq_soln"])
  59. return out