annotate gpp/bio/models.py @ 186:be3fff614b93

Implement #66; use jQuery UI autocomplete widget to replace obsolete jquery-autocomplete plugin. I implemented a very simple caching system.
author Brian Neal <bgneal@gmail.com>
date Tue, 30 Mar 2010 01:30:32 +0000
parents 152d77265da6
children b4305e18d3af
rev   line source
gremmie@1 1 """
gremmie@1 2 Contains models for the bio application.
gremmie@1 3 I would have picked profile for this application, but that is already taken, apparently.
gremmie@1 4 """
gremmie@1 5
gremmie@1 6 import os.path
gremmie@1 7
gremmie@1 8 from django.db import models
gremmie@1 9 from django.contrib import auth
gremmie@1 10 from django.conf import settings
bgneal@54 11 from django.core.cache import cache
gremmie@1 12
bgneal@128 13 from core.markup import SiteMarkup
bgneal@124 14
gremmie@1 15
bgneal@147 16 (STA_ACTIVE, STA_RESIGNED, STA_REMOVED, STA_SUSPENDED, STA_SPAMMER) = range(5)
bgneal@147 17
bgneal@147 18 USER_STATUS_CHOICES = (
bgneal@147 19 (STA_ACTIVE, "Active"),
bgneal@147 20 (STA_RESIGNED, "Resigned"),
bgneal@147 21 (STA_REMOVED, "Removed"),
bgneal@147 22 (STA_SUSPENDED, "Suspended"),
bgneal@147 23 (STA_SPAMMER, "Spammer"),
bgneal@147 24 )
bgneal@147 25
gremmie@1 26 def avatar_file_path_for_user(username, filename):
gremmie@1 27 return os.path.join(settings.AVATAR_DIR, 'users', username, filename)
gremmie@1 28
gremmie@1 29 def avatar_file_path(instance, filename):
gremmie@1 30 return avatar_file_path_for_user(instance.user.username, filename)
gremmie@1 31
gremmie@1 32
gremmie@1 33 class UserProfile(models.Model):
gremmie@1 34 """model to represent additional information about users"""
gremmie@1 35
gremmie@1 36 user = models.ForeignKey(auth.models.User, unique=True)
gremmie@1 37 location = models.CharField(max_length=128, blank=True)
gremmie@1 38 birthday = models.DateField(blank=True, null=True,
gremmie@1 39 help_text='Optional; the year is not shown to others')
gremmie@1 40 occupation = models.CharField(max_length=128, blank=True)
gremmie@1 41 interests = models.CharField(max_length=255, blank=True)
gremmie@1 42 profile_text = models.TextField(blank=True)
gremmie@1 43 profile_html = models.TextField(blank=True)
gremmie@1 44 hide_email = models.BooleanField(default=True)
gremmie@1 45 signature = models.TextField(blank=True)
gremmie@1 46 signature_html = models.TextField(blank=True)
gremmie@1 47 avatar = models.ImageField(upload_to=avatar_file_path, blank=True)
bgneal@70 48 time_zone = models.CharField(max_length=64, blank=True,
bgneal@70 49 default='US/Pacific')
bgneal@120 50 use_24_time = models.BooleanField(default=False)
bgneal@96 51 forum_post_count = models.IntegerField(default=0)
bgneal@147 52 status = models.IntegerField(default=STA_ACTIVE,
bgneal@147 53 choices=USER_STATUS_CHOICES)
bgneal@147 54 status_date = models.DateTimeField(auto_now_add=True)
gremmie@1 55
gremmie@1 56 def __unicode__(self):
gremmie@1 57 return self.user.username
gremmie@1 58
gremmie@1 59 class Meta:
gremmie@1 60 ordering = ('user__username', )
gremmie@1 61
gremmie@1 62 def save(self, *args, **kwargs):
bgneal@128 63 sm = SiteMarkup()
bgneal@128 64 self.profile_html = sm.convert(self.profile_text)
bgneal@128 65 self.signature_html = sm.convert(self.signature)
gremmie@1 66 super(UserProfile, self).save(*args, **kwargs)
bgneal@54 67 cache.delete('avatar_' + self.user.username)
bgneal@138 68
bgneal@138 69 @models.permalink
bgneal@138 70 def get_absolute_url(self):
bgneal@138 71 return ('bio-view_profile', (), {'username': self.user.username})
bgneal@138 72
bgneal@138 73
bgneal@138 74 class UserProfileFlag(models.Model):
bgneal@138 75 """This model represents a user flagging a profile as inappropriate."""
bgneal@138 76 user = models.ForeignKey(auth.models.User)
bgneal@138 77 profile = models.ForeignKey(UserProfile)
bgneal@138 78 flag_date = models.DateTimeField(auto_now_add=True)
bgneal@138 79
bgneal@138 80 def __unicode__(self):
bgneal@138 81 return u"%s's profile flagged by %s" % (self.profile.user.username,
bgneal@138 82 self.user.username)
bgneal@138 83
bgneal@138 84 class Meta:
bgneal@138 85 ordering = ('flag_date', )
bgneal@138 86
bgneal@138 87 def get_profile_url(self):
bgneal@138 88 return '<a href="%s">Profile</a>' % self.profile.get_absolute_url()
bgneal@138 89 get_profile_url.allow_tags = True