annotate gpp/bio/models.py @ 126:b0d62247c3e4

Add some javascript to check for posting a blank comment. Change wording on forum error message for the same thing.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Nov 2009 20:30:31 +0000
parents 9c18250972d5
children 48621ba5c385
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@124 13 from core.markup import Markdown
bgneal@124 14 from smiley import Smilify
bgneal@124 15
gremmie@1 16
gremmie@1 17 def avatar_file_path_for_user(username, filename):
gremmie@1 18 return os.path.join(settings.AVATAR_DIR, 'users', username, filename)
gremmie@1 19
gremmie@1 20 def avatar_file_path(instance, filename):
gremmie@1 21 return avatar_file_path_for_user(instance.user.username, filename)
gremmie@1 22
gremmie@1 23
gremmie@1 24 class UserProfile(models.Model):
gremmie@1 25 """model to represent additional information about users"""
gremmie@1 26
gremmie@1 27 user = models.ForeignKey(auth.models.User, unique=True)
gremmie@1 28 location = models.CharField(max_length=128, blank=True)
gremmie@1 29 birthday = models.DateField(blank=True, null=True,
gremmie@1 30 help_text='Optional; the year is not shown to others')
gremmie@1 31 occupation = models.CharField(max_length=128, blank=True)
gremmie@1 32 interests = models.CharField(max_length=255, blank=True)
gremmie@1 33 profile_text = models.TextField(blank=True)
gremmie@1 34 profile_html = models.TextField(blank=True)
gremmie@1 35 hide_email = models.BooleanField(default=True)
gremmie@1 36 signature = models.TextField(blank=True)
gremmie@1 37 signature_html = models.TextField(blank=True)
gremmie@1 38 avatar = models.ImageField(upload_to=avatar_file_path, blank=True)
bgneal@70 39 time_zone = models.CharField(max_length=64, blank=True,
bgneal@70 40 default='US/Pacific')
bgneal@120 41 use_24_time = models.BooleanField(default=False)
bgneal@96 42 forum_post_count = models.IntegerField(default=0)
gremmie@1 43
gremmie@1 44 def __unicode__(self):
gremmie@1 45 return self.user.username
gremmie@1 46
gremmie@1 47 class Meta:
gremmie@1 48 ordering = ('user__username', )
gremmie@1 49
gremmie@1 50 def save(self, *args, **kwargs):
bgneal@124 51 md = Markdown()
bgneal@124 52 sm = Smilify()
bgneal@124 53 self.profile_html = sm.convert(md.convert(self.profile_text))
bgneal@124 54 self.signature_html = sm.convert(md.convert(self.signature))
gremmie@1 55 super(UserProfile, self).save(*args, **kwargs)
bgneal@54 56 cache.delete('avatar_' + self.user.username)