diff --git a/bulbs/feeds/__init__.py b/bulbs/feeds/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bulbs/feeds/templates/feeds/_rss.xml b/bulbs/feeds/templates/feeds/_rss.xml new file mode 100644 index 00000000..38262331 --- /dev/null +++ b/bulbs/feeds/templates/feeds/_rss.xml @@ -0,0 +1,27 @@ +{% load betty %} + + + {{ title|default:"RSS Feed"}} + {{ search_url }} + {{ description|default:"RSS Feed"}} + + {{ build_date|date:"D, d M Y H:i:s O" }} + {% for content in page_obj.object_list %} + {{ content.feature_type }}: {{ content.title|striptags }} + {% if content.authors.all %}{% for author in content.authors.all %}{{ author.get_full_name }}{% if not forloop.last %}, {% endif %}{% endfor%}{% endif %} + {{ content.feed_url }} + + + + {% if full %} + + {{ content.description|safe }} + + {% endif %} + {{ content.published|date:"D, d M Y H:i:s O" }} + {{ content.feed_url }} + {% endfor%} + + \ No newline at end of file diff --git a/bulbs/feeds/urls.py b/bulbs/feeds/urls.py new file mode 100644 index 00000000..b435b7af --- /dev/null +++ b/bulbs/feeds/urls.py @@ -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 +) diff --git a/bulbs/feeds/views.py b/bulbs/feeds/views.py new file mode 100644 index 00000000..99943b0f --- /dev/null +++ b/bulbs/feeds/views.py @@ -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) diff --git a/conftest.py b/conftest.py index d5c1d97c..3ae22864 100644 --- a/conftest.py +++ b/conftest.py @@ -22,13 +22,18 @@ def pytest_configure(): "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", + + "djbetty", + "elastimorphic", "rest_framework", "polymorphic", - "elastimorphic", + "bulbs.api", "bulbs.content", + "bulbs.feeds", "bulbs.promotion", "bulbs.redirects", + "tests.testcontent",), ROOT_URLCONF = 'tests.urls', TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/tests/test_rss_feeds.py b/tests/test_rss_feeds.py new file mode 100644 index 00000000..d1d2609a --- /dev/null +++ b/tests/test_rss_feeds.py @@ -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) diff --git a/tests/urls.py b/tests/urls.py index 8a494bb3..fcd1af94 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -8,5 +8,6 @@ url(r"^api/v1/", include(api_v1_router.urls)), # noqa url(r"^content_list_one\.html", ContentListView.as_view(template_name="testapp/content_list.html")), url(r"^videos/", include("bulbs.videos.urls")), - url(r"^r/", include("bulbs.redirects.urls")) + url(r"^r/", include("bulbs.redirects.urls")), + url(r"^feeds", include("bulbs.feeds.urls")) )