Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:900ba3c7b765 | 1:dbd703f7d63a |
---|---|
1 """ | |
2 Contains models for the bio application. | |
3 I would have picked profile for this application, but that is already taken, apparently. | |
4 """ | |
5 | |
6 import os.path | |
7 | |
8 from django.db import models | |
9 from django.contrib import auth | |
10 from django.conf import settings | |
11 from django.template.loader import render_to_string | |
12 | |
13 | |
14 def avatar_file_path_for_user(username, filename): | |
15 return os.path.join(settings.AVATAR_DIR, 'users', username, filename) | |
16 | |
17 def avatar_file_path(instance, filename): | |
18 return avatar_file_path_for_user(instance.user.username, filename) | |
19 | |
20 | |
21 class UserProfile(models.Model): | |
22 """model to represent additional information about users""" | |
23 | |
24 user = models.ForeignKey(auth.models.User, unique=True) | |
25 location = models.CharField(max_length=128, blank=True) | |
26 birthday = models.DateField(blank=True, null=True, | |
27 help_text='Optional; the year is not shown to others') | |
28 occupation = models.CharField(max_length=128, blank=True) | |
29 interests = models.CharField(max_length=255, blank=True) | |
30 website_1 = models.URLField(verify_exists=False, blank=True) | |
31 website_2 = models.URLField(verify_exists=False, blank=True) | |
32 website_3 = models.URLField(verify_exists=False, blank=True) | |
33 profile_text = models.TextField(blank=True) | |
34 profile_html = models.TextField(blank=True) | |
35 hide_email = models.BooleanField(default=True) | |
36 icq = models.CharField('ICQ', max_length=15, blank=True) | |
37 aim = models.CharField('AIM', max_length=18, blank=True) | |
38 yim = models.CharField('YIM', max_length=25, blank=True) | |
39 msnm = models.CharField('MSN', max_length=25, blank=True) | |
40 twitter = models.CharField(max_length=64, blank=True) | |
41 signature = models.TextField(blank=True) | |
42 signature_html = models.TextField(blank=True) | |
43 avatar = models.ImageField(upload_to=avatar_file_path, blank=True) | |
44 | |
45 def __unicode__(self): | |
46 return self.user.username | |
47 | |
48 class Meta: | |
49 ordering = ('user__username', ) | |
50 | |
51 def save(self, *args, **kwargs): | |
52 html = render_to_string('bio/markdown.html', {'data': self.profile_text}) | |
53 self.profile_html = html.strip() | |
54 html = render_to_string('bio/markdown.html', {'data': self.signature}) | |
55 self.signature_html = html.strip() | |
56 super(UserProfile, self).save(*args, **kwargs) | |
57 | |
58 # vim: ts=4 sw=4 |