aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-12 18:43:07 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-12 18:43:07 +0200
commit6806497c0948775a0da7cc06e49ed90fe7484d80 (patch)
tree57b454025460a8ca935869f77d7b9731ef7ac565
parentRemoved option to disable a user. (diff)
downloadnewspipe-6806497c0948775a0da7cc06e49ed90fe7484d80.tar.gz
newspipe-6806497c0948775a0da7cc06e49ed90fe7484d80.tar.bz2
newspipe-6806497c0948775a0da7cc06e49ed90fe7484d80.zip
Export of all articles in HTML pages is now working again (but not yet on Heroku).
-rw-r--r--pyaggr3g470r/export.py14
-rwxr-xr-xpyaggr3g470r/utils.py5
-rw-r--r--pyaggr3g470r/views.py8
3 files changed, 15 insertions, 12 deletions
diff --git a/pyaggr3g470r/export.py b/pyaggr3g470r/export.py
index 3432e0f3..da63774e 100644
--- a/pyaggr3g470r/export.py
+++ b/pyaggr3g470r/export.py
@@ -132,29 +132,29 @@ img {
margin:1.00em 1.00em;
}"""
-def export_html(feeds):
+def export_html(user):
"""
- Export the articles given in parameter in a simple Webzine.
+ Export all articles of 'user' in Web pages.
"""
webzine_root = conf.PATH + "/pyaggr3g470r/var/export/webzine/"
- nb_articles = format(len(models.Article.objects()), ",d")
+ nb_articles = format(len(models.Article.query.filter(models.Article.user_id == user.id).all()), ",d")
index = HTML_HEADER("News archive")
index += "<h1>List of feeds</h1>\n"
index += """<p>%s articles.</p>\n<ul>\n""" % (nb_articles,)
- for feed in feeds:
+ for feed in user.feeds:
# creates a folder for each stream
- feed_folder = webzine_root + str(feed.oid)
+ feed_folder = webzine_root + str(feed.id)
try:
os.makedirs(feed_folder)
except OSError:
# directories already exists (not a problem)
pass
- index += """ <li><a href="%s">%s</a></li>\n""" % (feed.oid, feed.title)
+ index += """ <li><a href="%s">%s</a></li>\n""" % (feed.id, feed.title)
posts = HTML_HEADER(feed.title, "../style.css")
posts += """<h1>Articles of the feed <a href="%s">%s</a></h1>\n""" % (feed.site_link, feed.title)
- posts += """<p>%s articles.</p>\n""" % (format(len(feed.articles), ",d"),)
+ posts += """<p>%s articles.</p>\n""" % (format(len(feed.articles.all()), ",d"),)
for article in feed.articles:
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py
index 1a8a8387..6f0bab33 100755
--- a/pyaggr3g470r/utils.py
+++ b/pyaggr3g470r/utils.py
@@ -101,8 +101,7 @@ def import_opml(email, opml_file):
except:
continue
- existing_feed = [feed for feed in user.feeds if feed.link == link]
- if len(existing_feed) != 0:
+ if None != Feed.query.filter(Feed.link == link).first():
continue
try:
@@ -116,7 +115,7 @@ def import_opml(email, opml_file):
nb += 1
db.session.commit()
- return nb
+ return nb, len(subscriptions)-nb
def clean_url(url):
"""
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index d0b410ee..81462100 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -394,11 +394,14 @@ def export_articles():
Export all articles.
"""
user = User.query.filter(User.id == g.user.id).first()
+ archive_file, archive_file_name = export.export_html(user)
+ """
try:
archive_file, archive_file_name = export.export_html(user.feeds)
except:
flash("Error when exporting articles.", 'danger')
return redirect(url_for('management'))
+ """
response = make_response(archive_file)
response.headers['Content-Type'] = 'application/x-compressed'
response.headers['Content-Disposition'] = 'attachment; filename='+archive_file_name
@@ -453,8 +456,9 @@ def management():
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) + " feeds imported.", "success")
+ nb, nb_already = utils.import_opml(g.user.email, opml_path)
+ flash(str(nb) + " feeds imported (" + str(nb_already) + \
+ " already in the database).", "success")
except Exception as e:
flash("Impossible to import the new feeds.", "danger")
bgstack15