Mercurial > public > sg101
comparison gpp/bio/models.py @ 329:000c006fee97
Various small changes to reduce database hits.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 23 Feb 2011 03:40:18 +0000 |
parents | 4d086d2210b9 |
children | 9d470c7a2b93 |
comparison
equal
deleted
inserted
replaced
328:3f9b9fd54b01 | 329:000c006fee97 |
---|---|
110 @models.permalink | 110 @models.permalink |
111 def get_absolute_url(self): | 111 def get_absolute_url(self): |
112 return ('bio-view_profile', (), {'username': self.user.username}) | 112 return ('bio-view_profile', (), {'username': self.user.username}) |
113 | 113 |
114 def badge_ownership(self): | 114 def badge_ownership(self): |
115 if hasattr(self, '_badges'): | 115 return BadgeOwnership.objects.filter(profile=self).select_related('badge') |
116 return self._badges | |
117 | |
118 cache_key = 'badges-%s' % self.user.username | |
119 self._badges = cache.get(cache_key) | |
120 if self._badges is not None: | |
121 return self._badges | |
122 | |
123 self._badges = BadgeOwnership.objects.filter(profile=self).select_related( | |
124 "badge") | |
125 | |
126 cache.set(cache_key, self._badges, 15 * 60) | |
127 return self._badges | |
128 | 116 |
129 def is_stranger(self): | 117 def is_stranger(self): |
130 """Returns True if this user profile status is STA_STRANGER.""" | 118 """Returns True if this user profile status is STA_STRANGER.""" |
131 return self.status == STA_STRANGER | 119 return self.status == STA_STRANGER |
132 | 120 |