Mercurial > public > sg101
comparison gpp/shoutbox/models.py @ 151:e1d1a70d312d
Implement #43, various shoutbox improvements.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 18 Dec 2009 04:30:49 +0000 |
parents | 777451a98f9d |
children | 6a5bdcf93ad3 |
comparison
equal
deleted
inserted
replaced
150:b43e1288ff80 | 151:e1d1a70d312d |
---|---|
1 """ | 1 """ |
2 Models for the shoutbox application. | 2 Models for the shoutbox application. |
3 """ | 3 """ |
4 import datetime | |
5 | |
4 from django.db import models | 6 from django.db import models |
5 from django.contrib.auth.models import User | 7 from django.contrib.auth.models import User |
8 from django.utils.html import urlize | |
9 | |
10 from smiley import smilify_html | |
6 | 11 |
7 | 12 |
8 class Shout(models.Model): | 13 class Shout(models.Model): |
9 user = models.ForeignKey(User) | 14 user = models.ForeignKey(User) |
10 shout_date = models.DateTimeField(auto_now_add=True) | 15 shout_date = models.DateTimeField(blank=True) |
11 shout = models.TextField() | 16 shout = models.TextField() |
17 html = models.TextField() | |
18 | |
19 class Meta: | |
20 ordering = ('-shout_date', ) | |
21 | |
22 def __unicode__(self): | |
23 if len(self.shout) > 60: | |
24 return self.shout[:60] + "..." | |
25 return self.shout | |
12 | 26 |
13 @models.permalink | 27 @models.permalink |
14 def get_absolute_url(self): | 28 def get_absolute_url(self): |
15 return ('shoutbox-view', [str(self.id)]) | 29 return ('shoutbox-view', [str(self.id)]) |
16 | 30 |
17 def __unicode__(self): | 31 def save(self, *args, **kwargs): |
18 shout = self.shout[:60] | 32 if not self.id: |
19 return u'Shout from %s: %s' % (self.user.username, shout) | 33 self.shout_date = datetime.datetime.now() |
20 | 34 self.html = urlize(smilify_html(self.shout), trim_url_limit=15, |
21 class Meta: | 35 nofollow=True) |
22 ordering = ('-shout_date', ) | 36 super(Shout, self).save(*args, **kwargs) |
23 | 37 |
24 | 38 |
25 class ShoutFlag(models.Model): | 39 class ShoutFlag(models.Model): |
26 """This model represents a user flagging a shout as inappropriate.""" | 40 """This model represents a user flagging a shout as inappropriate.""" |
27 user = models.ForeignKey(User) | 41 user = models.ForeignKey(User) |
33 | 47 |
34 class Meta: | 48 class Meta: |
35 ordering = ('flag_date', ) | 49 ordering = ('flag_date', ) |
36 | 50 |
37 def get_shout_url(self): | 51 def get_shout_url(self): |
38 return '<a href="/admin/shoutbox/shout/%s">Shout</a>' % self.shout.id | 52 return '<a href="/admin/shoutbox/shout/%(id)d">Shout #%(id)d</a>' % ( |
53 {'id': self.shout.id}) | |
39 get_shout_url.allow_tags = True | 54 get_shout_url.allow_tags = True |
55 get_shout_url.short_description = 'Link to Shout' | |
40 | 56 |
41 # vim: ts=4 sw=4 |