Skip to content

Add feed to news page #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion celeryproject/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# calendars according to the current locale.
USE_L10N = True

LOCALE_PATHS = (join(PROJECT_ROOT, 'celeryweb/locale'))
LOCALE_PATHS = (join(PROJECT_ROOT, 'celeryweb/locale'),)

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
Expand Down
1 change: 1 addition & 0 deletions celeryproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

urlpatterns = [url(r'^news/$', views.news, name='news'),
url(r'^news/(?P<slug>[\w-]*)', views.news, name='news_entry'),
url(r'^news/feed/$', views.NewsFeed(), name='news_feed'),
url(r'^tutorials/$', views.tutorials, name='tutorials'),
url(r'^tutorials/(?P<slug>[\w-]*)',
views.tutorials, name='tutorial'),
Expand Down
2 changes: 0 additions & 2 deletions celeryweb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.contrib.flatpages.models import FlatPage
from django.utils.translation import ugettext_lazy as _


class TrackingModel(models.Model):
creator = models.CharField(verbose_name=_("_creator"),
max_length=255,
Expand Down Expand Up @@ -104,7 +103,6 @@ def __unicode__(self):
def permalink(self):
return "/news/%s/" % self.slug


class Tutorial(TrackingModel):
title = models.CharField(verbose_name=_("_title"), max_length=255)
slug = models.SlugField(verbose_name=_("_slug"), unique=True)
Expand Down
20 changes: 20 additions & 0 deletions celeryweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.contrib.syndication.views import Feed
from django.urls import reverse

from .models import News, Tutorial, CommunityLink

Expand Down Expand Up @@ -140,3 +142,21 @@ def package_info(request):
'ajax/celery_package_info.html',
package_info_context,
)

class NewsFeed(Feed):
title = "News | Celery: Distributed Task Queue"
link = "/sitenews/"
description = "News"

def items(self):
return News.objects.order_by('-pub_date')[:5]

def item_title(self, item):
return item.title

def item_description(self, item):
return item.text

# item_link is only needed if NewsItem has no get_absolute_url method.
def item_link(self, item):
return reverse('news_entry', args=[item.slug])
2 changes: 2 additions & 0 deletions templates/news.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{%extends "base.html" %}
{% load url from future %}
{%block title%}News{%endblock%}
<link rel="alternate" type="application/rss+xml"
href="{% site_url %}/news/feed" title="Celery Project News">
{%block content%}
<h1>News</h1>
<div class="list">
Expand Down