Ejemplo n.º 1
0
 def setUp(self):
     self.maxDiff = None  # to get large diff when a test fail
     reg_block = register(LeftBlock)
     reg_block.order = 0
     reg_block.save()
     reg_block = register(RightBlock)
     reg_block.order = 1
     reg_block.save()
     reg_block = register(FooterBlock)
     reg_block.order = 2
     reg_block.save()
     reg_block = register(FooContentBlock)
     reg_block.order = 3
     reg_block.save()
     reg_block = register(FooSectionBlock)
     reg_block.order = 4
     reg_block.save()
     self.content = BaseContent.objects.create(name_en='A content')
     content_reg_block = register(ContentRelatedBlock)
     content_reg_block.order = 5
     content_reg_block.content = self.content
     content_reg_block.save()
     self.content_2 = BaseContent.objects.create(name_en='Other content')
     content_reg_block_2 = register(ContentRelatedBlock)
     content_reg_block_2.order = 6
     content_reg_block_2.content = self.content_2
     content_reg_block_2.save()
     self.section = BaseSection.objects.create(name_en='A section')
     disabled_block = register(LeftBlock)
     disabled_block.active = False  # this block should not be visible
     disabled_block.save()
Ejemplo n.º 2
0
 def setUp(self):
     self.maxDiff = None  # to get large diff when a test fail
     reg_block = register(LeftBlock)
     reg_block.order = 0
     reg_block.save()
     reg_block = register(RightBlock)
     reg_block.order = 1
     reg_block.save()
     reg_block = register(FooterBlock)
     reg_block.order = 2
     reg_block.save()
     reg_block = register(FooContentBlock)
     reg_block.order = 3
     reg_block.save()
     reg_block = register(FooSectionBlock)
     reg_block.order = 4
     reg_block.save()
     self.content = BaseContent.objects.create(name_en='A content')
     content_reg_block = register(ContentRelatedBlock)
     content_reg_block.order = 5
     content_reg_block.content = self.content
     content_reg_block.save()
     self.content_2 = BaseContent.objects.create(name_en='Other content')
     content_reg_block_2 = register(ContentRelatedBlock)
     content_reg_block_2.order = 6
     content_reg_block_2.content = self.content_2
     content_reg_block_2.save()
     self.section = BaseSection.objects.create(name_en='A section')
     disabled_block = register(LeftBlock)
     disabled_block.active = False  # this block should not be visible
     disabled_block.save()
Ejemplo n.º 3
0
 def test_block_overwriting(self):
     """ Test block overriding behavior """
     content_reg_block = register(LeftBlock)
     content_reg_block.content = self.content
     content_reg_block.overwrite_always = True
     content_reg_block.placed_at = 'rightsidebar'
     content_reg_block.save()
     # this block will be placed in the "rightsidebar" and will hide the leftsidebar blocks
     self.assertTrue(
         'leftblock' not in get_block_names('leftsidebar', self.content))
     # section should not affect to this
     self.assertTrue('leftblock' not in get_block_names(
         'leftsidebar', self.content, self.section))
     # the overriding should not affect to content_2
     self.assertTrue(
         'leftblock' in get_block_names('leftsidebar', self.content_2))
     content_reg_block.overwrite_always = False
     content_reg_block.save()
     # this block will be placed in the "rightsidebar" but wont hide the leftsidebar blocks
     self.assertTrue(
         'leftblock' in get_block_names('leftsidebar', self.content))
     content_reg_block.overwrite_always = False
     content_reg_block.placed_at = 'leftsidebar'
     content_reg_block.save()
     # this block will be placed in the "rightsidebar" but wont hide the leftsidebar blocks
     self.assertEqual(
         get_block_names('leftsidebar', self.content).count('leftblock'), 1)
     content_reg_block.overwrite_if_place = False
     content_reg_block.save()
     # now the block "leftblock" should appears twice
     self.assertEqual(
         get_block_names('leftsidebar', self.content).count('leftblock'), 2)
Ejemplo n.º 4
0
 def test_block_overwriting(self):
     """ Test block overriding behavior """
     content_reg_block = register(LeftBlock)
     content_reg_block.content = self.content
     content_reg_block.overwrite_always = True
     content_reg_block.placed_at = 'rightsidebar'
     content_reg_block.save()
     # this block will be placed in the "rightsidebar" and will hide the leftsidebar blocks
     self.assertTrue('leftblock' not in get_block_names('leftsidebar', self.content))
     # section should not affect to this
     self.assertTrue('leftblock' not in get_block_names('leftsidebar', self.content, self.section))
     # the overriding should not affect to content_2
     self.assertTrue('leftblock' in get_block_names('leftsidebar', self.content_2))
     content_reg_block.overwrite_always = False
     content_reg_block.save()
     # this block will be placed in the "rightsidebar" but wont hide the leftsidebar blocks
     self.assertTrue('leftblock' in get_block_names('leftsidebar', self.content))
     content_reg_block.overwrite_always = False
     content_reg_block.placed_at = 'leftsidebar'
     content_reg_block.save()
     # this block will be placed in the "rightsidebar" but wont hide the leftsidebar blocks
     self.assertEqual(get_block_names('leftsidebar', self.content).count('leftblock'), 1)
     content_reg_block.overwrite_if_place = False
     content_reg_block.save()
     # now the block "leftblock" should appears twice
     self.assertEqual(get_block_names('leftsidebar', self.content).count('leftblock'), 2)
Ejemplo n.º 5
0
 def save(self):
     place = self.cleaned_data['place']
     reg_block = register(self.block_class)
     reg_block.active = True
     if self.cleaned_data['scope'] in ('content', 'section'):
         reg_block.content = self.tie_render
     reg_block.placed_at = place
     reg_block.save()
     reg_block.tied = self.tie_render
     return reg_block
Ejemplo n.º 6
0
 def save(self):
     place = self.cleaned_data['place']
     reg_block = register(self.block_class)
     reg_block.active = True
     if self.cleaned_data['scope'] in ('content', 'section'):
         reg_block.content = self.tie_render
     reg_block.placed_at = place
     reg_block.save()
     reg_block.tied = self.tie_render
     return reg_block
Ejemplo n.º 7
0
def register_plugin(plugin_dir):
    from merengue.pluggable.models import RegisteredPlugin
    from merengue.pluggable.utils import get_plugin_config, validate_plugin
    plugin_config = get_plugin_config(plugin_dir)
    if plugin_config:
        validate_plugin(plugin_config)
        try:
            reg_plugin = RegisteredPlugin.objects.get_by_item_class(plugin_config)
        except RegisteredPlugin.DoesNotExist:
            reg_plugin = register(plugin_config)
        plugin = reg_plugin.get_registry_item()
        reg_plugin.name = getattr(plugin, 'name')
        reg_plugin.directory_name = plugin_dir
        reg_plugin.description = getattr(plugin, 'description', '')
        reg_plugin.version = getattr(plugin, 'version', '')
        reg_plugin.required_apps = getattr(plugin, 'required_apps',
                                           None)
        reg_plugin.required_plugins = getattr(plugin,
                                              'required_plugins',
                                              None)
        reg_plugin.meta_info = {}
        if hasattr(plugin, 'screenshot'):
            reg_plugin.meta_info['screenshot'] = plugin.screenshot
        reg_plugin.meta_info['actions'] = []
        for action in plugin.get_actions():
            reg_plugin.meta_info['actions'].append({'name': unicode(action.name), 'help_text': unicode(action.help_text)})
        reg_plugin.meta_info['blocks'] = []
        for block in plugin.get_blocks():
            reg_plugin.meta_info['blocks'].append({'name': unicode(block.name), 'help_text': unicode(block.help_text)})
        if plugin.get_model_admins():
            reg_plugin.meta_info['has_own_admin'] = True
        else:
            reg_plugin.meta_info['has_own_admin'] = False
        reg_plugin.meta_info['middlewares'] = []
        for middleware in plugin.get_middlewares():
            reg_plugin.meta_info['middlewares'].append(middleware)
        reg_plugin.meta_info['section_models'] = []
        for model, admin in plugin.section_models():
            reg_plugin.meta_info['section_models'].append({'name': unicode(model._meta.verbose_name)})
        reg_plugin.meta_info['viewlets'] = []
        for viewlet in plugin.get_viewlets():
            reg_plugin.meta_info['viewlets'].append({'name': unicode(viewlet.name), 'help_text': unicode(viewlet.help_text)})

        if "notification" in settings.INSTALLED_APPS:
            from notification.models import create_notice_type
            for notification in plugin.get_notifications():
                label, display, description = notification
                create_notice_type(label, display, description)

        reg_plugin.save()
        return reg_plugin
    return None
Ejemplo n.º 8
0
    def save(self, *args, **kwargs):
        block_class_path = self.cleaned_data['block_class']
        class_name = block_class_path.split('.')[-1]
        module_path = '.'.join(block_class_path.split('.')[:-1])
        module = import_module(module_path)
        block_class = getattr(module, class_name)
        reg_block = register(block_class)
        reg_block.active = True
        reg_block.content = self.cleaned_data['content']

        # set to not rewrite if content has already a block of this kind
        filters = {'module': module_path, 'class_name': class_name,
                   'placed_at': getattr(block_class, 'default_place', None)}
        if reg_block.content.registeredblock_set.filter(**filters).count():
            reg_block.overwrite_if_place = False

        reg_block.save()
        return reg_block
Ejemplo n.º 9
0
    def save(self, *args, **kwargs):
        block_class_path = self.cleaned_data['block_class']
        class_name = block_class_path.split('.')[-1]
        module_path = '.'.join(block_class_path.split('.')[:-1])
        module = import_module(module_path)
        block_class = getattr(module, class_name)
        reg_block = register(block_class)
        reg_block.active = True
        reg_block.content = self.cleaned_data['content']

        # set to not rewrite if content has already a block of this kind
        filters = {
            'module': module_path,
            'class_name': class_name,
            'placed_at': getattr(block_class, 'default_place', None)
        }
        if reg_block.content.registeredblock_set.filter(**filters).count():
            reg_block.overwrite_if_place = False

        reg_block.save()
        return reg_block
Ejemplo n.º 10
0
def register_items(item_list):
    for item_class in item_list:
        if not registry.have_registered_items(item_class):
            registry.register(item_class)
Ejemplo n.º 11
0
def register_items(item_list):
    for item_class in item_list:
        if not registry.have_registered_items(item_class):
            registry.register(item_class)
Ejemplo n.º 12
0
def register_plugin(plugin_dir):
    from merengue.pluggable.models import RegisteredPlugin
    from merengue.pluggable.utils import get_plugin_config, validate_plugin
    plugin_config = get_plugin_config(plugin_dir)
    if plugin_config:
        validate_plugin(plugin_config)
        try:
            reg_plugin = RegisteredPlugin.objects.get_by_item_class(
                plugin_config)
        except RegisteredPlugin.DoesNotExist:
            reg_plugin = register(plugin_config)
        plugin = reg_plugin.get_registry_item()
        reg_plugin.name = getattr(plugin, 'name')
        reg_plugin.directory_name = plugin_dir
        reg_plugin.description = getattr(plugin, 'description', '')
        reg_plugin.version = getattr(plugin, 'version', '')
        reg_plugin.required_apps = getattr(plugin, 'required_apps', None)
        reg_plugin.required_plugins = getattr(plugin, 'required_plugins', None)
        reg_plugin.meta_info = {}
        if hasattr(plugin, 'screenshot'):
            reg_plugin.meta_info['screenshot'] = plugin.screenshot
        reg_plugin.meta_info['actions'] = []
        for action in plugin.get_actions():
            reg_plugin.meta_info['actions'].append({
                'name':
                unicode(action.name),
                'help_text':
                unicode(action.help_text)
            })
        reg_plugin.meta_info['blocks'] = []
        for block in plugin.get_blocks():
            reg_plugin.meta_info['blocks'].append({
                'name':
                unicode(block.name),
                'help_text':
                unicode(block.help_text)
            })
        if plugin.get_model_admins():
            reg_plugin.meta_info['has_own_admin'] = True
        else:
            reg_plugin.meta_info['has_own_admin'] = False
        reg_plugin.meta_info['middlewares'] = []
        for middleware in plugin.get_middlewares():
            reg_plugin.meta_info['middlewares'].append(middleware)
        reg_plugin.meta_info['section_models'] = []
        for model, admin in plugin.section_models():
            reg_plugin.meta_info['section_models'].append(
                {'name': unicode(model._meta.verbose_name)})
        reg_plugin.meta_info['viewlets'] = []
        for viewlet in plugin.get_viewlets():
            reg_plugin.meta_info['viewlets'].append({
                'name':
                unicode(viewlet.name),
                'help_text':
                unicode(viewlet.help_text)
            })

        if "notification" in settings.INSTALLED_APPS:
            from notification.models import create_notice_type
            for notification in plugin.get_notifications():
                label, display, description = notification
                create_notice_type(label, display, description)

        reg_plugin.save()
        return reg_plugin
    return None