Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

dummy.py 1.7KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import string
  2. from django.core.exceptions import ImproperlyConfigured
  3. from django.template import Origin, TemplateDoesNotExist
  4. from django.utils.html import conditional_escape
  5. from .base import BaseEngine
  6. from .utils import csrf_input_lazy, csrf_token_lazy
  7. class TemplateStrings(BaseEngine):
  8. app_dirname = "template_strings"
  9. def __init__(self, params):
  10. params = params.copy()
  11. options = params.pop("OPTIONS").copy()
  12. if options:
  13. raise ImproperlyConfigured("Unknown options: {}".format(", ".join(options)))
  14. super().__init__(params)
  15. def from_string(self, template_code):
  16. return Template(template_code)
  17. def get_template(self, template_name):
  18. tried = []
  19. for template_file in self.iter_template_filenames(template_name):
  20. try:
  21. with open(template_file, encoding="utf-8") as fp:
  22. template_code = fp.read()
  23. except FileNotFoundError:
  24. tried.append(
  25. (
  26. Origin(template_file, template_name, self),
  27. "Source does not exist",
  28. )
  29. )
  30. else:
  31. return Template(template_code)
  32. raise TemplateDoesNotExist(template_name, tried=tried, backend=self)
  33. class Template(string.Template):
  34. def render(self, context=None, request=None):
  35. if context is None:
  36. context = {}
  37. else:
  38. context = {k: conditional_escape(v) for k, v in context.items()}
  39. if request is not None:
  40. context["csrf_input"] = csrf_input_lazy(request)
  41. context["csrf_token"] = csrf_token_lazy(request)
  42. return self.safe_substitute(context)