comparison gpp/messages/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 dbd703f7d63a
children 48621ba5c385
comparison
equal deleted inserted replaced
123:3ae999b0c53b 124:9c18250972d5
2 2
3 import datetime 3 import datetime
4 from django.db import models 4 from django.db import models
5 from django.db.models import Q 5 from django.db.models import Q
6 from django.contrib.auth.models import User 6 from django.contrib.auth.models import User
7 from django.template.loader import render_to_string 7 from core.markup import markdown
8 from smiley import smilify
8 9
9 10
10 class MessageManager(models.Manager): 11 class MessageManager(models.Manager):
11 """The manager for the Message model. Provides convenience functions.""" 12 """The manager for the Message model. Provides convenience functions."""
12 13
60 return False 61 return False
61 62
62 def save(self, force_insert = False, force_update = False): 63 def save(self, force_insert = False, force_update = False):
63 if not self.id: 64 if not self.id:
64 self.send_date = datetime.datetime.now() 65 self.send_date = datetime.datetime.now()
65 html = render_to_string('messages/markdown.html', {'data': self.message}) 66 self.html = smilify(markdown(self.message))
66 self.html = html.strip()
67 super(Message, self).save(force_insert, force_update) 67 super(Message, self).save(force_insert, force_update)
68 68
69 @models.permalink 69 @models.permalink
70 def get_absolute_url(self): 70 def get_absolute_url(self):
71 return ('messages.views.view', [str(self.id)]) 71 return ('messages.views.view', [str(self.id)])