示例#1
0
    def handle(self, request, data):

        root_page = Page.objects.get(pk=data['page_id'])

        new_page = copy_model_instance(root_page, exclude=('id', 'parent'))

        if data.get("depth", 0):
            Page.copy_content_from(root_page)
示例#2
0
    def handle(self, request, data):

        root_page = Page.objects.get(pk=data['page_id'])

        new_page = copy_model_instance(root_page,
                                       exclude=('id', 'parent'))

        if data.get("depth", 0):
            Page.copy_content_from(root_page)
示例#3
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)
示例#4
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)
示例#5
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 *
示例#6
0
    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 Exception as e:
                    raise e
            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)


register_widgets()
Page.register_extensions(*settings.PAGE_EXTENSIONS)
Page.register_default_processors(True)
示例#7
0
    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)


register_widgets()
Page.register_extensions(*settings.PAGE_EXTENSIONS)
Page.register_default_processors(True)
示例#8
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 *
示例#9
0
 def test_01_simple_content_type_creation(self):
     for widget in default.widgets:
         self.assertIsNotNone(Page.content_type_for(widget))
示例#10
0
 def test_01_simple_content_type_creation(self):
     for widget in get_all_widget_classes():
         self.assertIsNotNone(Page.content_type_for(widget))