From 951ae1424875571a2fbafd9d13bf051702a2e561 Mon Sep 17 00:00:00 2001 From: Jeena Date: Thu, 13 Jul 2017 18:07:10 +0200 Subject: [PATCH] Add OPML export of subscriptions It's nice to be able to export all your subscriptions if you want to move to a different reader. This patch adds a link to the subscription page where one can download the subscription list as OPML which is the standard way of importing/exporting between feed readers. --- woodwind/templates/subscriptions.jinja2 | 1 + woodwind/templates/subscriptions_opml.xml | 10 ++++++++++ woodwind/views.py | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 woodwind/templates/subscriptions_opml.xml diff --git a/woodwind/templates/subscriptions.jinja2 b/woodwind/templates/subscriptions.jinja2 index 3a1abc2..74c583d 100644 --- a/woodwind/templates/subscriptions.jinja2 +++ b/woodwind/templates/subscriptions.jinja2 @@ -19,6 +19,7 @@
+ Export as OPML
diff --git a/woodwind/templates/subscriptions_opml.xml b/woodwind/templates/subscriptions_opml.xml new file mode 100644 index 0000000..70ed840 --- /dev/null +++ b/woodwind/templates/subscriptions_opml.xml @@ -0,0 +1,10 @@ + + + + + {% for s in subscriptions %} + + {% endfor %} + + + diff --git a/woodwind/views.py b/woodwind/views.py index 5cdab70..57b80ee 100644 --- a/woodwind/views.py +++ b/woodwind/views.py @@ -55,7 +55,8 @@ def index(): .join(Subscription.user)\ .filter(User.id == flask_login.current_user.id)\ .filter(db.or_(Entry.deleted == None, - Entry.deleted >= now)) + Entry.deleted >= now))\ + .order_by(Entry.published.desc()) if 'entry' in flask.request.args: entry_url = flask.request.args.get('entry') @@ -126,6 +127,21 @@ def subscriptions(): subscriptions=subscs) +@views.route('/subscriptions_opml.xml') +@flask_login.login_required +def subscriptions_opml(): + subscs = Subscription\ + .query\ + .filter_by(user_id=flask_login.current_user.id)\ + .options(sqlalchemy.orm.subqueryload(Subscription.feed))\ + .order_by(db.func.lower(Subscription.name))\ + .all() + template = flask.render_template('subscriptions_opml.xml', + subscriptions=subscs) + response = flask.make_response(template) + response.headers['Content-Type'] = 'application/xml' + return response + @views.route('/settings', methods=['GET', 'POST']) @flask_login.login_required def settings():