comparison gpp/forums/models.py @ 170:6f14970b103a

Implement #52 Forums RSS feeds.
author Brian Neal <bgneal@gmail.com>
date Thu, 11 Feb 2010 02:29:03 +0000
parents cf9f9d4c4d54
children 500e5875a306
comparison
equal deleted inserted replaced
169:7071b196ddd5 170:6f14970b103a
40 return True 40 return True
41 if user.is_authenticated(): 41 if user.is_authenticated():
42 return self.groups.filter(user__pk=user.id).count() > 0 42 return self.groups.filter(user__pk=user.id).count() > 0
43 return False 43 return False
44 44
45 def is_public(self):
46 """Returns true if this is a public category, viewable by all."""
47 return self.groups.count() == 0
48
45 49
46 class ForumManager(models.Manager): 50 class ForumManager(models.Manager):
47 """ 51 """
48 The manager for the Forum model. Provides a centralized place to 52 The manager for the Forum model. Provides a centralized place to
49 put commonly used and useful queries. 53 put commonly used and useful queries.
59 63
60 def forum_ids_for_user(self, user): 64 def forum_ids_for_user(self, user):
61 """Returns a list of forum IDs that the given user can "see".""" 65 """Returns a list of forum IDs that the given user can "see"."""
62 qs = self._for_user(user) 66 qs = self._for_user(user)
63 return qs.values_list('id', flat=True) 67 return qs.values_list('id', flat=True)
68
69 def public_forums(self):
70 """Returns a queryset containing the public forums."""
71 return self.filter(category__groups__isnull=True)
64 72
65 def _for_user(self, user): 73 def _for_user(self, user):
66 """Common code for the xxx_for_user() methods.""" 74 """Common code for the xxx_for_user() methods."""
67 if user.is_superuser: 75 if user.is_superuser:
68 qs = self.all() 76 qs = self.all()