Add app to store and view the PostgreSQL Weekly News, including generation

of the RSS feed. (Which will receive a new URL now that it lives in the
actual app and not in with the static files, so a redirect will be needed
there).
This commit is contained in:
Magnus Hagander
2010-06-10 20:43:54 +02:00
parent 4eef43a19f
commit 93d3450213
11 changed files with 115 additions and 1 deletions

0
pgweb/pwn/__init__.py Normal file
View File

4
pgweb/pwn/admin.py Normal file
View File

@ -0,0 +1,4 @@
from util.admin import register_markdown
from models import *
register_markdown(PwnPost)

22
pgweb/pwn/feeds.py Normal file
View File

@ -0,0 +1,22 @@
from django.contrib.syndication.feeds import Feed
from models import PwnPost
from datetime import datetime, time
class PwnFeed(Feed):
title = description = "PostgreSQL Weekly News"
link = "http://www.postgresql.org/community/weeklynews/"
description_template = 'pwn/rss_description.html'
title_template = 'pwn/rss_title.html'
def items(self):
return PwnPost.objects.all()[:5]
def item_link(self, obj):
return "http://www.postgresql.org/community/weeklynews/pwn%s/" % obj.linkdate
def item_pubdate(self, obj):
return datetime.combine(obj.date,time.min)

24
pgweb/pwn/models.py Normal file
View File

@ -0,0 +1,24 @@
from django.db import models
from datetime import date
class PwnPost(models.Model):
date = models.DateField(null=False, blank=False, default=date.today, unique=True)
intro = models.TextField(null=False, blank=False)
content = models.TextField(null=False, blank=False)
markdown_fields = ('intro', 'content',)
def __unicode__(self):
return "PostgreSQL Weekly News %s" % self.date
@property
def linkdate(self):
return self.date.strftime("%Y%m%d")
@property
def nicedate(self):
return self.date.strftime("%B %d, %Y")
class Meta:
ordering = ('-date',)

23
pgweb/pwn/views.py Normal file
View File

@ -0,0 +1,23 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, Http404, HttpResponseRedirect
from pgweb.util.contexts import NavContext
from datetime import date
from models import *
def index(request):
posts = PwnPost.objects.all()
return render_to_response('pwn/list.html', {
'posts': posts,
}, NavContext(request, 'community'))
def post(request, year, month, day):
d = date(int(year), int(month), int(day))
post = get_object_or_404(PwnPost, date=d)
return render_to_response('pwn/view.html', {
'post': post,
}, NavContext(request, 'community'))

View File

@ -105,6 +105,7 @@ INSTALLED_APPS = [
'pgweb.survey',
'pgweb.misc',
'pgweb.featurematrix',
'pgweb.pwn',
]

View File

@ -13,10 +13,12 @@ admin.autodiscover()
from core.feeds import VersionFeed
from news.feeds import NewsFeed
from events.feeds import EventFeed
from pwn.feeds import PwnFeed
feeds = {
'versions': VersionFeed,
'news': NewsFeed,
'events': EventFeed,
'weeklynews': PwnFeed,
}
urlpatterns = patterns('',
@ -48,6 +50,8 @@ urlpatterns = patterns('',
(r'^community/lists/subscribe/$', 'lists.views.subscribe'),
(r'^community/survey/vote/(\d+)/$', 'survey.views.vote'),
(r'^community/survey[/\.](\d+)(-.*)?/$', 'survey.views.results'),
(r'^community/weeklynews/$', 'pwn.views.index'),
(r'^community/weeklynews/pwn(\d{4})(\d{2})(\d{2})/$', 'pwn.views.post'),
(r'^support/professional_(support|hosting)/$', 'profserv.views.root'),
(r'^support/professional_(support|hosting)[/_](.*)/$', 'profserv.views.region'),
@ -59,7 +63,7 @@ urlpatterns = patterns('',
###
# RSS feeds
###
(r'^(versions|news|events).rss$', 'django.contrib.syndication.views.feed', {'feed_dict':feeds}),
(r'^(versions|news|events|weeklynews).rss$', 'django.contrib.syndication.views.feed', {'feed_dict':feeds}),
###
# Special secttions

22
templates/pwn/list.html Normal file
View File

@ -0,0 +1,22 @@
{%extends "base/page.html"%}
{%block title%}Weekly News{%endblock%}
{%block contents%}
<h1>Weekly News</h1>
<p>
The PostgreSQL Weekly News is a community newsletter, summarising the news and events
of the past week, focussing primarily on the development of PostgreSQL.
</p>
<p>
To receive the Weekly News in your inbox, please subscribe to the
<a href="/community/lists/subscribe">pgsql-announce@postgresql.org</a>
mailing list.
</p>
<ul>
{%for post in posts %}
<li><a href="pwn{{post.linkdate}}/">{{post.nicedate}}</a></li>
{%endfor%}
</ul>
{%endblock%}

View File

@ -0,0 +1,2 @@
{%load markup%}
{{obj.intro|markdown}}

View File

@ -0,0 +1 @@
PostgreSQL Weekly News - {{obj.date}}

11
templates/pwn/view.html Normal file
View File

@ -0,0 +1,11 @@
{%extends "base/page.html"%}
{%load markup%}
{%block title%}PostgreSQL Weekly News - {{post.nicedate}}{%endblock%}
{%block contents%}
<h1>PostgreSQL Weekly News - {{post.nicedate}}</h1>
<p>
{{post.intro|markdown}}
</p>
{{post.content|markdown}}
{%endblock%}