comparison gpp/bio/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 f8f4514b806a
children 48621ba5c385
comparison
equal deleted inserted replaced
123:3ae999b0c53b 124:9c18250972d5
6 import os.path 6 import os.path
7 7
8 from django.db import models 8 from django.db import models
9 from django.contrib import auth 9 from django.contrib import auth
10 from django.conf import settings 10 from django.conf import settings
11 from django.template.loader import render_to_string
12 from django.core.cache import cache 11 from django.core.cache import cache
12
13 from core.markup import Markdown
14 from smiley import Smilify
13 15
14 16
15 def avatar_file_path_for_user(username, filename): 17 def avatar_file_path_for_user(username, filename):
16 return os.path.join(settings.AVATAR_DIR, 'users', username, filename) 18 return os.path.join(settings.AVATAR_DIR, 'users', username, filename)
17 19
44 46
45 class Meta: 47 class Meta:
46 ordering = ('user__username', ) 48 ordering = ('user__username', )
47 49
48 def save(self, *args, **kwargs): 50 def save(self, *args, **kwargs):
49 html = render_to_string('bio/markdown.html', {'data': self.profile_text}) 51 md = Markdown()
50 self.profile_html = html.strip() 52 sm = Smilify()
51 html = render_to_string('bio/markdown.html', {'data': self.signature}) 53 self.profile_html = sm.convert(md.convert(self.profile_text))
52 self.signature_html = html.strip() 54 self.signature_html = sm.convert(md.convert(self.signature))
53 super(UserProfile, self).save(*args, **kwargs) 55 super(UserProfile, self).save(*args, **kwargs)
54 cache.delete('avatar_' + self.user.username) 56 cache.delete('avatar_' + self.user.username)
55