Mercurial > public > sg101
annotate gpp/smiley/models.py @ 58:02e5dfa830cc
#11 Update Blueprints to 0.9. Also update the conditional IE specific include of the ie.css file. Hopefully this will resolve some issues seen with IE8.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 24 Jun 2009 00:18:53 +0000 |
parents | 8eb9b8d014a2 |
children | 3ae999b0c53b |
rev | line source |
---|---|
gremmie@1 | 1 """ |
gremmie@1 | 2 Models for the smiley application. |
gremmie@1 | 3 """ |
gremmie@1 | 4 from django.db import models |
gremmie@1 | 5 |
gremmie@1 | 6 |
gremmie@1 | 7 class SmileyManager(models.Manager): |
gremmie@1 | 8 smiley_map = None |
gremmie@1 | 9 smilies = None |
gremmie@1 | 10 |
gremmie@1 | 11 def get_smiley_map(self): |
gremmie@1 | 12 if self.smiley_map is None: |
gremmie@1 | 13 smilies = self.all() |
gremmie@1 | 14 self.smiley_map = {} |
gremmie@1 | 15 for s in smilies: |
gremmie@1 | 16 self.smiley_map[s.code] = s.html() |
gremmie@1 | 17 return self.smiley_map |
gremmie@1 | 18 |
gremmie@1 | 19 def get_smilies(self): |
gremmie@1 | 20 if self.smilies is None: |
gremmie@1 | 21 self.smilies = self.all() |
gremmie@1 | 22 return self.smilies |
gremmie@1 | 23 |
gremmie@1 | 24 def clear_cache(self): |
gremmie@1 | 25 self.smiley_map = None |
bgneal@17 | 26 self.smilies = None |
gremmie@1 | 27 |
gremmie@1 | 28 |
gremmie@1 | 29 class Smiley(models.Model): |
gremmie@1 | 30 image = models.ImageField(upload_to='smiley/images/') |
gremmie@1 | 31 title = models.CharField(max_length=32) |
gremmie@1 | 32 code = models.CharField(max_length=32) |
gremmie@1 | 33 |
gremmie@1 | 34 objects = SmileyManager() |
gremmie@1 | 35 |
gremmie@1 | 36 class Meta: |
gremmie@1 | 37 verbose_name_plural = 'Smilies' |
gremmie@1 | 38 ordering = ('title', ) |
gremmie@1 | 39 |
gremmie@1 | 40 def __unicode__(self): |
gremmie@1 | 41 return self.title |
gremmie@1 | 42 |
gremmie@1 | 43 def get_absolute_url(self): |
gremmie@1 | 44 return self.image.url |
gremmie@1 | 45 |
gremmie@1 | 46 def html(self): |
gremmie@1 | 47 if self.image: |
gremmie@1 | 48 return u'<img src="%s" alt="%s" title="%s" />' % \ |
gremmie@1 | 49 (self.get_absolute_url(), self.title, self.title) |
gremmie@1 | 50 return u'' |
gremmie@1 | 51 html.allow_tags = True |
gremmie@1 | 52 |