Mercurial > public > sg101
comparison gpp/bio/models.py @ 562:98b373ca09f3
For bitbucket issue #3, ensure that changes to Profile, Post & Topic models
via the admin cause the search index to be updated.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 08 Feb 2012 18:58:57 -0600 |
parents | 4e891919c63f |
children |
comparison
equal
deleted
inserted
replaced
561:8f3b7f0d4d13 | 562:98b373ca09f3 |
---|---|
10 from django.conf import settings | 10 from django.conf import settings |
11 from django.core.cache import cache | 11 from django.core.cache import cache |
12 from django.template.loader import render_to_string | 12 from django.template.loader import render_to_string |
13 | 13 |
14 from core.markup import SiteMarkup | 14 from core.markup import SiteMarkup |
15 | |
15 | 16 |
16 # These are the secondary user status enumeration values. | 17 # These are the secondary user status enumeration values. |
17 (STA_ACTIVE, # User is a full member in good standing. | 18 (STA_ACTIVE, # User is a full member in good standing. |
18 STA_RESIGNED, # User has voluntarily asked to be removed. | 19 STA_RESIGNED, # User has voluntarily asked to be removed. |
19 STA_REMOVED, # User was removed for bad behavior. | 20 STA_REMOVED, # User was removed for bad behavior. |
101 | 102 |
102 class Meta: | 103 class Meta: |
103 ordering = ('user__username', ) | 104 ordering = ('user__username', ) |
104 | 105 |
105 def save(self, *args, **kwargs): | 106 def save(self, *args, **kwargs): |
106 self.update_date = datetime.datetime.now() | 107 """ |
107 sm = SiteMarkup() | 108 Custom profile save() function. |
108 self.profile_html = sm.convert(self.profile_text) | 109 If content_update is True (default), then it is assumed that major |
109 self.signature_html = sm.convert(self.signature) | 110 fields are being updated and that the profile_content_update signal |
111 should be signalled. When content_update is False, the update_date is | |
112 not updated, expensive markup conversions are not performed, and the | |
113 signal is not signalled. This is useful for updating the | |
114 forum_post_count, for example. | |
115 | |
116 """ | |
117 content_update = kwargs.pop('content_update', True) | |
118 | |
119 if content_update: | |
120 self.update_date = datetime.datetime.now() | |
121 sm = SiteMarkup() | |
122 self.profile_html = sm.convert(self.profile_text) | |
123 self.signature_html = sm.convert(self.signature) | |
124 cache.delete('avatar_' + self.user.username) | |
125 | |
110 super(UserProfile, self).save(*args, **kwargs) | 126 super(UserProfile, self).save(*args, **kwargs) |
111 cache.delete('avatar_' + self.user.username) | 127 |
128 if content_update: | |
129 notify_profile_content_update(self) | |
112 | 130 |
113 @models.permalink | 131 @models.permalink |
114 def get_absolute_url(self): | 132 def get_absolute_url(self): |
115 return ('bio-view_profile', (), {'username': self.user.username}) | 133 return ('bio-view_profile', (), {'username': self.user.username}) |
116 | 134 |
191 | 209 |
192 def badge_count_str(self): | 210 def badge_count_str(self): |
193 if self.count == 1: | 211 if self.count == 1: |
194 return u"1 %s" % self.badge.name | 212 return u"1 %s" % self.badge.name |
195 return u"%d %ss" % (self.count, self.badge.name) | 213 return u"%d %ss" % (self.count, self.badge.name) |
214 | |
215 # Put down here to avoid a circular import | |
216 from bio.signals import notify_profile_content_update |