| Conditions | 3 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | # coding=utf-8 |
||
| 9 | def get_backend(backend_class=None): |
||
| 10 | """ |
||
| 11 | Get backend instance |
||
| 12 | |||
| 13 | If no `backend_class` is specified, the backend class is determined from |
||
| 14 | the value of `settings.ROUGHPAGES_BACKEND`. |
||
| 15 | `backend_class` can be a class object or dots separated python import path |
||
| 16 | |||
| 17 | Returns: |
||
| 18 | backend instance |
||
| 19 | """ |
||
| 20 | cache_name = '_backend_instance' |
||
| 21 | if not hasattr(get_backend, cache_name): |
||
| 22 | backend_class = backend_class or settings.ROUGHPAGES_BACKEND |
||
| 23 | if isinstance(backend_class, basestring): |
||
| 24 | module_path, class_name = backend_class.rsplit(".", 1) |
||
| 25 | module = import_module(module_path) |
||
| 26 | backend_class = getattr(module, class_name) |
||
| 27 | setattr(get_backend, cache_name, backend_class()) |
||
| 28 | return getattr(get_backend, cache_name) |
||
| 29 | |||
| 35 |