added Markdown/HTML support for news items
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Sun, 1 Mar 2009 21:18:17 +0000 (21:18 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Sun, 1 Mar 2009 21:18:17 +0000 (21:18 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@131 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/models.py
conifer/templates/welcome.xhtml

index 51f5e0e..dfc6553 100644 (file)
@@ -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))
+            
index 9da242e..dac15ff 100644 (file)
@@ -12,7 +12,7 @@ title = 'Welcome!'
   <h1>News</h1>
   <div class="newsitem" py:for="news in models.NewsItem.objects.all().order_by('-published')[0:5]">
     <h2>${news.subject}</h2>
-    <div>${news.body}</div>
+    <div>${news.generated_body()}</div>
   </div>
 </body>
 </html>