Ejemplo n.º 1
0
 def render_body(self, remove_more=True):
     """
     Parses the body content to convert bbcode & my tags into html. All old posts
     are written in HTML format so we give the option of formatting posts either
     way and returning the appropriate data for output.
     """       
     if self.body == '' or self.body is None:            
         if self.format == 'bbcode':
             return bb2xhtml(self.teaser)
         else:
             return self.teaser
     if self.format == 'html':          
         return self.body
     else:           
         images = self.images_mapped()        
         body = bb2xhtml(self.body)        
         if remove_more:
             body = body.replace('[readmore]', '')            
         for index in images:                
             if images[index].link:
                 repl = '<a href="%s"><img class="news-inline-image" src="%s" alt="%s image" /></a>' \
                     % (images[index].link, images[index].image.url, self.title)
             else:
                 repl = '<img src="%s" class="news-inline-image" alt="%s image" />' \
                     % (images[index].image.url, self.title)
             body = re.sub(r'(\[\[image-%s\]\])' \
                 % (int(index)+1).__str__(), repl, body)
         
         return mark_safe(body)        
Ejemplo n.º 2
0
 def actual_teaser(self):
     """ Returns the summary content based on the post. If there is a
     teaser defined that is used otherwise it checks if the post has
     a [[more]] tag and returns the first part of the match. Finally
     it will trim it to a certain word length. """
     if self.teaser:
         if self.format == 'bbcode':
              print "render bbcode"
              return bb2xhtml(self.teaser)
         else:
              return self.teaser            
     else:
         clean_body = self.clean_body
         match_split = self.split_body
         if len(match_split) == 3: # we have 1 [[more]] tag
             return match_split[0]
         else:
             return ' '.join(clean_body.split(' ')[:settings.NEWS['AUTO_TEASER_LENGTH']])