gremmie@1: """ gremmie@1: Models for the shoutbox application. gremmie@1: """ bgneal@151: import datetime bgneal@151: gremmie@1: from django.db import models gremmie@1: from django.contrib.auth.models import User bgneal@162: from django.utils.html import escape, urlize bgneal@151: bgneal@151: from smiley import smilify_html gremmie@1: bgneal@13: gremmie@1: class Shout(models.Model): bgneal@13: user = models.ForeignKey(User) bgneal@151: shout_date = models.DateTimeField(blank=True) bgneal@13: shout = models.TextField() bgneal@151: html = models.TextField() bgneal@151: bgneal@151: class Meta: bgneal@151: ordering = ('-shout_date', ) bgneal@151: bgneal@151: def __unicode__(self): bgneal@151: if len(self.shout) > 60: bgneal@151: return self.shout[:60] + "..." bgneal@151: return self.shout gremmie@1: bgneal@13: @models.permalink bgneal@13: def get_absolute_url(self): bgneal@13: return ('shoutbox-view', [str(self.id)]) gremmie@1: bgneal@151: def save(self, *args, **kwargs): bgneal@151: if not self.id: bgneal@151: self.shout_date = datetime.datetime.now() bgneal@791: self.html = urlize(smilify_html(escape(self.shout)), trim_url_limit=15, bgneal@151: nofollow=True) bgneal@151: super(Shout, self).save(*args, **kwargs) bgneal@13: bgneal@13: bgneal@13: class ShoutFlag(models.Model): bgneal@13: """This model represents a user flagging a shout as inappropriate.""" bgneal@13: user = models.ForeignKey(User) bgneal@13: shout = models.ForeignKey(Shout) bgneal@13: flag_date = models.DateTimeField(auto_now_add=True) bgneal@13: bgneal@13: def __unicode__(self): bgneal@13: return u'Shout ID %s flagged by %s' % (self.shout_id, self.user.username) bgneal@13: bgneal@13: class Meta: bgneal@13: ordering = ('flag_date', ) bgneal@13: bgneal@13: def get_shout_url(self): bgneal@151: return 'Shout #%(id)d' % ( bgneal@151: {'id': self.shout.id}) bgneal@13: get_shout_url.allow_tags = True bgneal@151: get_shout_url.short_description = 'Link to Shout' bgneal@13: