Mercurial > public > sg101
comparison gpp/bio/models.py @ 277:d424b8bae71d
Fixing #128 and #129. Add elsewhere weblinks to search content. Add support for haystack's get_update_field() method.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 02 Oct 2010 23:24:39 +0000 |
parents | 75ea1a8be7f2 |
children | 39664e661c69 |
comparison
equal
deleted
inserted
replaced
276:8a46843c258f | 277:d424b8bae71d |
---|---|
1 """ | 1 """ |
2 Contains models for the bio application. | 2 Contains models for the bio application. |
3 I would have picked profile for this application, but that is already taken, apparently. | 3 I would have picked profile for this application, but that is already taken, apparently. |
4 """ | 4 """ |
5 | 5 import datetime |
6 import os.path | 6 import os.path |
7 | 7 |
8 from django.db import models | 8 from django.db import models |
9 from django.contrib.auth.models import User | 9 from django.contrib.auth.models import User |
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 | 13 |
13 from core.markup import SiteMarkup | 14 from core.markup import SiteMarkup |
14 | 15 |
15 # These are the secondary user status enumeration values. | 16 # These are the secondary user status enumeration values. |
16 (STA_ACTIVE, # User is a full member in good standing. | 17 (STA_ACTIVE, # User is a full member in good standing. |
88 forum_post_count = models.IntegerField(default=0) | 89 forum_post_count = models.IntegerField(default=0) |
89 status = models.IntegerField(default=STA_STRANGER, | 90 status = models.IntegerField(default=STA_STRANGER, |
90 choices=USER_STATUS_CHOICES) | 91 choices=USER_STATUS_CHOICES) |
91 status_date = models.DateTimeField(auto_now_add=True) | 92 status_date = models.DateTimeField(auto_now_add=True) |
92 badges = models.ManyToManyField(Badge, through="BadgeOwnership") | 93 badges = models.ManyToManyField(Badge, through="BadgeOwnership") |
94 update_date = models.DateTimeField(db_index=True, blank=True) | |
93 | 95 |
94 def __unicode__(self): | 96 def __unicode__(self): |
95 return self.user.username | 97 return self.user.username |
96 | 98 |
97 class Meta: | 99 class Meta: |
98 ordering = ('user__username', ) | 100 ordering = ('user__username', ) |
99 | 101 |
100 def save(self, *args, **kwargs): | 102 def save(self, *args, **kwargs): |
103 update_date = datetime.datetime.now() | |
101 sm = SiteMarkup() | 104 sm = SiteMarkup() |
102 self.profile_html = sm.convert(self.profile_text) | 105 self.profile_html = sm.convert(self.profile_text) |
103 self.signature_html = sm.convert(self.signature) | 106 self.signature_html = sm.convert(self.signature) |
104 super(UserProfile, self).save(*args, **kwargs) | 107 super(UserProfile, self).save(*args, **kwargs) |
105 cache.delete('avatar_' + self.user.username) | 108 cache.delete('avatar_' + self.user.username) |
132 if full_name: | 135 if full_name: |
133 return u"%s (%s)" % (self.user.username, full_name) | 136 return u"%s (%s)" % (self.user.username, full_name) |
134 return self.user.username | 137 return self.user.username |
135 | 138 |
136 def search_summary(self): | 139 def search_summary(self): |
137 return u"\n".join((self.location, self.occupation, self.interests, | 140 text = render_to_string('search/indexes/bio/userprofile_text.txt', |
138 self.profile_text, self.signature)) | 141 {'object': self}); |
142 return text | |
139 | 143 |
140 | 144 |
141 class UserProfileFlag(models.Model): | 145 class UserProfileFlag(models.Model): |
142 """This model represents a user flagging a profile as inappropriate.""" | 146 """This model represents a user flagging a profile as inappropriate.""" |
143 user = models.ForeignKey(User) | 147 user = models.ForeignKey(User) |