예제 #1
0
def create_moderate_perms(app, created_models, verbosity, **kwargs):
    """ This will create moderate permissions for all registered models"""
    from django.contrib.auth.models import Permission

    from django_monitor import queued_models

    for model in queued_models():
        ctype = ContentType.objects.get_for_model(model)
        codename = 'moderate_%s' % model._meta.object_name.lower()
        name = u'Can moderate %s' % model._meta.verbose_name_raw
        p, created = Permission.objects.get_or_create(
            codename = codename,
            content_type__pk = ctype.id,
            defaults = {'name': name, 'content_type': ctype}
        )
        if created and verbosity >= 2:
            print "Adding permission '%s'" % p
예제 #2
0
def create_moderate_perms(sender, verbosity=0, **kwargs):
    """ This will create moderate permissions for all registered models"""
    from django.contrib.auth.models import Permission
    from django.contrib.contenttypes.models import ContentType

    from django_monitor import queued_models

    for model in queued_models():
        ctype = ContentType.objects.get_for_model(model)
        codename = 'moderate_%s' % model._meta.object_name.lower()
        name = u'Can moderate %s' % model._meta.verbose_name_raw
        p, created = Permission.objects.get_or_create(
            codename=codename,
            content_type__pk=ctype.id,
            defaults={
                'name': name,
                'content_type': ctype
            })
        if created and verbosity >= 2:
            print "Adding permission '%s'" % p
예제 #3
0
    def changelist_view(self, request, extra_context = None):
        """
        The 'change list' admin view is overridden to return a page showing the
        moderation summary aggregated for each model.
        """
        model_list = []
        for model in queued_models():
            # I do not like to access private objects. No other option here!
            # Get only those objects developer wish to let user see..
            try:
                model_admin = self.admin_site._registry[model]
            except KeyError:
                # This may happen at test-time. There the ``queued_models``
                # come from the project where the test is actually being run
                # but the admin_site registry knows only those models in
                # ``django_monitor.tests.apps.testapp.models``.
                continue

            ip_count = model_admin.queryset(request).pending().count()
            ch_count = model_admin.queryset(request).challenged().count()

            app_label = model._meta.app_label
            if ip_count or ch_count:
                model_list.append({
                    'model_name': model._meta.verbose_name,
                    'app_name': app_label.title(),
                    'pending': ip_count, 'challenged': ch_count,
                    'admin_url': mark_safe(
                        '/admin/%s/%s/' % (app_label, model.__name__.lower())
                    ),
                })
        model_list.sort(key = lambda x: (x['app_name'], x['model_name']))
        return render_to_response(
            self.change_list_template,
            {
                'model_list': model_list,
                'ip_status': PENDING_STATUS, 'ip_descr': PENDING_DESCR,
                'ch_status': CHALLENGED_STATUS, 'ch_descr': CHALLENGED_DESCR
            },
            context_instance = RequestContext(request)
        )
예제 #4
0
    def changelist_view(self, request, extra_context = None):
        """
        The 'change list' admin view is overridden to return a page showing the
        moderation summary aggregated for each model.
        """
        model_list = []
        for model in queued_models():
            # I do not like to access private objects. No other option here!
            # Get only those objects developer wish to let user see..
            try:
                model_admin = self.admin_site._registry[model]
            except KeyError:
                # This may happen at test-time. There the ``queued_models``
                # come from the project where the test is actually being run
                # but the admin_site registry knows only those models in
                # ``django_monitor.tests.apps.testapp.models``.
                continue

            ip_count = model_admin.get_queryset(request).pending().count()
            ch_count = model_admin.get_queryset(request).challenged().count()

            app_label = model._meta.app_label
            if ip_count or ch_count:
                model_list.append({
                    'model_name': model._meta.verbose_name,
                    'app_name': app_label.title(),
                    'pending': ip_count, 'challenged': ch_count,
                    'admin_url': mark_safe(
                        '/admin/%s/%s/' % (app_label, model.__name__.lower())
                    ),
                })
        model_list.sort(key = lambda x: (x['app_name'], x['model_name']))
        return render(
            request,
            self.change_list_template,
            {
                'model_list': model_list,
                'ip_status': PENDING_STATUS, 'ip_descr': PENDING_DESCR,
                'ch_status': CHALLENGED_STATUS, 'ch_descr': CHALLENGED_DESCR
            }
        )