Get a registered Document class by name.
(name)
| 26 | |
| 27 | |
| 28 | def get_document(name): |
| 29 | """Get a registered Document class by name.""" |
| 30 | doc = _document_registry.get(name, None) |
| 31 | if not doc: |
| 32 | # Possible old style name |
| 33 | single_end = name.split(".")[-1] |
| 34 | compound_end = ".%s" % single_end |
| 35 | possible_match = [ |
| 36 | k for k in _document_registry if k.endswith(compound_end) or k == single_end |
| 37 | ] |
| 38 | if len(possible_match) == 1: |
| 39 | doc = _document_registry.get(possible_match.pop(), None) |
| 40 | if not doc: |
| 41 | raise NotRegistered( |
| 42 | """ |
| 43 | `%s` has not been registered in the document registry. |
| 44 | Importing the document class automatically registers it, has it |
| 45 | been imported? |
| 46 | """.strip() |
| 47 | % name |
| 48 | ) |
| 49 | return doc |
| 50 | |
| 51 | |
| 52 | def _get_documents_by_db(connection_alias, default_connection_alias): |