Added Atom feeds for snippets.
This commit is contained in:
parent
eac73e3dd4
commit
749e9ce7ac
4 changed files with 37 additions and 6 deletions
|
|
@ -76,12 +76,6 @@ class WebsiteOpenIDStore(OpenIDStore):
|
||||||
OpenIDAssociation.lifetime < int(time())
|
OpenIDAssociation.lifetime < int(time())
|
||||||
).delete()
|
).delete()
|
||||||
|
|
||||||
def getAuthKey(self):
|
|
||||||
return sha1(config.SECRET_KEY).hexdigest()[:self.AUTH_KEY_LEN]
|
|
||||||
|
|
||||||
def isDump(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def redirect_back():
|
def redirect_back():
|
||||||
return redirect(request.values.get('next') or url_for('general.index'))
|
return redirect(request.values.get('next') or url_for('general.index'))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block head %}
|
{% block head %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
|
<link href="{{ url_for('recent_feed') }}" rel="alternate" title="Recent Flask Snippets" type="application/atom+xml">
|
||||||
<style type=text/css>
|
<style type=text/css>
|
||||||
h1 { background-image: url(/static/snippets.png); }
|
h1 { background-image: url(/static/snippets.png); }
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
{% extends "snippets/layout.html" %}
|
{% extends "snippets/layout.html" %}
|
||||||
{% block title %}{{ snippet.title }}{% endblock %}
|
{% block title %}{{ snippet.title }}{% endblock %}
|
||||||
|
{% block head %}
|
||||||
|
{{ super() }}
|
||||||
|
<link href="{{ url_for('comments_feed', id=snippet.id) }}" rel="alternate" title="Snippet Comments" type="application/atom+xml">
|
||||||
|
{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>{{ snippet.title }}</h2>
|
<h2>{{ snippet.title }}</h2>
|
||||||
<p class=snippet-author>By {{ snippet.author.name }}
|
<p class=snippet-author>By {{ snippet.author.name }}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from urlparse import urljoin
|
||||||
from flask import Module, render_template, request, flash, abort, redirect, \
|
from flask import Module, render_template, request, flash, abort, redirect, \
|
||||||
g, url_for
|
g, url_for
|
||||||
|
from werkzeug.contrib.atom import AtomFeed
|
||||||
from flask_website.utils import requires_login, format_creole
|
from flask_website.utils import requires_login, format_creole
|
||||||
from flask_website.database import Category, Snippet, Comment, db_session
|
from flask_website.database import Category, Snippet, Comment, db_session
|
||||||
|
|
||||||
|
|
@ -112,3 +115,32 @@ def category(slug):
|
||||||
snippets = category.snippets.order_by(Snippet.title).all()
|
snippets = category.snippets.order_by(Snippet.title).all()
|
||||||
return render_template('snippets/category.html', category=category,
|
return render_template('snippets/category.html', category=category,
|
||||||
snippets=snippets)
|
snippets=snippets)
|
||||||
|
|
||||||
|
|
||||||
|
@snippets.route('/recent.atom')
|
||||||
|
def recent_feed():
|
||||||
|
feed = AtomFeed(u'Recent Flask Snippets',
|
||||||
|
subtitle=u'Recent additions to the Flask snippet archive',
|
||||||
|
feed_url=request.url, url=request.url_root)
|
||||||
|
snippets = Snippet.query.order_by(Snippet.pub_date.desc()).limit(15)
|
||||||
|
for snippet in snippets:
|
||||||
|
feed.add(snippet.title, unicode(snippet.rendered_body),
|
||||||
|
content_type='html', author=snippet.author.name,
|
||||||
|
url=urljoin(request.url_root, snippet.url),
|
||||||
|
updated=snippet.pub_date)
|
||||||
|
return feed.get_response()
|
||||||
|
|
||||||
|
|
||||||
|
@snippets.route('/snippets/<int:id>/comments.atom')
|
||||||
|
def comments_feed(id):
|
||||||
|
snippet = Snippet.query.get(id)
|
||||||
|
if snippet is None:
|
||||||
|
abort(404)
|
||||||
|
feed = AtomFeed(u'Comments for Snippet “%s”' % snippet.title,
|
||||||
|
feed_url=request.url, url=request.url_root)
|
||||||
|
for comment in snippet.comments:
|
||||||
|
feed.add(comment.title or u'Untitled Comment',
|
||||||
|
unicode(snippet.rendered_text),
|
||||||
|
content_type='html', author=comment.author.name,
|
||||||
|
url=request.url, updated=comment.pub_date)
|
||||||
|
return feed.get_response()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue