Content Moderator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from django.contrib.sites.managers import CurrentSiteManager
from django.db.models import Manager
from django.db.models.manager import ManagerDescriptor
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q

from flag.models import FlaggedContent


class GenericManager(Manager):
    def get_query_set(self):
        f=~Q(id__in=getapprovedids(self.model))
        return super(GenericManager, self).get_query_set().filter(f)

class SiteManager(CurrentSiteManager):
    def get_query_set(self):
        f=~Q(id__in=getapprovedids(self.model))
        return super(SiteManager, self).get_query_set().filter(f)


def getapprovedids(model):
    ct=ContentType.objects.get_for_model(model)
    statusfilter= Q(status=4) | Q(status=5)
    ids=FlaggedContent.objects.filter(Q(content_type=ct), statusfilter).values_list('object_id')
    return map(lambda x: x[0],ids)
    
    

def register(model):
        for key in model.__dict__:
            if(type(model.__dict__[key])==ManagerDescriptor):
                if type(model.__dict__[key].manager)==Manager:
                    GenericManager().contribute_to_class(model,key)
                else:
                    SiteManager().contribute_to_class(model,key)  


"""

Usage Example:

Put the above code in your django-flag.__init__.py .

Wherever applicable, state the following code:

from flag import register
from myapp.models import mymodel
register(mymodel)


"""  

More like this

  1. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  2. Unobtrusive comment moderation by ubernostrum 6 years, 2 months ago
  3. monkey-patch django to use jinja2 templates for 404/500 pages and 3rd-party apps by brondsem 4 years, 2 months ago
  4. Semi-Portable recaptcha integration with django forms by pinkeen 2 years, 5 months ago
  5. nginx x-accel-redirect protection of static files by sean 5 years, 5 months ago

Comments

(Forgotten your password?)