gremmie@1: """ gremmie@1: Contains models for the bio application. gremmie@1: I would have picked profile for this application, but that is already taken, apparently. gremmie@1: """ gremmie@1: gremmie@1: import os.path gremmie@1: gremmie@1: from django.db import models gremmie@1: from django.contrib import auth gremmie@1: from django.conf import settings bgneal@54: from django.core.cache import cache gremmie@1: bgneal@124: from core.markup import Markdown bgneal@124: from smiley import Smilify bgneal@124: gremmie@1: gremmie@1: def avatar_file_path_for_user(username, filename): gremmie@1: return os.path.join(settings.AVATAR_DIR, 'users', username, filename) gremmie@1: gremmie@1: def avatar_file_path(instance, filename): gremmie@1: return avatar_file_path_for_user(instance.user.username, filename) gremmie@1: gremmie@1: gremmie@1: class UserProfile(models.Model): gremmie@1: """model to represent additional information about users""" gremmie@1: gremmie@1: user = models.ForeignKey(auth.models.User, unique=True) gremmie@1: location = models.CharField(max_length=128, blank=True) gremmie@1: birthday = models.DateField(blank=True, null=True, gremmie@1: help_text='Optional; the year is not shown to others') gremmie@1: occupation = models.CharField(max_length=128, blank=True) gremmie@1: interests = models.CharField(max_length=255, blank=True) gremmie@1: profile_text = models.TextField(blank=True) gremmie@1: profile_html = models.TextField(blank=True) gremmie@1: hide_email = models.BooleanField(default=True) gremmie@1: signature = models.TextField(blank=True) gremmie@1: signature_html = models.TextField(blank=True) gremmie@1: avatar = models.ImageField(upload_to=avatar_file_path, blank=True) bgneal@70: time_zone = models.CharField(max_length=64, blank=True, bgneal@70: default='US/Pacific') bgneal@120: use_24_time = models.BooleanField(default=False) bgneal@96: forum_post_count = models.IntegerField(default=0) gremmie@1: gremmie@1: def __unicode__(self): gremmie@1: return self.user.username gremmie@1: gremmie@1: class Meta: gremmie@1: ordering = ('user__username', ) gremmie@1: gremmie@1: def save(self, *args, **kwargs): bgneal@124: md = Markdown() bgneal@124: sm = Smilify() bgneal@124: self.profile_html = sm.convert(md.convert(self.profile_text)) bgneal@124: self.signature_html = sm.convert(md.convert(self.signature)) gremmie@1: super(UserProfile, self).save(*args, **kwargs) bgneal@54: cache.delete('avatar_' + self.user.username)