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.
This commit is contained in:
Jeena 2017-07-13 18:07:10 +02:00
parent 0d16b1ef88
commit 951ae14248
3 changed files with 28 additions and 1 deletions

View file

@ -19,6 +19,7 @@
<form action="{{ url_for('.update_all') }}" method="POST">
<button type="submit">Poll All</button>
<a href="{{ url_for('.subscriptions_opml')}}">Export as OPML</a>
</form>
</article>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<body>
<outline text="Subscriptions" title="Woodwind">
{% for s in subscriptions %}
<outline xmlUrl="{{ s.feed.feed }}" />
{% endfor %}
</outline>
</body>
</opml>

View file

@ -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():