Beispiel #1
0
    pass


class WidgetDoesNotExist(Exception):
    pass


DEFAULT_WIDGET_LOADERS = ("page.loaders.PathWidgetLoader",)
DEFAULT_ENTITY_LOADERS = ("page.loaders.SafeModelLoader",)
DEFAULT_LAYOUT_LOADERS = (
    "page.loaders.SlugLayoutLoader",
    "page.loaders.EntityLayoutLoader",
    "page.loaders.EntityTypeLayoutLoader",
)

LAYOUT_LOADERS = [import_class(s)() for s in getattr(settings, "PAGE_LAYOUT_LOADERS", DEFAULT_LAYOUT_LOADERS)]
ENTITY_LOADERS = [import_class(s)() for s in getattr(settings, "PAGE_ENTITY_LOADERS", DEFAULT_ENTITY_LOADERS)]
WIDGET_LOADERS = [import_class(s)() for s in getattr(settings, "PAGE_WIDGET_LOADERS", DEFAULT_WIDGET_LOADERS)]


def get_layout(slug, entity_type, entity):
    for loader in LAYOUT_LOADERS:
        try:
            result = loader.get(slug=slug, entity_type=entity_type, entity=entity)
            if result:
                return result
        except:
            pass
    raise LayoutDoesNotExist

	def get(self, widget_name):
		for path in WIDGET_PATHS:
			try:
				return import_class("%s.%s" % (path, widget_name))
			except:
				pass