~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlprofile/models.py

  • Committer: Holger Rapp
  • Date: 2009-03-15 16:40:37 UTC
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: sirver@kallisto.local-20090315164037-6sbx3vlo089d46e8
Added support for profiles. No gravatar yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.db import models
 
2
from django.contrib.auth.models import User
 
3
from fields import AutoOneToOneField, ExtendedImageField
 
4
from django.utils.translation import ugettext_lazy as _
 
5
import settings
 
6
 
 
7
TZ_CHOICES = [(float(x[0]), x[1]) for x in (
 
8
    (-12, '-12'), (-11, '-11'), (-10, '-10'), (-9.5, '-09.5'), (-9, '-09'),
 
9
    (-8.5, '-08.5'), (-8, '-08 PST'), (-7, '-07 MST'), (-6, '-06 CST'),
 
10
    (-5, '-05 EST'), (-4, '-04 AST'), (-3.5, '-03.5'), (-3, '-03 ADT'),
 
11
    (-2, '-02'), (-1, '-01'), (0, '00 GMT'), (1, '+01 CET'), (2, '+02'),
 
12
    (3, '+03'), (3.5, '+03.5'), (4, '+04'), (4.5, '+04.5'), (5, '+05'),
 
13
    (5.5, '+05.5'), (6, '+06'), (6.5, '+06.5'), (7, '+07'), (8, '+08'),
 
14
    (9, '+09'), (9.5, '+09.5'), (10, '+10'), (10.5, '+10.5'), (11, '+11'),
 
15
    (11.5, '+11.5'), (12, '+12'), (13, '+13'), (14, '+14'),
 
16
)]
 
17
 
 
18
class Profile(models.Model):
 
19
    user = AutoOneToOneField(User, related_name='wlprofile', verbose_name=_('User'))
 
20
 
 
21
    # Web related fields.
 
22
    site = models.URLField(_('Site'), verify_exists=False, blank=True, default='')
 
23
    jabber = models.CharField(_('Jabber'), max_length=80, blank=True, default='')
 
24
    icq = models.CharField(_('ICQ'), max_length=12, blank=True, default='')
 
25
    msn = models.CharField(_('MSN'), max_length=80, blank=True, default='')
 
26
    aim = models.CharField(_('AIM'), max_length=80, blank=True, default='')
 
27
    yahoo = models.CharField(_('Yahoo'), max_length=80, blank=True, default='')
 
28
 
 
29
    # Personal Informations
 
30
    location = models.CharField(_('Location'), max_length=30, blank=True, default='')
 
31
 
 
32
    # Configuration for Forum/Site
 
33
    time_zone = models.FloatField(_('Time zone'), choices=TZ_CHOICES, default=float(settings.DEFAULT_TIME_ZONE))
 
34
    time_display = models.CharField(_('Time display'), max_length=80, default="%c")
 
35
    signature = models.TextField(_('Signature'), blank=True, default='', max_length=settings.SIGNATURE_MAX_LENGTH)
 
36
    # language = models.CharField(_('Language'), max_length=10, blank=True, default='',
 
37
    #                             choices=settings.LANGUAGES)
 
38
 
 
39
    avatar = ExtendedImageField(_('Avatar'), blank=True, default='', upload_to=settings.AVATARS_UPLOAD_TO, width=settings.AVATAR_WIDTH, height=settings.AVATAR_HEIGHT)
 
40
    show_signatures = models.BooleanField(_('Show signatures'), blank=True, default=True)
 
41
    # markup = models.CharField(_('Default markup'), max_length=15, default=settings.DEFAULT_MARKUP, choices=MARKUP_CHOICES)
 
42
 
 
43
    class Meta:
 
44
        verbose_name = _('Profile')
 
45
        verbose_name_plural = _('Profiles')
 
46
 
 
47
 
 
48
    def unread_pm_count(self):
 
49
        return PrivateMessage.objects.filter(dst_user=self, read=False).count()
 
50
 
 
51
    def post_count(self):
 
52
        """
 
53
        Return the nr of posts the user has. This uses djangos filter feature
 
54
        will therefore hit the database. This should maybe be reworked when the 
 
55
        database grows to not be always calculated.
 
56
        """
 
57
        return Post.objects.filter(user=self.user).count()
 
58