Add back endpoints files with deprecation warnings

pull/5677/head
Karl Hobley 2019-11-15 14:51:53 +00:00 zatwierdzone przez Karl Hobley
rodzic 36d440d2dd
commit 56a6fb17e8
4 zmienionych plików z 42 dodań i 5 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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