~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to django/contrib/comments/managers.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.db import models
 
2
from django.dispatch import dispatcher
 
3
from django.contrib.contenttypes.models import ContentType
 
4
from django.utils.encoding import force_unicode
 
5
 
 
6
class CommentManager(models.Manager):
 
7
 
 
8
    def in_moderation(self):
 
9
        """
 
10
        QuerySet for all comments currently in the moderation queue.
 
11
        """
 
12
        return self.get_query_set().filter(is_public=False, is_removed=False)
 
13
 
 
14
    def for_model(self, model):
 
15
        """
 
16
        QuerySet for all comments for a particular model (either an instance or
 
17
        a class).
 
18
        """
 
19
        ct = ContentType.objects.get_for_model(model)
 
20
        qs = self.get_query_set().filter(content_type=ct)
 
21
        if isinstance(model, models.Model):
 
22
            qs = qs.filter(object_pk=force_unicode(model._get_pk_val()))
 
23
        return qs