Source code for superdjango.exceptions.library

# Imports

from django.core.exceptions import ImproperlyConfigured

# Exports

__all__ = (
    "DeeplyDisturbingError",
    "IMustBeMissingSomething",
    "ModelAlreadyRegistered",
    "NoUserInRequest",
    "NoViewForYou",
    "ThisShouldNeverHappen",
    "ViewAlreadyExists",
    "YouShallNotPass",
)

# Classes


[docs]class DeeplyDisturbingError(Exception): """Indicates something is very (very) wrong with core, or "deep" functionality -- and we don't really know why.""" pass
[docs]class IMustBeMissingSomething(ImproperlyConfigured): """Indicates a view is missing an attribute or method definition."""
[docs] def __init__(self, class_name, attribute_name, method_name=None): """Issue the error. :param class_name: The name of the class with the missing attribute or method. :type class_name: str :param attribute_name: The name of the missing attribute. :type attribute_name: str :param method_name: The name (without the parentheses) of the method that calls the attribute. :type method_name: str """ message = '"%s" must define "%s"' % (class_name, attribute_name) if method_name is not None: message += ' or implement the "%s()" method' % method_name message += "." super().__init__(message)
[docs]class ModelAlreadyRegistered(Exception): """Indicates a model has already been registered with a :py:class:`SiteUI` instance."""
[docs] def __init__(self, model): message = 'The model %s is already registered.' % model.__name__ super().__init__(message)
[docs]class NoUserInRequest(ImproperlyConfigured): """This error occurs when a request has no user attribute."""
[docs] def __init__(self): message = "No user attribute for request. django.core.context_processors.auth and " \ "django.contrib.auth.middleware.AuthenticationMiddleware must be enabled." super().__init__(message)
[docs]class NoViewForYou(Exception): """Occurs when a view or viewset encounters errors with automatic generation of the view or URL.""" pass
[docs]class ThisShouldNeverHappen(Exception): """Indicates an application state that should never actually occur.""" pass
[docs]class ViewAlreadyExists(Exception): """Raised when a view of the same name has already been defined."""
[docs] def __init__(self, name): """Issue the error. :param name: The name of the view. :type name: str """ message = "The %s view already exists." % name super().__init__(message)
[docs]class YouShallNotPass(Exception): """Indicates a conditional or other member has "passed" when it shouldn't. .. code-block:: py if some_condition: # ... elif some_other_condition: # ... else: raise YouShallNotPass("No condition found.") """ pass