[open-ils-commits] r131 - in servres/trunk/conifer: syrup templates (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Mar 1 16:18:22 EST 2009


Author: gfawcett
Date: 2009-03-01 16:18:17 -0500 (Sun, 01 Mar 2009)
New Revision: 131

Modified:
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/templates/welcome.xhtml
Log:
added Markdown/HTML support for news items

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-03-01 19:21:43 UTC (rev 130)
+++ servres/trunk/conifer/syrup/models.py	2009-03-01 21:18:17 UTC (rev 131)
@@ -2,6 +2,7 @@
 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,7 +354,16 @@
             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)
     body = m.TextField()
@@ -363,3 +373,12 @@
                                       ('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))
+            

Modified: servres/trunk/conifer/templates/welcome.xhtml
===================================================================
--- servres/trunk/conifer/templates/welcome.xhtml	2009-03-01 19:21:43 UTC (rev 130)
+++ servres/trunk/conifer/templates/welcome.xhtml	2009-03-01 21:18:17 UTC (rev 131)
@@ -12,7 +12,7 @@
   <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>



More information about the open-ils-commits mailing list