add rss feeds for public pastes

This commit is contained in:
Dan Colish 2011-07-13 22:28:22 -07:00
parent 6cba016f0c
commit 4867f71fd7
7 changed files with 33 additions and 7 deletions

View File

@ -1,2 +1,3 @@
\.py[co]$ \.py[co]$
\.DS_Store$ \.DS_Store$
bootstrap.py

4
TODO
View File

@ -4,4 +4,6 @@
* Improve i18n support * Improve i18n support
* Improve LodgeIt Interface (null-interface + star) * Improve LodgeIt Interface (null-interface + star)
* use udiff module instead of pygments-diff-highlighter for diff highlighning * use udiff module instead of pygments-diff-highlighter for diff highlighning
* use flatland for forms * use flatland for forms
* comparisons are suprising by using the paste being compared to as the
initial

View File

@ -11,7 +11,7 @@
from werkzeug import redirect, Response from werkzeug import redirect, Response
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound
from lodgeit import local from lodgeit import local
from lodgeit.i18n import list_languages as i18n_list_languages, _ from lodgeit.i18n import list_languages as i18n_list_languages
from lodgeit.utils import render_to_response, url_for from lodgeit.utils import render_to_response, url_for
from lodgeit.models import Paste from lodgeit.models import Paste
from lodgeit.database import session from lodgeit.database import session
@ -19,7 +19,6 @@ from lodgeit.lib.highlighting import list_languages, STYLES, get_style
from lodgeit.lib.pagination import generate_pagination from lodgeit.lib.pagination import generate_pagination
class PasteController(object): class PasteController(object):
"""Provides all the handler callback for paste related stuff.""" """Provides all the handler callback for paste related stuff."""
@ -177,5 +176,10 @@ class PasteController(object):
return redirect(local.request.headers.get('referer') or return redirect(local.request.headers.get('referer') or
url_for('pastes/new_paste')) url_for('pastes/new_paste'))
def rss(self):
query = Paste.find_all()
items = query.all()
return render_to_response('rss.html', items=items,
mimetype='application/rss+xml')
controller = PasteController controller = PasteController

View File

@ -90,6 +90,7 @@ class Paste(db.Model):
"""Get the new replies for the ower of a request and flag them """Get the new replies for the ower of a request and flag them
as handled. as handled.
""" """
#XXX:dc:clean this query up to just return the ids
ids = [x.paste_id for x in Paste.query.filter_by( ids = [x.paste_id for x in Paste.query.filter_by(
user_hash=local.request.user_hash).all()] user_hash=local.request.user_hash).all()]
paste_list = Paste.query.filter(db.and_( paste_list = Paste.query.filter(db.and_(

View File

@ -39,4 +39,7 @@ urlmap = Map([
# language # language
Rule('/language/<lang>/', endpoint='pastes/set_language'), Rule('/language/<lang>/', endpoint='pastes/set_language'),
# rss
Rule('/rss.xml', endpoint='pastes/rss'),
]) ])

View File

@ -39,9 +39,9 @@ _word_only = partial(re.compile(r'[^a-zA-Z0-9]').sub, '')
COOKIE_NAME = u'lodgeit_session' COOKIE_NAME = u'lodgeit_session'
def url_for(endpoint, _external=False, **values): def url_for(endpoint, external=False, **values):
builder = local.ctx.url_adapter.build builder = local.ctx.url_adapter.build
return builder(endpoint, values, force_external=_external) return builder(endpoint, values, force_external=external)
jinja_environment.globals['url_for'] = url_for jinja_environment.globals['url_for'] = url_for
@ -109,7 +109,7 @@ def render_template(template_name, **context):
return jinja_environment.get_template(template_name).render(context) return jinja_environment.get_template(template_name).render(context)
def render_to_response(template_name, **context): def render_to_response(template_name, mimetype='text/html', **context):
"""Render a template to a response. This automatically fetches """Render a template to a response. This automatically fetches
the list of new replies for the layout template. It also the list of new replies for the layout template. It also
adds the current request to the context. This is used for the adds the current request to the context. This is used for the
@ -120,4 +120,4 @@ def render_to_response(template_name, **context):
if request.method == 'GET': if request.method == 'GET':
context['new_replies'] = Paste.fetch_replies() context['new_replies'] = Paste.fetch_replies()
return Response(render_template(template_name, **context), return Response(render_template(template_name, **context),
mimetype='text/html') mimetype=mimetype)

15
lodgeit/views/rss.html Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Paste</title>
<link>{{ url_for('pastes/new_paste', external=True) }}</link>
<description>Public pastes</description>
{%- for item in items %}
<item>
<title>{{ item.paste_id }}</title>
<link>{{ url_for('pastes/show_paste', identifier=item.paste_id, external=True) }}</link>
<guid>{{ url_for('pastes/show_paste', identifier=item.paste_id, external=True) }}</guid>
</item>
{%- endfor %}
</channel>
</rss>