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.

base.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from django.template import Template, TemplateDoesNotExist
  2. class Loader:
  3. def __init__(self, engine):
  4. self.engine = engine
  5. def get_template(self, template_name, skip=None):
  6. """
  7. Call self.get_template_sources() and return a Template object for
  8. the first template matching template_name. If skip is provided, ignore
  9. template origins in skip. This is used to avoid recursion during
  10. template extending.
  11. """
  12. tried = []
  13. for origin in self.get_template_sources(template_name):
  14. if skip is not None and origin in skip:
  15. tried.append((origin, "Skipped to avoid recursion"))
  16. continue
  17. try:
  18. contents = self.get_contents(origin)
  19. except TemplateDoesNotExist:
  20. tried.append((origin, "Source does not exist"))
  21. continue
  22. else:
  23. return Template(
  24. contents,
  25. origin,
  26. origin.template_name,
  27. self.engine,
  28. )
  29. raise TemplateDoesNotExist(template_name, tried=tried)
  30. def get_template_sources(self, template_name):
  31. """
  32. An iterator that yields possible matching template paths for a
  33. template name.
  34. """
  35. raise NotImplementedError(
  36. "subclasses of Loader must provide a get_template_sources() method"
  37. )
  38. def reset(self):
  39. """
  40. Reset any state maintained by the loader instance (e.g. cached
  41. templates or cached loader modules).
  42. """
  43. pass