This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Sinchok
committed
Jun 9, 2014
1 parent
52de1db
commit 520da22
Showing
7 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% load betty %}<?xml version="1.0" encoding="utf-8"?> | ||
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"> | ||
<channel> | ||
<title>{{ title|default:"RSS Feed"}}</title> | ||
<link>{{ search_url }}</link> | ||
<description>{{ description|default:"RSS Feed"}}</description> | ||
<atom:link href="{{ feed_url|escape }}" rel="self"></atom:link> | ||
<lastBuildDate>{{ build_date|date:"D, d M Y H:i:s O" }}</lastBuildDate> | ||
{% for content in page_obj.object_list %}<item> | ||
<title>{{ content.feature_type }}: {{ content.title|striptags }}</title> | ||
{% if content.authors.all %}<author>{% for author in content.authors.all %}{{ author.get_full_name }}{% if not forloop.last %}, {% endif %}{% endfor%}</author>{% endif %} | ||
<link>{{ content.feed_url }}</link> | ||
<description> | ||
<![CDATA[ | ||
{{ content.description|safe }} | ||
]]> | ||
</description> | ||
{% if full %} | ||
<content:encoded> | ||
{{ content.description|safe }} | ||
</content:encoded> | ||
{% endif %} | ||
<pubDate>{{ content.published|date:"D, d M Y H:i:s O" }}</pubDate> | ||
<guid>{{ content.feed_url }}</guid> | ||
</item>{% endfor%} | ||
</channel> | ||
</rss> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf.urls import url, patterns | ||
|
||
from .views import RSSView | ||
|
||
|
||
urlpatterns = patterns("", | ||
url(r"^rss", RSSView.as_view(), name="rss-feed") # noqa | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.template import RequestContext | ||
from django.utils.timezone import now | ||
from django.views.decorators.cache import cache_control | ||
|
||
from bulbs.content.views import ContentListView | ||
|
||
|
||
class RSSView(ContentListView): | ||
"""Really simply, this syndicates Content.""" | ||
template_name = "feeds/rss.xml" | ||
paginate_by = 20 | ||
feed_title = "RSS Feed" | ||
utm_params = "utm_medium=RSS&utm_campaign=feeds" | ||
|
||
def get_template_names(self): | ||
return ["feeds/rss.xml", "feeds/_rss.xml"] | ||
|
||
@cache_control(max_age=600) | ||
def get(self, request, *args, **kwargs): | ||
response = super(RSSView, self).get(request, *args, **kwargs) | ||
response["Content-Type"] = "application/rss+xml" | ||
return response | ||
|
||
def get_queryset(self): | ||
return super(RSSView, self).get_queryset().full() | ||
|
||
def get_context_data(self, *args, **kwargs): | ||
context = super(RSSView, self).get_context_data(*args, **kwargs) | ||
context["full"] = (self.request.GET.get("full", "false").lower() == "true") | ||
context["images"] = (self.request.GET.get("images", "false").lower() == "true") | ||
context["build_date"] = now() | ||
context["title"] = self.feed_title | ||
context["feed_url"] = self.request.build_absolute_uri() | ||
context["search_url"] = self.request.build_absolute_uri( | ||
u"/search?%s" % self.request.META["QUERY_STRING"]) | ||
|
||
# OK, so this is kinda brutal. Stay with me here. | ||
for content in context["page_obj"].object_list: | ||
feed_path = content.get_absolute_url() + "?" + self.utm_params | ||
content.feed_url = self.request.build_absolute_uri(feed_path) | ||
|
||
return RequestContext(self.request, context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.test.client import Client | ||
|
||
from elastimorphic.tests.base import BaseIndexableTestCase | ||
|
||
from model_mommy import mommy | ||
|
||
from tests.testcontent.models import TestContentObj | ||
|
||
|
||
class RSSTestCase(BaseIndexableTestCase): | ||
"""A base test case, allowing tearDown and setUp of the ES index""" | ||
|
||
def test_rss_feed(self): | ||
|
||
# Let's bust out some content | ||
mommy.make(TestContentObj, _quantity=100) | ||
|
||
rss_endpoint = reverse("rss-feed") | ||
|
||
client = Client() | ||
response = client.get(rss_endpoint) | ||
self.assertEqual(response.status_code, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters