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 gremmie@1: from django.template.loader import render_to_string bgneal@54: from django.core.cache import cache gremmie@1: 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') 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): gremmie@1: html = render_to_string('bio/markdown.html', {'data': self.profile_text}) gremmie@1: self.profile_html = html.strip() gremmie@1: html = render_to_string('bio/markdown.html', {'data': self.signature}) gremmie@1: self.signature_html = html.strip() gremmie@1: super(UserProfile, self).save(*args, **kwargs) bgneal@54: cache.delete('avatar_' + self.user.username) gremmie@1: