comparison gpp/smiley/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 8eb9b8d014a2
comparison
equal deleted inserted replaced
0:900ba3c7b765 1:dbd703f7d63a
1 """
2 Models for the smiley application.
3 """
4 from django.db import models
5
6
7 class SmileyManager(models.Manager):
8 smiley_map = None
9 smilies = None
10
11 def get_smiley_map(self):
12 if self.smiley_map is None:
13 smilies = self.all()
14 self.smiley_map = {}
15 for s in smilies:
16 self.smiley_map[s.code] = s.html()
17 return self.smiley_map
18
19 def get_smilies(self):
20 if self.smilies is None:
21 self.smilies = self.all()
22 return self.smilies
23
24 def clear_cache(self):
25 self.smiley_map = None
26 self.smileis = None
27
28
29 class Smiley(models.Model):
30 image = models.ImageField(upload_to='smiley/images/')
31 title = models.CharField(max_length=32)
32 code = models.CharField(max_length=32)
33
34 objects = SmileyManager()
35
36 class Meta:
37 verbose_name_plural = 'Smilies'
38 ordering = ('title', )
39
40 def __unicode__(self):
41 return self.title
42
43 def get_absolute_url(self):
44 return self.image.url
45
46 def html(self):
47 if self.image:
48 return u'<img src="%s" alt="%s" title="%s" />' % \
49 (self.get_absolute_url(), self.title, self.title)
50 return u''
51 html.allow_tags = True
52