diff --git a/wagtail/api/v2/endpoints.py b/wagtail/api/v2/endpoints.py new file mode 100644 index 000000000..2525f112b --- /dev/null +++ b/wagtail/api/v2/endpoints.py @@ -0,0 +1,9 @@ +import sys +from wagtail.utils.deprecation import MovedDefinitionHandler, RemovedInWagtail210Warning + +MOVED_DEFINITIONS = { + 'BaseAPIEndpoint': ('wagtail.api.v2.views', 'BaseAPIViewSet'), + 'PagesAPIEndpoint': ('wagtail.api.v2.views', 'PagesAPIViewSet'), +} + +sys.modules[__name__] = MovedDefinitionHandler(sys.modules[__name__], MOVED_DEFINITIONS, RemovedInWagtail210Warning) diff --git a/wagtail/documents/api/v2/endpoints.py b/wagtail/documents/api/v2/endpoints.py new file mode 100644 index 000000000..b20323495 --- /dev/null +++ b/wagtail/documents/api/v2/endpoints.py @@ -0,0 +1,8 @@ +import sys +from wagtail.utils.deprecation import MovedDefinitionHandler, RemovedInWagtail210Warning + +MOVED_DEFINITIONS = { + 'DocumentsAPIEndpoint': ('wagtail.documents.api.v2.views', 'DocumentsAPIViewSet'), +} + +sys.modules[__name__] = MovedDefinitionHandler(sys.modules[__name__], MOVED_DEFINITIONS, RemovedInWagtail210Warning) diff --git a/wagtail/images/api/v2/endpoints.py b/wagtail/images/api/v2/endpoints.py new file mode 100644 index 000000000..5472f4c21 --- /dev/null +++ b/wagtail/images/api/v2/endpoints.py @@ -0,0 +1,8 @@ +import sys +from wagtail.utils.deprecation import MovedDefinitionHandler, RemovedInWagtail210Warning + +MOVED_DEFINITIONS = { + 'ImagesAPIEndpoint': ('wagtail.images.api.v2.views', 'ImagesAPIViewSet'), +} + +sys.modules[__name__] = MovedDefinitionHandler(sys.modules[__name__], MOVED_DEFINITIONS, RemovedInWagtail210Warning) diff --git a/wagtail/utils/deprecation.py b/wagtail/utils/deprecation.py index 0c0fc6c79..8429a18a2 100644 --- a/wagtail/utils/deprecation.py +++ b/wagtail/utils/deprecation.py @@ -42,19 +42,31 @@ class MovedDefinitionHandler: try: # is the missing name one of our moved definitions? new_module_name = self.moved_definitions[name] + new_name = name + + if isinstance(new_module_name, tuple): + new_module_name, new_name = new_module_name + except KeyError: # raise the original AttributeError without including the inner try/catch # in the stack trace raise e from None - warnings.warn( - "%s has been moved from %s to %s" % (name, self.real_module.__name__, new_module_name), - category=self.warning_class, stacklevel=2 - ) + if new_name != name: + warnings.warn( + "%s has been moved from %s to %s and renamed to %s" % (name, self.real_module.__name__, new_module_name, new_name), + category=self.warning_class, stacklevel=2 + ) + + else: + warnings.warn( + "%s has been moved from %s to %s" % (name, self.real_module.__name__, new_module_name), + category=self.warning_class, stacklevel=2 + ) # load the requested definition from the module named in moved_definitions new_module = import_module(new_module_name) - definition = getattr(new_module, name) + definition = getattr(new_module, new_name) # stash that definition into the current module so that we don't have to # redo this import next time we access it