Example #1
0
    def index(self, request, extra_context=None):
        from merengue.pluggable.utils import get_plugin_config

        extra_context = extra_context or {}
        app_dict = {}
        manage_plugin_content = perms_api.can_manage_plugin_content(
            request.user)
        for plugin_name, site in self._plugin_sites.items():
            app_label = plugin_name

            if app_label in app_dict:
                continue

            if manage_plugin_content:
                name = app_label.split('.')[1:]
                name = name and name[0] or ''
                config = get_plugin_config(name)
                app_dict[app_label] = {
                    'name': name.title(),
                    'app_url': app_label + '/',
                    'has_module_perms': manage_plugin_content,
                    'description': getattr(config, 'description', None),
                    'version': getattr(config, 'version', None),
                }

        # Sort the apps alphabetically.
        app_list = app_dict.values()
        app_list.sort(lambda x, y: cmp(x['name'], y['name']))

        extra_context.update({'plugins': app_dict})
        return super(AdminSite, self).index(request, extra_context)
Example #2
0
def register_all_plugins(verbose=False):
    from merengue.pluggable.models import RegisteredPlugin
    from merengue.pluggable.utils import (get_plugin_directories, get_plugin_config,
                                          reload_models_cache, remove_from_installed_apps,
                                          clear_plugin_module_cache, get_plugin_module_name)
    from merengue.pluggable.checker import mark_broken_plugin
    try:
        for plugin_dir in get_plugin_directories():
            try:
                if verbose:
                    plugin_config = get_plugin_config(plugin_dir)
                    if plugin_config:
                        if not have_registered_items(plugin_config):
                            print 'Registering new plugin %s...' % plugin_dir
                        else:
                            print 'Re-registering plugin %s...' % plugin_dir
                    else:
                        print 'Error walking to plugin %s.' % plugin_dir
                register_plugin(plugin_dir)
            except:
                mark_broken_plugin(plugin_dir)
                print 'Error registering %s plugin... go to next plugin.' % plugin_dir
    finally:
        for plugin in RegisteredPlugin.objects.inactives():
            clear_plugin_module_cache(get_plugin_module_name(plugin.directory_name))
            remove_from_installed_apps(plugin.directory_name)
        reload_models_cache()
Example #3
0
    def index(self, request, extra_context=None):
        from merengue.pluggable.utils import get_plugin_config

        extra_context = extra_context or {}
        app_dict = {}
        manage_plugin_content = perms_api.can_manage_plugin_content(request.user)
        for plugin_name, site in self._plugin_sites.items():
            app_label = plugin_name

            if app_label in app_dict:
                continue

            if manage_plugin_content:
                name = app_label.split('.')[1:]
                name = name and name[0] or ''
                config = get_plugin_config(name)
                app_dict[app_label] = {
                    'name': name.title(),
                    'app_url': app_label + '/',
                    'has_module_perms': manage_plugin_content,
                    'description': getattr(config, 'description', None),
                    'version': getattr(config, 'version', None),
                }

        # Sort the apps alphabetically.
        app_list = app_dict.values()
        app_list.sort(lambda x, y: cmp(x['name'], y['name']))

        extra_context.update(
            {'plugins': app_dict})
        return super(AdminSite, self).index(request, extra_context)
Example #4
0
def register_all_plugins(verbose=False):
    from merengue.pluggable.models import RegisteredPlugin
    from merengue.pluggable.utils import (get_plugin_directories,
                                          get_plugin_config,
                                          reload_models_cache,
                                          remove_from_installed_apps,
                                          clear_plugin_module_cache,
                                          get_plugin_module_name)
    from merengue.pluggable.checker import mark_broken_plugin
    try:
        for plugin_dir in get_plugin_directories():
            try:
                if verbose:
                    plugin_config = get_plugin_config(plugin_dir)
                    if plugin_config:
                        if not have_registered_items(plugin_config):
                            print 'Registering new plugin %s...' % plugin_dir
                        else:
                            print 'Re-registering plugin %s...' % plugin_dir
                    else:
                        print 'Error walking to plugin %s.' % plugin_dir
                register_plugin(plugin_dir)
            except:
                mark_broken_plugin(plugin_dir)
                print 'Error registering %s plugin... go to next plugin.' % plugin_dir
    finally:
        for plugin in RegisteredPlugin.objects.inactives():
            clear_plugin_module_cache(
                get_plugin_module_name(plugin.directory_name))
            remove_from_installed_apps(plugin.directory_name)
        reload_models_cache()
Example #5
0
 def breadcrumbs_first_item(self):
     from merengue.pluggable.utils import get_plugin_config
     plugin_dir = self._meta.app_label
     plugin_config = get_plugin_config(plugin_dir)
     if plugin_config is None:
         return None  # item model is outside plugin... no first item generated
     url_prefix = plugin_config.url_prefixes[0][0]
     if isinstance(url_prefix, dict):
         url_prefix = url_prefix.get(get_url_default_lang(), 'en')
     plugin_url = "/%s/" % url_prefix
     return (self._meta.verbose_name_plural, plugin_url)
Example #6
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
Example #7
0
 def get_plugin_config(self):
     from merengue.pluggable.utils import get_plugin_config
     return get_plugin_config(self.directory_name)
Example #8
0
 def get_plugin_config(self):
     from merengue.pluggable.utils import get_plugin_config
     return get_plugin_config(self.directory_name)
Example #9
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