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
3from django.core.exceptions import ImproperlyConfigured
5# Exports
7__all__ = (
8 "DeeplyDisturbingError",
9 "IMustBeMissingSomething",
10 "ModelAlreadyRegistered",
11 "NoUserInRequest",
12 "NoViewForYou",
13 "ThisShouldNeverHappen",
14 "ViewAlreadyExists",
15 "YouShallNotPass",
16)
18# Classes
21class DeeplyDisturbingError(Exception):
22 """Indicates something is very (very) wrong with core, or "deep" functionality -- and we don't really know why."""
23 pass
26class IMustBeMissingSomething(ImproperlyConfigured):
27 """Indicates a view is missing an attribute or method definition."""
29 def __init__(self, class_name, attribute_name, method_name=None):
30 """Issue the error.
32 :param class_name: The name of the class with the missing attribute or method.
33 :type class_name: str
35 :param attribute_name: The name of the missing attribute.
36 :type attribute_name: str
38 :param method_name: The name (without the parentheses) of the method that calls the attribute.
39 :type method_name: str
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
46 message += "."
48 super().__init__(message)
51class ModelAlreadyRegistered(Exception):
52 """Indicates a model has already been registered with a :py:class:`SiteUI` instance."""
54 def __init__(self, model):
55 message = 'The model %s is already registered.' % model.__name__
56 super().__init__(message)
59class NoUserInRequest(ImproperlyConfigured):
60 """This error occurs when a request has no user attribute."""
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."
66 super().__init__(message)
69class NoViewForYou(Exception):
70 """Occurs when a view or viewset encounters errors with automatic generation of the view or URL."""
71 pass
74class ThisShouldNeverHappen(Exception):
75 """Indicates an application state that should never actually occur."""
76 pass
79class ViewAlreadyExists(Exception):
80 """Raised when a view of the same name has already been defined."""
82 def __init__(self, name):
83 """Issue the error.
85 :param name: The name of the view.
86 :type name: str
88 """
89 message = "The %s view already exists." % name
90 super().__init__(message)
93class YouShallNotPass(Exception):
94 """Indicates a conditional or other member has "passed" when it shouldn't.
96 .. code-block:: py
98 if some_condition:
99 # ...
100 elif some_other_condition:
101 # ...
102 else:
103 raise YouShallNotPass("No condition found.")
105 """
106 pass