Mercurial > public > sg101
comparison gpp/forums/models.py @ 459:9d3bd7304050
Fixing #221. Also combined all permissions checks into a new module, permissions.py. This allows us to cache user, category, and forum groups information since it rarely changes.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 02 Jul 2011 23:35:45 +0000 |
parents | e9f203c5f5bb |
children | 7388cdf61b25 |
comparison
equal
deleted
inserted
replaced
458:9a4bffdf37c3 | 459:9d3bd7304050 |
---|---|
27 ordering = ('position', ) | 27 ordering = ('position', ) |
28 verbose_name_plural = 'Categories' | 28 verbose_name_plural = 'Categories' |
29 | 29 |
30 def __unicode__(self): | 30 def __unicode__(self): |
31 return self.name | 31 return self.name |
32 | |
33 def can_access(self, user): | |
34 """ | |
35 Checks to see if the given user has permission to access | |
36 this category. | |
37 If this category has no groups assigned to it, return true. | |
38 Else, return true if the user belongs to a group that has been | |
39 assigned to this category, and false otherwise. | |
40 """ | |
41 if self.groups.count() == 0: | |
42 return True | |
43 if user.is_authenticated(): | |
44 return self.groups.filter(user__pk=user.id).count() > 0 | |
45 return False | |
46 | |
47 def is_public(self): | |
48 """Returns true if this is a public category, viewable by all.""" | |
49 return self.groups.count() == 0 | |
50 | 32 |
51 | 33 |
52 class ForumManager(models.Manager): | 34 class ForumManager(models.Manager): |
53 """ | 35 """ |
54 The manager for the Forum model. Provides a centralized place to | 36 The manager for the Forum model. Provides a centralized place to |