Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Imports 

2 

3from django.core.exceptions import ImproperlyConfigured 

4 

5# Exports 

6 

7__all__ = ( 

8 "DeeplyDisturbingError", 

9 "IMustBeMissingSomething", 

10 "ModelAlreadyRegistered", 

11 "NoUserInRequest", 

12 "NoViewForYou", 

13 "ThisShouldNeverHappen", 

14 "ViewAlreadyExists", 

15 "YouShallNotPass", 

16) 

17 

18# Classes 

19 

20 

21class DeeplyDisturbingError(Exception): 

22 """Indicates something is very (very) wrong with core, or "deep" functionality -- and we don't really know why.""" 

23 pass 

24 

25 

26class IMustBeMissingSomething(ImproperlyConfigured): 

27 """Indicates a view is missing an attribute or method definition.""" 

28 

29 def __init__(self, class_name, attribute_name, method_name=None): 

30 """Issue the error. 

31 

32 :param class_name: The name of the class with the missing attribute or method. 

33 :type class_name: str 

34 

35 :param attribute_name: The name of the missing attribute. 

36 :type attribute_name: str 

37 

38 :param method_name: The name (without the parentheses) of the method that calls the attribute. 

39 :type method_name: str 

40 

41 """ 

42 message = '"%s" must define "%s"' % (class_name, attribute_name) 

43 if method_name is not None: 

44 message += ' or implement the "%s()" method' % method_name 

45 

46 message += "." 

47 

48 super().__init__(message) 

49 

50 

51class ModelAlreadyRegistered(Exception): 

52 """Indicates a model has already been registered with a :py:class:`SiteUI` instance.""" 

53 

54 def __init__(self, model): 

55 message = 'The model %s is already registered.' % model.__name__ 

56 super().__init__(message) 

57 

58 

59class NoUserInRequest(ImproperlyConfigured): 

60 """This error occurs when a request has no user attribute.""" 

61 

62 def __init__(self): 

63 message = "No user attribute for request. django.core.context_processors.auth and " \ 

64 "django.contrib.auth.middleware.AuthenticationMiddleware must be enabled." 

65 

66 super().__init__(message) 

67 

68 

69class NoViewForYou(Exception): 

70 """Occurs when a view or viewset encounters errors with automatic generation of the view or URL.""" 

71 pass 

72 

73 

74class ThisShouldNeverHappen(Exception): 

75 """Indicates an application state that should never actually occur.""" 

76 pass 

77 

78 

79class ViewAlreadyExists(Exception): 

80 """Raised when a view of the same name has already been defined.""" 

81 

82 def __init__(self, name): 

83 """Issue the error. 

84 

85 :param name: The name of the view. 

86 :type name: str 

87 

88 """ 

89 message = "The %s view already exists." % name 

90 super().__init__(message) 

91 

92 

93class YouShallNotPass(Exception): 

94 """Indicates a conditional or other member has "passed" when it shouldn't. 

95 

96 .. code-block:: py 

97 

98 if some_condition: 

99 # ... 

100 elif some_other_condition: 

101 # ... 

102 else: 

103 raise YouShallNotPass("No condition found.") 

104 

105 """ 

106 pass