From 30b11b1cc48bbe683e6a6f112e76baeee6a89841 Mon Sep 17 00:00:00 2001
From: Raoul Snyman
Date: Tue, 26 Jan 2010 15:06:47 +0200
Subject: [PATCH 1/6] Added feed controller
---
run-server | 2 +-
scribeengine/controllers/feed.py | 16 ++++++++++++++++
scribeengine/tests/functional/test_feed.py | 7 +++++++
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 scribeengine/controllers/feed.py
create mode 100644 scribeengine/tests/functional/test_feed.py
diff --git a/run-server b/run-server
index 534e752..3cc02c7 100755
--- a/run-server
+++ b/run-server
@@ -1 +1 @@
-/home/raoul/VirtualEnv/ScribeEngine/trunk/bin/paster serve development.ini --reload
+/home/raoul/VirtualEnv/ScribeEngine/feeds/bin/paster serve development.ini --reload
diff --git a/scribeengine/controllers/feed.py b/scribeengine/controllers/feed.py
new file mode 100644
index 0000000..5a86c5c
--- /dev/null
+++ b/scribeengine/controllers/feed.py
@@ -0,0 +1,16 @@
+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+
+from scribeengine.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+
+class FeedController(BaseController):
+
+ def index(self):
+ # Return a rendered template
+ #return render('/feed.mako')
+ # or, return a response
+ return 'Hello World'
diff --git a/scribeengine/tests/functional/test_feed.py b/scribeengine/tests/functional/test_feed.py
new file mode 100644
index 0000000..b9702ee
--- /dev/null
+++ b/scribeengine/tests/functional/test_feed.py
@@ -0,0 +1,7 @@
+from scribeengine.tests import *
+
+class TestFeedController(TestController):
+
+ def test_index(self):
+ response = self.app.get(url(controller='feed', action='index'))
+ # Test response...
From e3cef7a4fd4b1582a9e5e700918b592185bcaf46 Mon Sep 17 00:00:00 2001
From: Raoul Snyman
Date: Tue, 26 Jan 2010 15:44:26 +0200
Subject: [PATCH 2/6] Initial RSS+Atom feeds.
---
scribeengine/controllers/feed.py | 55 ++++++++++++++++++++++++++++----
1 file changed, 48 insertions(+), 7 deletions(-)
diff --git a/scribeengine/controllers/feed.py b/scribeengine/controllers/feed.py
index 5a86c5c..7eb96c7 100644
--- a/scribeengine/controllers/feed.py
+++ b/scribeengine/controllers/feed.py
@@ -1,16 +1,57 @@
import logging
-from pylons import request, response, session, tmpl_context as c
-from pylons.controllers.util import abort, redirect_to
+from feedformatter import Feed
+import time
-from scribeengine.lib.base import BaseController, render
+from scribeengine.lib.base import *
+from scribeengine.model.meta import Session
+from scribeengine.model import Post, Variable
log = logging.getLogger(__name__)
class FeedController(BaseController):
+ def _generate_feed(self):
+ blog_title = Session.query(Variable).get(u'blog title').value
+ blog_slogan = Session.query(Variable).get(u'blog slogan').value
+ blog_link = request.environ[u'HTTP_HOST']
+ if blog_link.endswith(u'/'):
+ blog_link = blog_link[:-1]
+ posts = Session.query(Post)\
+ .filter_by(status=u'published')\
+ .order_by(Post.created.desc())\
+ .all()
+ # Create the feed
+ feed = Feed()
+ # Set the feed/channel level properties
+ feed.feed[u'title'] = blog_title
+ feed.feed[u'link'] = blog_link + u'/'
+ #feed.feed[u'author'] = blog_author
+ feed.feed[u'description'] = blog_slogan
+ for post in posts:
+ # Create an item
+ item = {}
+ item[u'title'] = post.title
+ item[u'link'] = blog_link + h.url_for_post(post)
+ item[u'author'] = post.user.nick
+ item[u'description'] = post.body
+ item[u'pubDate'] = post.created.timetuple()
+ #item[u'guid'] = "1234567890"
+ # Add item to feed
+ feed.items.append(item)
+ return feed
+
def index(self):
- # Return a rendered template
- #return render('/feed.mako')
- # or, return a response
- return 'Hello World'
+ h.redirect_to('/')
+
+ def rss(self, id=u'2.0'):
+ feed = self._generate_feed()
+ if id == u'1.0':
+ return feed.format_rss1_string()
+ else:
+ return feed.format_rss2_string()
+
+ def atom(self):
+ feed = self._generate_feed()
+ return feed.format_atom_string()
+
From 9ac86fc3e19ab8e1e6f7c397867444062b5ca7bb Mon Sep 17 00:00:00 2001
From: Raoul Snyman
Date: Wed, 27 Jan 2010 09:26:47 +0200
Subject: [PATCH 3/6] Removed HTML from feeds, and reduced them just to the
teaser.
---
scribeengine/controllers/feed.py | 11 +++++++----
scribeengine/lib/base.py | 1 -
scribeengine/lib/helpers.py | 2 +-
scribeengine/templates/base.mako | 2 ++
scribeengine/templates/blog/index.mako | 2 +-
5 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/scribeengine/controllers/feed.py b/scribeengine/controllers/feed.py
index 7eb96c7..d11250c 100644
--- a/scribeengine/controllers/feed.py
+++ b/scribeengine/controllers/feed.py
@@ -1,4 +1,6 @@
import logging
+import uuid
+import re
from feedformatter import Feed
import time
@@ -14,7 +16,8 @@ class FeedController(BaseController):
def _generate_feed(self):
blog_title = Session.query(Variable).get(u'blog title').value
blog_slogan = Session.query(Variable).get(u'blog slogan').value
- blog_link = request.environ[u'HTTP_HOST']
+ blog_link = str('%s://%s' % (request.environ[u'wsgi.url_scheme'], \
+ request.environ[u'HTTP_HOST']))
if blog_link.endswith(u'/'):
blog_link = blog_link[:-1]
posts = Session.query(Post)\
@@ -34,15 +37,15 @@ class FeedController(BaseController):
item[u'title'] = post.title
item[u'link'] = blog_link + h.url_for_post(post)
item[u'author'] = post.user.nick
- item[u'description'] = post.body
+ item[u'description'] = re.sub(r'<(.*?)>', u'', h.teaser(post.body))
item[u'pubDate'] = post.created.timetuple()
- #item[u'guid'] = "1234567890"
+ item[u'guid'] = str(uuid.uuid5(uuid.NAMESPACE_URL, blog_link + h.url_for_post(post)))
# Add item to feed
feed.items.append(item)
return feed
def index(self):
- h.redirect_to('/')
+ h.redirect_to(h.url_for(action=u'atom'))
def rss(self, id=u'2.0'):
feed = self._generate_feed()
diff --git a/scribeengine/lib/base.py b/scribeengine/lib/base.py
index d4fe506..339b356 100644
--- a/scribeengine/lib/base.py
+++ b/scribeengine/lib/base.py
@@ -49,7 +49,6 @@ log = logging.getLogger(__name__)
class BaseController(WSGIController):
def __before__(self):
- #c.theme_name = Session.query(Configuration).get(u'theme').value
if session.get(u'REMOTE_USER'):
c.current_user = Session.query(User).get(session[u'REMOTE_USER'])
c.blog_title = Session.query(Variable).get(u'blog title').value
diff --git a/scribeengine/lib/helpers.py b/scribeengine/lib/helpers.py
index ca64222..d020ee9 100644
--- a/scribeengine/lib/helpers.py
+++ b/scribeengine/lib/helpers.py
@@ -61,7 +61,7 @@ class Flash(object):
return message_type
-def teaser(text, url):
+def teaser(text):
position = text.find(u'
')
if position > 0:
return text[:position + 4]
diff --git a/scribeengine/templates/base.mako b/scribeengine/templates/base.mako
index f6f63f8..ed63f0a 100644
--- a/scribeengine/templates/base.mako
+++ b/scribeengine/templates/base.mako
@@ -6,6 +6,8 @@
${c.page_title}
+
+
% for script in c.scripts:
diff --git a/scribeengine/templates/blog/index.mako b/scribeengine/templates/blog/index.mako
index cb560ae..011f27a 100644
--- a/scribeengine/templates/blog/index.mako
+++ b/scribeengine/templates/blog/index.mako
@@ -4,7 +4,7 @@
- ${h.literal(h.teaser(post.body, h.url_for_post(post)))}
+ ${h.literal(h.teaser(post.body))}
Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}
From daeb272c177a7212b57bf116f7de163e025de14c Mon Sep 17 00:00:00 2001
From: Raoul Snyman
Date: Wed, 27 Jan 2010 09:52:31 +0200
Subject: [PATCH 4/6] Removed unnecessary line
---
scribeengine/controllers/feed.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/scribeengine/controllers/feed.py b/scribeengine/controllers/feed.py
index d11250c..82702a0 100644
--- a/scribeengine/controllers/feed.py
+++ b/scribeengine/controllers/feed.py
@@ -29,7 +29,6 @@ class FeedController(BaseController):
# Set the feed/channel level properties
feed.feed[u'title'] = blog_title
feed.feed[u'link'] = blog_link + u'/'
- #feed.feed[u'author'] = blog_author
feed.feed[u'description'] = blog_slogan
for post in posts:
# Create an item
From 72c107e817aa44dacbdee2305faa6702438294c7 Mon Sep 17 00:00:00 2001
From: Raoul Snyman
Date: Wed, 27 Jan 2010 10:15:39 +0200
Subject: [PATCH 5/6] Fixed a problem on the tags page.
---
scribeengine/controllers/blog.py | 2 +-
scribeengine/templates/blog/tag.mako | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py
index 3f87f02..2d43e18 100644
--- a/scribeengine/controllers/blog.py
+++ b/scribeengine/controllers/blog.py
@@ -74,7 +74,7 @@ class BlogController(BaseController):
def tag(self, id=None):
if not id:
h.redirect_to('/')
- c.tag = Session.query(Tag).filter_by(url=id).first()
+ c.tag = Session.query(Tag).filter_by(url=id).all()
if not c.tag:
h.redirect_to('/')
c.page_title = u'Blog posts with tag: %s' % c.tag.name
diff --git a/scribeengine/templates/blog/tag.mako b/scribeengine/templates/blog/tag.mako
index 6fd917a..2d566d7 100644
--- a/scribeengine/templates/blog/tag.mako
+++ b/scribeengine/templates/blog/tag.mako
@@ -5,7 +5,7 @@
- ${h.literal(h.teaser(post.body, h.url_for_post(post)))}
+ ${h.literal(h.teaser(post.body))}
Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}
From db6d31cc9eb68c790f7656d6759143ecd2135892 Mon Sep 17 00:00:00 2001
From: Raoul Snyman
Date: Wed, 27 Jan 2010 10:33:06 +0200
Subject: [PATCH 6/6] Fixed a small problem with the tags page.
---
scribeengine/controllers/blog.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py
index 2d43e18..3f87f02 100644
--- a/scribeengine/controllers/blog.py
+++ b/scribeengine/controllers/blog.py
@@ -74,7 +74,7 @@ class BlogController(BaseController):
def tag(self, id=None):
if not id:
h.redirect_to('/')
- c.tag = Session.query(Tag).filter_by(url=id).all()
+ c.tag = Session.query(Tag).filter_by(url=id).first()
if not c.tag:
h.redirect_to('/')
c.page_title = u'Blog posts with tag: %s' % c.tag.name