From 882581abe066f16f14b7cc54776bb7985f2b34c6 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 12 Apr 2014 19:10:38 +0200 Subject: Trying the export to HTML option on Heroku (3). --- conf.py | 4 ++++ pyaggr3g470r/export.py | 7 ++++--- pyaggr3g470r/views.py | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/conf.py b/conf.py index ecc85d11..01483f10 100644 --- a/conf.py +++ b/conf.py @@ -44,6 +44,8 @@ if not ON_HEROKU: basedir = os.path.abspath(os.path.dirname(__file__)) PATH = os.path.abspath(".") + + WEBZINE_ROOT = PATH + "/pyaggr3g470r/var/export/webzine/" else: HTTP_PROXY = "" @@ -57,6 +59,8 @@ else: MAIL_ENABLED = False SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL'] + + WEBZINE_ROOT = "/tmp/" CSRF_ENABLED = True # slow database query threshold (in seconds) diff --git a/pyaggr3g470r/export.py b/pyaggr3g470r/export.py index da63774e..530c08fd 100644 --- a/pyaggr3g470r/export.py +++ b/pyaggr3g470r/export.py @@ -136,7 +136,7 @@ def export_html(user): """ Export all articles of 'user' in Web pages. """ - webzine_root = conf.PATH + "/pyaggr3g470r/var/export/webzine/" + webzine_root = conf.WEBZINE_ROOT nb_articles = format(len(models.Article.query.filter(models.Article.user_id == user.id).all()), ",d") index = HTML_HEADER("News archive") index += "

List of feeds

\n" @@ -177,8 +177,9 @@ def export_html(user): f.write(a_post.encode("utf-8")) posts += HTML_FOOTER - with open(feed_index, "w") as f: - f.write(posts.encode("utf-8")) + if len(feed.articles.all()) != 0: + with open(feed_index, "w") as f: + f.write(posts.encode("utf-8")) index += "\n" index += "

" + time.strftime("Generated on %d %b %Y at %H:%M.") + "

\n" diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 3cd8afc5..9ce597e6 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -394,8 +394,9 @@ 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) + archive_file, archive_file_name = export.export_html(user) except: flash("Error when exporting articles.", 'danger') return redirect(url_for('management')) -- cgit