comparison gpp/forums/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 19b64e8f02a2
children 48621ba5c385
comparison
equal deleted inserted replaced
123:3ae999b0c53b 124:9c18250972d5
4 import datetime 4 import datetime
5 5
6 from django.db import models 6 from django.db import models
7 from django.db.models import Q 7 from django.db.models import Q
8 from django.contrib.auth.models import User, Group 8 from django.contrib.auth.models import User, Group
9 from django.template.loader import render_to_string 9 from core.markup import markdown
10 from smiley import smilify
10 11
11 12
12 POST_EDIT_DELTA = datetime.timedelta(seconds=3) 13 POST_EDIT_DELTA = datetime.timedelta(seconds=3)
13 14
14 15
249 250
250 def __unicode__(self): 251 def __unicode__(self):
251 return self.summary() 252 return self.summary()
252 253
253 def save(self, *args, **kwargs): 254 def save(self, *args, **kwargs):
254 html = render_to_string('forums/post.html', {'data': self.body}) 255 self.html = smilify(markdown(self.body))
255 self.html = html.strip()
256 super(Post, self).save(*args, **kwargs) 256 super(Post, self).save(*args, **kwargs)
257 257
258 def delete(self, *args, **kwargs): 258 def delete(self, *args, **kwargs):
259 first_post_id = self.topic.posts.all()[0].id 259 first_post_id = self.topic.posts.all()[0].id
260 super(Post, self).delete(*args, **kwargs) 260 super(Post, self).delete(*args, **kwargs)