From: gfawcett Date: Sun, 1 Mar 2009 21:18:17 +0000 (+0000) Subject: added Markdown/HTML support for news items X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b44f54cea79bc5128165d39144f071fe23a6baa9;p=Syrup.git added Markdown/HTML support for news items git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@131 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 51f5e0e..dfc6553 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -2,6 +2,7 @@ from django.db import models as m from django.contrib.auth.models import User from django.contrib.auth.models import AnonymousUser from datetime import datetime +from genshi import Markup import re def highlight(text, phrase, @@ -353,6 +354,15 @@ class Item(m.Model): return self.course.course_url() #------------------------------------------------------------ +# News items + +try: + import markdown + def do_markdown(txt): + return markdown.markdown(txt) +except ImportError: + def do_markdown(txt): + return '(Markdown not installed).' class NewsItem(m.Model): subject = m.CharField(max_length=200) @@ -363,3 +373,12 @@ class NewsItem(m.Model): ('html', 'html'), ('markdown', 'markdown')), default = 'html') + + def generated_body(self): + if self.encoding == 'plain': + return self.body + elif self.encoding == 'html': + return Markup(self.body) + elif self.encoding == 'markdown': + return Markup(do_markdown(self.body)) + diff --git a/conifer/templates/welcome.xhtml b/conifer/templates/welcome.xhtml index 9da242e..dac15ff 100644 --- a/conifer/templates/welcome.xhtml +++ b/conifer/templates/welcome.xhtml @@ -12,7 +12,7 @@ title = 'Welcome!'

News

${news.subject}

-
${news.body}
+
${news.generated_body()}