def shorten_body_filter postdata abstract_limit Make shorten body aka

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def shorten_body_filter(postdata, abstract_limit=3):
"""
Make shorten body (aka spoiler)
"""
soup = BeautifulSoup(postdata['body'])
ps = soup.findAll('p')
if len(ps) > abstract_limit+1:
postdata['spoiler'] = '\n'.join(unicode(p) for p in ps[:abstract_limit])
postdata['is_full_entry'] = False
else:
postdata['spoiler'] = postdata['body']
postdata['is_full_entry'] = True
return postdata