示例#1
0
 def serialize(self):
     from helpers import shorten_text
     return {
         'id': self.post_id,
         'title': self.title,
         'date': self.date_posted.strftime('%d/%m/%Y'),
         'short_text': shorten_text(self.post_text)
     }
示例#2
0
def post_index():
    all_posts = Post.get_posts().order_by(Post.date_posted.desc()).\
        limit(config.POSTS_PER_PAGE)
    for item in all_posts:
        item.post_text = shorten_text(item.post_text)

    random_banner = Banner.select().\
        where(Banner.disabled == False).order_by(fn.Rand()).first()
    quote = Quote.select().order_by(fn.Rand()).first()
    messages = StreamMessage.select()

    template = env.get_template('post/index.html')
    return template.render(posts=all_posts, banner=random_banner,
                           stream_messages=messages,
                           quote=quote,
                           link_what='pstlink')