aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-05-27 17:18:59 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-05-27 17:18:59 +0200
commitadcc7801eaa6a4f24f2c01596e82369cc7375b5e (patch)
tree0190c083ad8f508ff455037e6f632572864300f0
parentUpdated translations. (diff)
downloadnewspipe-adcc7801eaa6a4f24f2c01596e82369cc7375b5e.tar.gz
newspipe-adcc7801eaa6a4f24f2c01596e82369cc7375b5e.tar.bz2
newspipe-adcc7801eaa6a4f24f2c01596e82369cc7375b5e.zip
Updated JSON export.
-rw-r--r--pyaggr3g470r/export.py9
-rw-r--r--pyaggr3g470r/templates/management.html13
-rwxr-xr-xpyaggr3g470r/utils.py6
-rw-r--r--pyaggr3g470r/views.py38
4 files changed, 50 insertions, 16 deletions
diff --git a/pyaggr3g470r/export.py b/pyaggr3g470r/export.py
index 214997d0..812739f2 100644
--- a/pyaggr3g470r/export.py
+++ b/pyaggr3g470r/export.py
@@ -212,10 +212,17 @@ def export_json(user):
"description": feed.description,
"link": feed.link,
"site_link": feed.site_link,
+ "email_notification": feed.email_notification,
+ "enabled": feed.enabled,
+ "created_date": feed.created_date,
"articles": [ {
"title": article.title,
"link": article.link,
- "content": article.content
+ "content": article.content,
+ "readed": article.readed,
+ "like": article.like,
+ "date": article.date,
+ "retrieved_date": article.retrieved_date
}
for article in feed.articles
]
diff --git a/pyaggr3g470r/templates/management.html b/pyaggr3g470r/templates/management.html
index fb2b8601..afdad9b6 100644
--- a/pyaggr3g470r/templates/management.html
+++ b/pyaggr3g470r/templates/management.html
@@ -28,19 +28,24 @@
</div>
</div>
<div class="jumbotron">
- <h1>{{ _('Import/export feeds') }}</h1>
- <h2 id="import-opml">{{ _('Import') }}</h2>
+ <h1 id="import-opml">{{ _('OPML import/export') }}</h1>
<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>
- <h2>{{ _('Export') }}</h2>
+ <br />
<a href="/export_opml/" class="btn btn-default">{{ _('Export feeds to OPML') }}</a>
+ <h1>{{ _('Data liberation') }}</h1>
+ <form action="" method="post" id="formImportJSON" enctype="multipart/form-data">
+ <span class="btn btn-default btn-file">{{ _('Import account') }} (<span class="text-info">*.xml {{ _('or') }} *.opml</span>)<input type="file" name="jsonfile" /></span>
+ <button class="btn btn-default" type="submit">OK</button>
+ </form>
+ <br />
+ <a href="/export/?format=JSON" class="btn btn-default">Export account to JSON</a>
</div>
<div class="jumbotron">
<h1>{{ _('Export articles') }}</h1>
<a href="/export/?format=HTML" class="btn btn-default">HTML</a>
- <a href="/export/?format=JSON" class="btn btn-default">JSON</a>
</div>
</div><!-- /.container -->
{% endblock %}
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py
index 2ed828f6..6e23e12c 100755
--- a/pyaggr3g470r/utils.py
+++ b/pyaggr3g470r/utils.py
@@ -130,6 +130,12 @@ def import_opml(email, opml_file):
db.session.commit()
return nb
+def import_json(email, json_file):
+ """
+ Import an account from a JSON file.
+ """
+ user = User.query.filter(User.email == email).first()
+
def clean_url(url):
"""
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index ee9ef7a1..e4fa9963 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -551,18 +551,34 @@ def management():
Display the management page.
"""
if request.method == 'POST':
- # Import an OPML file
- data = request.files.get('opmlfile', None)
- if None == data or not allowed_file(data.filename):
- flash(gettext('File not allowed.'), 'danger')
+ if None != request.files.get('opmlfile', None):
+ # Import an OPML file
+ data = request.files.get('opmlfile', None)
+ if not allowed_file(data.filename):
+ flash(gettext('File not allowed.'), 'danger')
+ else:
+ opml_path = os.path.join("./pyaggr3g470r/var/", data.filename)
+ data.save(opml_path)
+ try:
+ nb = utils.import_opml(g.user.email, opml_path)
+ flash(str(nb) + ' ' + gettext('feeds imported.'), "success")
+ except Exception as e:
+ flash(gettext("Impossible to import the new feeds."), "danger")
+ elif None != request.files.get('jsonfile', None):
+ # Import an account
+ data = request.files.get('jsonfile', None)
+ if not allowed_file(data.filename):
+ flash(gettext('File not allowed.'), 'danger')
+ else:
+ json_path = os.path.join("./pyaggr3g470r/var/", data.filename)
+ data.save(json_path)
+ try:
+ utils.import_json(g.user.email, json_path)
+ flash(gettext('Account imported.'), "success")
+ except:
+ flash(gettext("Impossible to import the account."), "danger")
else:
- opml_path = os.path.join("./pyaggr3g470r/var/", data.filename)
- data.save(opml_path)
- try:
- nb = utils.import_opml(g.user.email, opml_path)
- flash(str(nb) + ' ' + gettext('feeds imported.'), "success")
- except Exception as e:
- flash(gettext("Impossible to import the new feeds."), "danger")
+ flash(gettext('File not allowed.'), 'danger')
form = AddFeedForm()
bgstack15