aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/web')
-rw-r--r--src/web/templates/management.html39
-rw-r--r--src/web/templates/opml.xml2
-rw-r--r--src/web/views/article.py32
-rw-r--r--src/web/views/feed.py35
4 files changed, 73 insertions, 35 deletions
diff --git a/src/web/templates/management.html b/src/web/templates/management.html
index 375b8f37..9c6a2e1c 100644
--- a/src/web/templates/management.html
+++ b/src/web/templates/management.html
@@ -20,24 +20,47 @@
<div class="well">
<div class="row">
<div class="col-md-6">
- <h1>{{ _('Data liberation') }}</h1>
+ <h1>{{ _('Your data') }}</h1>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-md-6">
+ <h2>{{ _('Articles') }}</h2>
+ <h3>{{ _('Import') }}</h3>
<form action="" method="post" id="formImportJSON" enctype="multipart/form-data">
<span class="btn btn-default btn-file">{{ _('Import a Newspipe account') }} (<span class="text-info">*.json</span>)<input type="file" name="jsonfile" /></span>
<button class="btn btn-default" type="submit">OK</button>
</form>
- <br />
- <a href="{{ url_for('articles.export', format='JSON') }}" class="btn btn-default">{{ _('Export your Newspipe account to JSON') }}</a>
- <br /><br />
- <a href="{{ url_for('bookmarks.export') }}" class="btn btn-default">{{ _('Export your bookmarks to JSON') }}</a>
+ <h3>{{ _('Export') }}</h3>
+ <a href="{{ url_for('articles.export') }}" class="btn btn-default">{{ _('Export your Newspipe account to JSON') }}</a>
</div>
<div class="col-md-6">
- <h1 id="import">{{ _('OPML import/export') }}</h1>
+ <h2 id="import">{{ _('OPML') }}</h2>
+ <h3>{{ _('Import') }}</h3>
<form action="" method="post" id="formImportOPML" enctype="multipart/form-data">
<span class="btn btn-default btn-file">{{ _('Batch import feeds from OPML') }} (<span class="text-info">*.xml {{ _('or') }} *.opml</span>)<input type="file" name="opmlfile" /></span>
<button class="btn btn-default" type="submit">OK</button>
</form>
- <br />
- <a href="{{ url_for('articles.export', format='OPML') }}" class="btn btn-default">{{ _('Export your feeds to OPML') }}</a>
+ <h3>{{ _('Export') }}</h3>
+ <form class="form-inline" action="{{ url_for('feeds.export') }}" method="GET" id="formExportOPML">
+ <div class="form-group">
+ <div class="input-group">
+ <label>Include disabled feeds</label>
+ <input type="checkbox" class="form-control"name="includedisabled" checked />
+ </div>
+ <div class="input-group">
+ <label>Include private feeds</label>
+ <input type="checkbox" class="form-control" name="includeprivate" checked />
+ </div>
+ </div>
+ <button class="btn btn-default" type="submit">{{ _('Export your feeds to OPML') }}</button>
+ </form>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-md-12">
+ <h1>{{ _('Bookmarks') }}</h1>
+ <a href="{{ url_for('bookmarks.export') }}" class="btn btn-default">{{ _('Export your bookmarks to JSON') }}</a>
</div>
</div>
</div>
diff --git a/src/web/templates/opml.xml b/src/web/templates/opml.xml
index 3862772d..7159e279 100644
--- a/src/web/templates/opml.xml
+++ b/src/web/templates/opml.xml
@@ -8,6 +8,6 @@
<ownerName>{{ user.nickname }}</ownerName>
</head>
<body>
- {% for feed in user.feeds %} <outline title="{{ feed.title|escape }}" text="{{ feed.title|escape }}" description="{{ feed.description|escape }}" {% if feed.category_id != None %}category="/{{ categories[feed.category_id].name }}"{% endif %} xmlUrl="{{ feed.link|escape }}" htmlUrl="{{ feed.site_link|escape }}" />
+ {% for feed in feeds %} <outline title="{{ feed.title|escape }}" text="{{ feed.title|escape }}" description="{{ feed.description|escape }}" {% if feed.category_id != None %}category="/{{ categories[feed.category_id].name }}"{% endif %} xmlUrl="{{ feed.link|escape }}" htmlUrl="{{ feed.site_link|escape }}" />
{% endfor %}</body>
</opml>
diff --git a/src/web/views/article.py b/src/web/views/article.py
index 640de8b4..bf39795d 100644
--- a/src/web/views/article.py
+++ b/src/web/views/article.py
@@ -139,30 +139,16 @@ def expire():
@login_required
def export():
"""
- Export to OPML or JSON.
+ Export articles to JSON.
"""
user = UserController(current_user.id).get(id=current_user.id)
- if request.args.get('format') == "JSON":
- # Export to JSON for the export of account.
- try:
- json_result = export_json(user)
- except Exception as e:
- flash(gettext("Error when exporting articles."), 'danger')
- return redirect(redirect_url())
- response = make_response(json_result)
- response.mimetype = 'application/json'
- response.headers["Content-Disposition"] \
- = 'attachment; filename=account.json'
- elif request.args.get('format') == "OPML":
- # Export to the OPML format.
- categories = {cat.id: cat.dump()
- for cat in CategoryController(user.id).read()}
- response = make_response(render_template('opml.xml', user=user,
- categories=categories,
- now=datetime.now()))
- response.headers['Content-Type'] = 'application/xml'
- response.headers['Content-Disposition'] = 'attachment; filename=feeds.opml'
- else:
- flash(gettext('Export format not supported.'), 'warning')
+ try:
+ json_result = export_json(user)
+ except Exception as e:
+ flash(gettext("Error when exporting articles."), 'danger')
return redirect(redirect_url())
+ response = make_response(json_result)
+ response.mimetype = 'application/json'
+ response.headers["Content-Disposition"] \
+ = 'attachment; filename=account.json'
return response
diff --git a/src/web/views/feed.py b/src/web/views/feed.py
index 873e1eb6..dcc3aa3e 100644
--- a/src/web/views/feed.py
+++ b/src/web/views/feed.py
@@ -5,7 +5,7 @@ from sqlalchemy import desc
from werkzeug.exceptions import BadRequest
from flask import Blueprint, render_template, flash, \
- redirect, request, url_for
+ redirect, request, url_for, make_response
from flask_babel import gettext
from flask_login import login_required, current_user
@@ -14,8 +14,8 @@ from lib import misc_utils, utils
from lib.feed_utils import construct_feed_from
from web.lib.view_utils import etag_match
from web.forms import AddFeedForm
-from web.controllers import (CategoryController, FeedController,
- ArticleController)
+from web.controllers import (UserController, CategoryController,
+ FeedController, ArticleController)
logger = logging.getLogger(__name__)
feeds_bp = Blueprint('feeds', __name__, url_prefix='/feeds')
@@ -261,3 +261,32 @@ def duplicates(feed_id):
'info')
return redirect(url_for('home'))
return render_template('duplicates.html', duplicates=duplicates, feed=feed)
+
+
+@feeds_bp.route('/export', methods=['GET'])
+@login_required
+def export():
+ """
+ Export feeds to OPML.
+ """
+ include_disabled = request.args.get('includedisabled', '') == 'on'
+ include_private = request.args.get('includeprivate', '') == 'on'
+
+ filter = {}
+ if not include_disabled:
+ filter['enabled'] = True
+ if not include_private:
+ filter['private'] = False
+
+ user = UserController(current_user.id).get(id=current_user.id)
+ feeds = FeedController(current_user.id).read(**filter)
+ categories = {cat.id: cat.dump()
+ for cat in CategoryController(user.id).read()}
+
+ response = make_response(render_template('opml.xml',
+ user=user, feeds=feeds,
+ categories=categories,
+ now=datetime.now()))
+ response.headers['Content-Type'] = 'application/xml'
+ response.headers['Content-Disposition'] = 'attachment; filename=feeds.opml'
+ return response
bgstack15