示例#1
0
def register_widgets():
    """
    Register all collected widgets from settings
    WIDGETS = [('mymodule.models.MyWidget', {'mykwargs': 'mykwarg'})]
    WIDGETS = ['mymodule.models.MyWidget', MyClass]
    """

    # special case
    # register external apps
    Page.create_content_type(
        ApplicationWidget, APPLICATIONS=settings.APPLICATION_CHOICES)

    for _optgroup, _widgets in six.iteritems(settings.WIDGETS):
        optgroup = _optgroup if _optgroup != 'ungrouped' else None
        for widget in _widgets:

            kwargs = {'optgroup': optgroup}

            # load class from strings
            if isinstance(widget, six.string_types):
                try:
                    WidgetCls = get_class_from_string(widget)
                except:
                    exc_info = sys.exc_info()
                    raise six.reraise(*exc_info)
            elif isinstance(widget, tuple):
                try:
                    WidgetCls = get_class_from_string(widget[0])
                    if len(widget) > 1:
                        kwargs.update(widget[1])
                except Exception as e:
                    raise Exception('%s: %s' % (mod, e))
            else:
                WidgetCls = widget

            Page.create_content_type(
                WidgetCls, **kwargs)
示例#2
0
def register_widgets():
    """
    Register all collected widgets from settings
    WIDGETS = [('mymodule.models.MyWidget', {'mykwargs': 'mykwarg'})]
    WIDGETS = ['mymodule.models.MyWidget', MyClass]
    """

    # special case
    # register external apps
    Page.create_content_type(
        ApplicationWidget, APPLICATIONS=settings.APPLICATION_CHOICES)

    for _optgroup, _widgets in six.iteritems(settings.WIDGETS):
        optgroup = _optgroup if _optgroup != 'ungrouped' else None
        for widget in _widgets:

            kwargs = {'optgroup': optgroup}

            # load class from strings
            if isinstance(widget, six.string_types):
                try:
                    WidgetCls = get_class_from_string(widget)
                except:
                    exc_info = sys.exc_info()
                    raise six.reraise(*exc_info)
            elif isinstance(widget, tuple):
                try:
                    WidgetCls = get_class_from_string(widget[0])
                    if len(widget) > 1:
                        kwargs.update(widget[1])
                except Exception as e:
                    raise Exception('%s: %s' % (mod, e))
            else:
                WidgetCls = widget

            Page.create_content_type(
                WidgetCls, **kwargs)
示例#3
0
                warnings.warn('You have ungrouped widgets'
                              ', please specify your ``optgroup``'
                              'which categorize your widgets in %s' % mod)

    except Exception as e:
        warnings.warn(
            'Exception "{}" raised during loading '
            'module {}'.format(str(e), mod))

setattr(leonardo, 'widgets', WIDGETS)

from leonardo.module.web.models import Page
from leonardo.module.web.widget import ApplicationWidget

# register external apps
Page.create_content_type(
    ApplicationWidget, APPLICATIONS=APPLICATION_CHOICES)

# register widgets
for _optgroup, _widgets in six.iteritems(WIDGETS):
    optgroup = _optgroup if _optgroup != 'ungrouped' else None
    for widget in _widgets:
        Page.create_content_type(widget, optgroup=optgroup)

Page.register_extensions(*PAGE_EXTENSIONS)
Page.register_default_processors(LEONARDO_FRONTEND_EDITING)

# FINALLY OVERRIDE ALL

try:
    # local settings
    from local_settings import *
示例#4
0
                warnings.warn('You have ungrouped widgets'
                              ', please specify your ``optgroup``'
                              'which categorize your widgets in %s' % mod)

    except Exception as e:
        warnings.warn(
            'Exception "{}" raised during loading '
            'module {}'.format(str(e), mod))

setattr(leonardo, 'widgets', WIDGETS)

from leonardo.module.web.models import Page
from leonardo.module.web.widget import ApplicationWidget

# register external apps
Page.create_content_type(
    ApplicationWidget, APPLICATIONS=APPLICATION_CHOICES)

# register widgets
for _optgroup, _widgets in six.iteritems(WIDGETS):
    optgroup = _optgroup if _optgroup != 'ungrouped' else None
    for widget in _widgets:
        Page.create_content_type(widget, optgroup=optgroup)

Page.register_extensions(*PAGE_EXTENSIONS)
Page.register_default_processors(LEONARDO_FRONTEND_EDITING)

# FINALLY OVERRIDE ALL

try:
    # local settings
    from local_settings import *