Development of an internal social media platform with personalised dashboards for students
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.

exceptions.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from django.template import TemplateSyntaxError
  2. __all__ = ['ArgumentRequiredError', 'InvalidFlag', 'BreakpointExpected',
  3. 'TooManyArguments']
  4. class BaseError(TemplateSyntaxError):
  5. template = ''
  6. def __str__(self): # pragma: no cover
  7. return self.template % self.__dict__
  8. class ArgumentRequiredError(BaseError):
  9. template = "The tag '%(tagname)s' requires the '%(argname)s' argument."
  10. def __init__(self, argument, tagname):
  11. self.argument = argument
  12. self.tagname = tagname
  13. self.argname = self.argument.name
  14. class InvalidFlag(BaseError):
  15. template = ("The flag '%(argname)s' for the tag '%(tagname)s' must be one "
  16. "of %(allowed_values)s, but got '%(actual_value)s'")
  17. def __init__(self, argname, actual_value, allowed_values, tagname):
  18. self.argname = argname
  19. self.tagname = tagname
  20. self.actual_value = actual_value
  21. self.allowed_values = allowed_values
  22. class BreakpointExpected(BaseError):
  23. template = ("Expected one of the following breakpoints: %(breakpoints)s "
  24. "in %(tagname)s, got '%(got)s' instead.")
  25. def __init__(self, tagname, breakpoints, got):
  26. self.breakpoints = ', '.join(["'%s'" % bp for bp in breakpoints])
  27. self.tagname = tagname
  28. self.got = got
  29. class TrailingBreakpoint(BaseError):
  30. template = (
  31. "Tag %(tagname)s ends in trailing breakpoint '%(breakpoint)s' without "
  32. "an argument following."
  33. )
  34. def __init__(self, tagname, breakpoint):
  35. self.tagname = tagname
  36. self.breakpoint = breakpoint
  37. class TooManyArguments(BaseError):
  38. template = "The tag '%(tagname)s' got too many arguments: %(extra)s"
  39. def __init__(self, tagname, extra):
  40. self.tagname = tagname
  41. self.extra = ', '.join(["'%s'" % e for e in extra])
  42. class TemplateSyntaxWarning(Warning):
  43. """
  44. Used for variable cleaning TemplateSyntaxErrors when in non-debug-mode.
  45. """