Coverage for pages.widgets_registry: 100%

# Coverage for pages.widgets_registry : 100%

## 17 statements 17 run 0 excluded 0 missing

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """Django page CMS widget registry.""" __all__ = ('register_widget',) from django.utils.translation import ugettext as _ class WidgetAlreadyRegistered(Exception): """ An attempt was made to register a widget for Django page CMS more than once. """ pass class WidgetNotFound(Exception): """ The requested widget was not found """ pass registry = [] def register_widget(widget): """ Register the given widget as a candidate to use in placeholder. """ if widget in registry: raise WidgetAlreadyRegistered( _('The widget %s has already been registered.') % widget.__name__) registry.append(widget) def get_widget(name): """ Give back a widget class according to his name. """ for widget in registry: if widget.__name__ == name: return widget raise WidgetNotFound( _('The widget %s has not been registered.') % name)