annotate gpp/bio/models.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children 5eed5e7c1c98
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
gremmie@1 11 from django.template.loader import render_to_string
gremmie@1 12
gremmie@1 13
gremmie@1 14 def avatar_file_path_for_user(username, filename):
gremmie@1 15 return os.path.join(settings.AVATAR_DIR, 'users', username, filename)
gremmie@1 16
gremmie@1 17 def avatar_file_path(instance, filename):
gremmie@1 18 return avatar_file_path_for_user(instance.user.username, filename)
gremmie@1 19
gremmie@1 20
gremmie@1 21 class UserProfile(models.Model):
gremmie@1 22 """model to represent additional information about users"""
gremmie@1 23
gremmie@1 24 user = models.ForeignKey(auth.models.User, unique=True)
gremmie@1 25 location = models.CharField(max_length=128, blank=True)
gremmie@1 26 birthday = models.DateField(blank=True, null=True,
gremmie@1 27 help_text='Optional; the year is not shown to others')
gremmie@1 28 occupation = models.CharField(max_length=128, blank=True)
gremmie@1 29 interests = models.CharField(max_length=255, blank=True)
gremmie@1 30 website_1 = models.URLField(verify_exists=False, blank=True)
gremmie@1 31 website_2 = models.URLField(verify_exists=False, blank=True)
gremmie@1 32 website_3 = models.URLField(verify_exists=False, 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 icq = models.CharField('ICQ', max_length=15, blank=True)
gremmie@1 37 aim = models.CharField('AIM', max_length=18, blank=True)
gremmie@1 38 yim = models.CharField('YIM', max_length=25, blank=True)
gremmie@1 39 msnm = models.CharField('MSN', max_length=25, blank=True)
gremmie@1 40 twitter = models.CharField(max_length=64, blank=True)
gremmie@1 41 signature = models.TextField(blank=True)
gremmie@1 42 signature_html = models.TextField(blank=True)
gremmie@1 43 avatar = models.ImageField(upload_to=avatar_file_path, blank=True)
gremmie@1 44
gremmie@1 45 def __unicode__(self):
gremmie@1 46 return self.user.username
gremmie@1 47
gremmie@1 48 class Meta:
gremmie@1 49 ordering = ('user__username', )
gremmie@1 50
gremmie@1 51 def save(self, *args, **kwargs):
gremmie@1 52 html = render_to_string('bio/markdown.html', {'data': self.profile_text})
gremmie@1 53 self.profile_html = html.strip()
gremmie@1 54 html = render_to_string('bio/markdown.html', {'data': self.signature})
gremmie@1 55 self.signature_html = html.strip()
gremmie@1 56 super(UserProfile, self).save(*args, **kwargs)
gremmie@1 57
gremmie@1 58 # vim: ts=4 sw=4