Handle old named (referenced) docs

Refs #199
This commit is contained in:
Ross Lawley 2011-06-16 09:47:44 +01:00
parent 658b85d327
commit 22a7ee5885

View File

@ -23,13 +23,20 @@ class ValidationError(Exception):
_document_registry = {}
def get_document(name):
if name not in _document_registry:
doc = _document_registry.get(name, None)
if not doc:
# Possible old style names
end = ".%s" % name
possible_match = [k for k in _document_registry.keys() if k.endswith(end)]
if len(possible_match) == 1:
doc = _document_registry.get(possible_match.pop(), None)
if not doc:
raise NotRegistered("""
`%s` has not been registered in the document registry.
Importing the document class automatically registers it, has it
been imported?
""".strip() % name)
return _document_registry[name]
return doc
class BaseField(object):