comparison smiley/models.py @ 613:0729c73d5761

For issue #18, use absolute URLs to the smilies for RSS readers.
author Brian Neal <bgneal@gmail.com>
date Sat, 01 Sep 2012 15:17:40 -0500
parents ee87ea74d46b
children 7429c98c8ece
comparison
equal deleted inserted replaced
612:5be850a66dfc 613:0729c73d5761
3 """ 3 """
4 import re 4 import re
5 5
6 from django.db import models 6 from django.db import models
7 from django.core.cache import cache 7 from django.core.cache import cache
8 from django.contrib.sites.models import Site
8 9
9 CACHE_TIMEOUT = 60 * 60 # seconds 10 CACHE_TIMEOUT = 60 * 60 # seconds
10 11
11 12
12 class SmileyManager(models.Manager): 13 class SmileyManager(models.Manager):
73 return self.image.url 74 return self.image.url
74 75
75 def html(self): 76 def html(self):
76 """Returns a HTML img tag representation of the smiley.""" 77 """Returns a HTML img tag representation of the smiley."""
77 if self.image: 78 if self.image:
78 return (u'<img src="%s" alt="%s" title="%s" />' % 79 site = Site.objects.get_current()
79 (self.get_absolute_url(), self.title, self.title)) 80 return (u'<img src="http://%s%s" alt="%s" title="%s" />' %
81 (site.domain, self.get_absolute_url(), self.title, self.title))
80 return u'' 82 return u''
81 html.allow_tags = True 83 html.allow_tags = True
82 84
83 def markdown(self): 85 def markdown(self):
84 """Returns a markdown representation of the smiley.""" 86 """Returns a markdown representation of the smiley."""
85 if self.image: 87 if self.image:
86 return (u'![%s](%s "%s")' % 88 site = Site.objects.get_current()
87 (self.title, self.get_absolute_url(), self.title)) 89 return (u'![%s](http://%s%s "%s")' %
90 (self.title, site.domain, self.get_absolute_url(), self.title))
88 return u'' 91 return u''