Mercurial > public > sg101
comparison forums/latest.py @ 594:2469d5864249
Include links to video attachments in forum post RSS feeds.
This is for bitbucket issue #9.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 22 May 2012 19:53:39 -0500 |
parents | ee87ea74d46b |
children | f3fded5df64b |
comparison
equal
deleted
inserted
replaced
593:302db5b46ec9 | 594:2469d5864249 |
---|---|
14 import logging | 14 import logging |
15 import time | 15 import time |
16 | 16 |
17 from django.dispatch import receiver | 17 from django.dispatch import receiver |
18 from django.utils import simplejson | 18 from django.utils import simplejson |
19 from django.template.loader import render_to_string | |
19 import redis | 20 import redis |
20 | 21 |
21 from forums.signals import post_content_update, topic_content_update | 22 from forums.signals import post_content_update, topic_content_update |
22 from forums.models import Forum, Topic, Post | 23 from forums.models import Forum, Topic, Post, Attachment |
23 from forums.views.subscriptions import notify_topic_subscribers | 24 from forums.views.subscriptions import notify_topic_subscribers |
24 from forums.tools import auto_favorite, auto_subscribe | 25 from forums.tools import auto_favorite, auto_subscribe |
25 from core.services import get_redis_connection | 26 from core.services import get_redis_connection |
26 | 27 |
27 # This constant controls how many latest posts per forum we store | 28 # This constant controls how many latest posts per forum we store |
88 def _update_post_feeds(conn, post): | 89 def _update_post_feeds(conn, post): |
89 """ | 90 """ |
90 Updates the forum feeds we keep in Redis so that our RSS feeds are quick. | 91 Updates the forum feeds we keep in Redis so that our RSS feeds are quick. |
91 | 92 |
92 """ | 93 """ |
94 # get any attachments for the post | |
95 | |
96 attachments = Attachment.objects.filter(post=post).select_related( | |
97 'embed').order_by('order') | |
98 embeds = [item.embed for item in attachments] | |
99 if len(embeds) == 0: | |
100 content = post.html | |
101 else: | |
102 content = render_to_string('forums/post_rss.html', { | |
103 'post': post, | |
104 'embeds': embeds, | |
105 }) | |
106 | |
93 # serialize post attributes | 107 # serialize post attributes |
94 post_content = { | 108 post_content = { |
95 'id': post.id, | 109 'id': post.id, |
96 'title': post.topic.name, | 110 'title': post.topic.name, |
97 'content': post.html, | 111 'content': content, |
98 'author': post.user.username, | 112 'author': post.user.username, |
99 'pubdate': int(time.mktime(post.creation_date.timetuple())), | 113 'pubdate': int(time.mktime(post.creation_date.timetuple())), |
100 'forum_name': post.topic.forum.name, | 114 'forum_name': post.topic.forum.name, |
101 'url': post.get_absolute_url() | 115 'url': post.get_absolute_url() |
102 } | 116 } |