Mercurial > public > sg101
comparison gpp/downloads/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 | a5f27f25fa52 |
children | 48621ba5c385 |
comparison
equal
deleted
inserted
replaced
123:3ae999b0c53b | 124:9c18250972d5 |
---|---|
4 import os | 4 import os |
5 | 5 |
6 import datetime | 6 import datetime |
7 from django.db import models | 7 from django.db import models |
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.template.defaultfilters import filesizeformat | 9 from django.template.defaultfilters import filesizeformat |
10 | |
11 from core.markup import markdown | |
12 from smiley import smilify | |
11 | 13 |
12 | 14 |
13 class Category(models.Model): | 15 class Category(models.Model): |
14 """Downloads belong to categories.""" | 16 """Downloads belong to categories.""" |
15 title = models.CharField(max_length=64) | 17 title = models.CharField(max_length=64) |
70 @models.permalink | 72 @models.permalink |
71 def get_absolute_url(self): | 73 def get_absolute_url(self): |
72 return ('downloads-details', [str(self.id)]) | 74 return ('downloads-details', [str(self.id)]) |
73 | 75 |
74 def save(self, force_insert=False, force_update=False): | 76 def save(self, force_insert=False, force_update=False): |
75 html = render_to_string('downloads/markdown.html', {'data': self.description}) | 77 self.html = smilify(markdown(self.description)) |
76 self.html = html.strip() | |
77 super(Download, self).save(force_insert, force_update) | 78 super(Download, self).save(force_insert, force_update) |
78 | 79 |
79 def vote(self, vote_value): | 80 def vote(self, vote_value): |
80 """receives a vote_value and updates internal score accordingly""" | 81 """receives a vote_value and updates internal score accordingly""" |
81 total_score = self.average_score * self.total_votes | 82 total_score = self.average_score * self.total_votes |