Commits

Anonymous committed 6416718

Make truncated post prettier by render html markup

Comments (0)

Files changed (1)

 # Create your models here.
 import datetime
 import markdown
+import re
 
 class Post(db.Model):
     title = db.StringProperty()
                                                    self.key())
 
     def trunc_body(self):
-        if len(self.body) > 500:
-            return self.body[:500].rsplit(' ', 1)[0]+'...'+'<a href="'+self.get_absolute_url()+'">Read More</a>'
+        # remove image
+        p = re.compile(r'<img.*?>')
+        body = p.sub('', self.body_html)
+        if len(body) > 500:
+            return body[:500].rsplit(' ', 1)[0]+'...'+'<a href="'+self.get_absolute_url()+'">Read More</a>'
         else:
-            return self.body
+            return body
 
 
     def put(self):