Exemple #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)
Exemple #2
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)
Exemple #3
0
    def index(self, request):
        """
        Displays the main admin index page, which lists all of the installed
        apps that have been registered in this site.

        Code taken of django.contrib.admin.sites module. We have change the
        permissions to see all models admins.
        """
        extra_context = {
            'title': _('%(plugin_name)s plugin administration') % {'plugin_name': self.plugin_name},
            'inplugin': True,
            'plugin_name': self.plugin_name,
        }
        app_dict = {}
        for model, model_admin in self._registry.items():
            app_label = model._meta.app_label
            # in plugin site admin
            has_module_perms = perms_api.can_manage_plugin_content(request.user)

            if has_module_perms:
                perms = model_admin.get_model_perms(request)

                # Check whether user has any perm for this module.
                # If so, add the module to the model_list.
                if True in perms.values():
                    model_dict = {
                        'name': capfirst(model._meta.verbose_name_plural),
                        'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())),
                        'perms': perms,
                    }
                    if app_label in app_dict:
                        app_dict[app_label]['models'].append(model_dict)
                    else:
                        app_dict[app_label] = {
                            'name': app_label.title(),
                            'app_url': app_label + '/',
                            'has_module_perms': has_module_perms,
                            'models': [model_dict],
                        }

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

        # Sort the models alphabetically within each app.
        for app in app_list:
            app['models'].sort(lambda x, y: cmp(x['name'], y['name']))

        context = {
            'title': _('Site administration'),
            'app_list': app_list,
            'root_path': self.root_path,
        }
        context.update(extra_context or {})
        context_instance = template.RequestContext(request, current_app=self.name)
        return render_to_response(
            self.index_template or 'admin/index.html', context,
            context_instance=context_instance,
        )
Exemple #4
0
    def index(self, request):
        """
        Displays the main admin index page, which lists all of the installed
        apps that have been registered in this site.

        Code taken of django.contrib.admin.sites module. We have change the
        permissions to see all models admins.
        """
        extra_context = {
            'title': _('%(plugin_name)s plugin administration') % {
                'plugin_name': self.plugin_name
            },
            'inplugin': True,
            'plugin_name': self.plugin_name,
        }
        app_dict = {}
        for model, model_admin in self._registry.items():
            app_label = model._meta.app_label
            # in plugin site admin
            has_module_perms = perms_api.can_manage_plugin_content(
                request.user)

            if has_module_perms:
                perms = model_admin.get_model_perms(request)

                # Check whether user has any perm for this module.
                # If so, add the module to the model_list.
                if True in perms.values():
                    model_dict = {
                        'name':
                        capfirst(model._meta.verbose_name_plural),
                        'admin_url':
                        mark_safe('%s/%s/' %
                                  (app_label, model.__name__.lower())),
                        'perms':
                        perms,
                    }
                    if app_label in app_dict:
                        app_dict[app_label]['models'].append(model_dict)
                    else:
                        app_dict[app_label] = {
                            'name': app_label.title(),
                            'app_url': app_label + '/',
                            'has_module_perms': has_module_perms,
                            'models': [model_dict],
                        }

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

        # Sort the models alphabetically within each app.
        for app in app_list:
            app['models'].sort(lambda x, y: cmp(x['name'], y['name']))

        context = {
            'title': _('Site administration'),
            'app_list': app_list,
            'root_path': self.root_path,
        }
        context.update(extra_context or {})
        context_instance = template.RequestContext(request,
                                                   current_app=self.name)
        return render_to_response(
            self.index_template or 'admin/index.html',
            context,
            context_instance=context_instance,
        )