comparison gpp/comments/models.py @ 124:9c18250972d5

Refactored the markdown/smiley logic. Created classes for Markdown and Smilify. No longer call render_to_string() in models.py for various models.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Nov 2009 04:32:32 +0000
parents d0d779dd0832
children 48621ba5c385
comparison
equal deleted inserted replaced
123:3ae999b0c53b 124:9c18250972d5
4 from django.db import models 4 from django.db import models
5 from django.conf import settings 5 from django.conf import settings
6 from django.contrib.contenttypes.models import ContentType 6 from django.contrib.contenttypes.models import ContentType
7 from django.contrib.contenttypes import generic 7 from django.contrib.contenttypes import generic
8 from django.contrib.auth.models import User 8 from django.contrib.auth.models import User
9 from django.template.loader import render_to_string
10 from django.core import urlresolvers 9 from django.core import urlresolvers
10
11 from core.markup import markdown
12 from smiley import smilify
11 13
12 14
13 COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000) 15 COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000)
14 16
15 class CommentManager(models.Manager): 17 class CommentManager(models.Manager):
49 51
50 def __unicode__(self): 52 def __unicode__(self):
51 return u'%s: %s...' % (self.user.username, self.comment[:50]) 53 return u'%s: %s...' % (self.user.username, self.comment[:50])
52 54
53 def save(self, force_insert=False, force_update=False): 55 def save(self, force_insert=False, force_update=False):
54 html = render_to_string('comments/markdown.html', {'data': self.comment}) 56 self.html = smilify(markdown(self.comment))
55 self.html = html.strip()
56 super(Comment, self).save(force_insert, force_update) 57 super(Comment, self).save(force_insert, force_update)
57 58
58 def get_absolute_url(self): 59 def get_absolute_url(self):
59 return self.get_content_object_url() + ('#c%s' % self.id) 60 return self.get_content_object_url() + ('#c%s' % self.id)
60 61