comparison forums/latest.py @ 792:7429c98c8ece

Issue #71: use relative URLs for smileys on the web and absolute for RSS.
author Brian Neal <bgneal@gmail.com>
date Mon, 26 May 2014 14:59:55 -0500
parents 89b240fe9297
children 90e8cc6eff77
comparison
equal deleted inserted replaced
791:0ca691cccf8d 792:7429c98c8ece
62 from forums.signals import post_content_update, topic_content_update 62 from forums.signals import post_content_update, topic_content_update
63 from forums.models import Forum, Topic, Post, Attachment 63 from forums.models import Forum, Topic, Post, Attachment
64 from forums.views.subscriptions import notify_topic_subscribers 64 from forums.views.subscriptions import notify_topic_subscribers
65 from forums.tools import auto_favorite, auto_subscribe 65 from forums.tools import auto_favorite, auto_subscribe
66 from core.services import get_redis_connection 66 from core.services import get_redis_connection
67 from core.markup import site_markup
67 68
68 # This constant controls how many latest posts per forum we store 69 # This constant controls how many latest posts per forum we store
69 MAX_POSTS = 50 70 MAX_POSTS = 50
70 71
71 # This controls how many updated topics we track 72 # This controls how many updated topics we track
451 452
452 def _serialize_post(post): 453 def _serialize_post(post):
453 """Serialize a post to JSON and return it. 454 """Serialize a post to JSON and return it.
454 455
455 """ 456 """
457 # Use absolute URLs for smileys for RSS. This means we have to reconvert the
458 # post Markdown to HTML.
459 content = site_markup(post.body, relative_urls=False)
460
456 # get any attachments for the post 461 # get any attachments for the post
457
458 attachments = Attachment.objects.filter(post=post).select_related( 462 attachments = Attachment.objects.filter(post=post).select_related(
459 'embed').order_by('order') 463 'embed').order_by('order')
460 embeds = [item.embed for item in attachments] 464 embeds = [item.embed for item in attachments]
461 if len(embeds) == 0: 465 if len(embeds):
462 content = post.html
463 else:
464 content = render_to_string('forums/post_rss.html', { 466 content = render_to_string('forums/post_rss.html', {
465 'post': post, 467 'content': content,
466 'embeds': embeds, 468 'embeds': embeds,
467 }) 469 })
468 470
469 # serialize post attributes 471 # serialize post attributes
470 post_content = { 472 post_content = {