Added registration/activation stuff.

Merged from trunk.
Removed conflict.
This commit is contained in:
Raoul Snyman 2010-01-30 23:41:29 +02:00
commit c4bb6d0e93
7 changed files with 71 additions and 4 deletions

View File

@ -0,0 +1,59 @@
import logging
import uuid
import re
from feedformatter import Feed
import time
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 = 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)\
.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'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'] = re.sub(r'<(.*?)>', u'', h.teaser(post.body))
item[u'pubDate'] = post.created.timetuple()
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.url_for(action=u'atom'))
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()

View File

@ -49,7 +49,6 @@ log = logging.getLogger(__name__)
class BaseController(WSGIController): class BaseController(WSGIController):
def __before__(self): def __before__(self):
#c.theme_name = Session.query(Configuration).get(u'theme').value
if session.get(u'REMOTE_USER'): if session.get(u'REMOTE_USER'):
c.current_user = Session.query(User).get(session[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 c.blog_title = Session.query(Variable).get(u'blog title').value

View File

@ -61,7 +61,7 @@ class Flash(object):
return message_type return message_type
def teaser(text, url): def teaser(text):
position = text.find(u'</p>') position = text.find(u'</p>')
if position > 0: if position > 0:
return text[:position + 4] return text[:position + 4]

View File

@ -6,6 +6,8 @@
<title>${c.page_title}</title> <title>${c.page_title}</title>
<meta name="keywords" content="" /> <meta name="keywords" content="" />
<meta name="description" content="" /> <meta name="description" content="" />
<link href="${h.url_for(controller=u'feed', action=u'atom')}" type="application/atom+xml" rel="alternate" title="Sitewide ATOM Feed" />
<link href="${h.url_for(controller=u'feed', action=u'rss')}" type="application/rss+xml" rel="alternate" title="Sitewide RSS Feed" />
<link href="${h.url_for('/styles/style.css')}" rel="stylesheet" type="text/css" media="screen" /> <link href="${h.url_for('/styles/style.css')}" rel="stylesheet" type="text/css" media="screen" />
% for script in c.scripts: % for script in c.scripts:
<script src="/scripts/${script}" type="text/javascript"></script> <script src="/scripts/${script}" type="text/javascript"></script>

View File

@ -4,7 +4,7 @@
<div class="post"> <div class="post">
<h2 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h2> <h2 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h2>
<div class="entry"> <div class="entry">
${h.literal(h.teaser(post.body, h.url_for_post(post)))} ${h.literal(h.teaser(post.body))}
</div> </div>
<p class="meta"> <p class="meta">
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span> <span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>

View File

@ -5,7 +5,7 @@
<div class="post"> <div class="post">
<h3 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h3> <h3 class="title"><a href="${h.url_for_post(post)}">${post.title}</a></h3>
<div class="entry"> <div class="entry">
${h.literal(h.teaser(post.body, h.url_for_post(post)))} ${h.literal(h.teaser(post.body))}
</div> </div>
<p class="meta"> <p class="meta">
<span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span> <span class="byline">Posted by ${post.user.nick} on ${post.created.strftime('%B %d, %Y')}</span>

View File

@ -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...