diff options
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/crawler.py | 5 | ||||
-rw-r--r-- | pyaggr3g470r/forms.py | 4 | ||||
-rw-r--r-- | pyaggr3g470r/templates/edit_feed.html | 8 | ||||
-rwxr-xr-x | pyaggr3g470r/utils.py | 5 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 14 |
5 files changed, 23 insertions, 13 deletions
diff --git a/pyaggr3g470r/crawler.py b/pyaggr3g470r/crawler.py index b505ff2a..f14d2154 100644 --- a/pyaggr3g470r/crawler.py +++ b/pyaggr3g470r/crawler.py @@ -135,6 +135,11 @@ class FeedGetter(object): feed.title = a_feed.feed.title except: feed.title = "" + if feed.link == "": + try: + feed.link = a_feed.feed.link + except: + feed.link = "" if feed.description == "": try: feed.description = a_feed.feed.subtitle diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py index d745154b..5e977071 100644 --- a/pyaggr3g470r/forms.py +++ b/pyaggr3g470r/forms.py @@ -80,8 +80,8 @@ class SigninForm(Form): return False class AddFeedForm(Form): - title = TextField(lazy_gettext("Title"), [validators.Required(lazy_gettext("Please enter a title."))]) - link = TextField(lazy_gettext("Feed link"), [validators.Required(lazy_gettext("Please enter a link for the feed."))]) + title = TextField(lazy_gettext("Title"), [validators.Optional()]) + link = TextField(lazy_gettext("Feed link"), [validators.Optional()]) site_link = TextField(lazy_gettext("Site link")) email_notification = BooleanField(lazy_gettext("Email notification"), default=False) enabled = BooleanField(lazy_gettext("Check for updates"), default=True) diff --git a/pyaggr3g470r/templates/edit_feed.html b/pyaggr3g470r/templates/edit_feed.html index 09065d4c..bcfdb0aa 100644 --- a/pyaggr3g470r/templates/edit_feed.html +++ b/pyaggr3g470r/templates/edit_feed.html @@ -6,14 +6,14 @@ <form action="" method="post" name="save"> {{ form.hidden_tag() }} - {{ form.title.label }} - {{ form.title(class_="form-control") }} {% for error in form.title.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} - {{ form.link.label }} {{ form.link(class_="form-control") }} {% for error in form.link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.title.label }} + {{ form.title(class_="form-control", placeholder="Optional") }} {% for error in form.title.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.site_link.label }} - {{ form.site_link(class_="form-control") }} {% for error in form.site_link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.site_link(class_="form-control", placeholder="Optional") }} {% for error in form.site_link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} {% if not_on_heroku %} {{ form.email_notification.label }} diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py index 336ec804..dcbf5027 100755 --- a/pyaggr3g470r/utils.py +++ b/pyaggr3g470r/utils.py @@ -42,9 +42,9 @@ import logging import datetime import operator import urllib +import subprocess from urlparse import urlparse, parse_qs, urlunparse from bs4 import BeautifulSoup - from collections import Counter from contextlib import contextmanager @@ -75,6 +75,9 @@ def opened_w_error(filename, mode="r"): finally: f.close() +def fetch(email, feed_id=None): + cmd = ['python', conf.basedir+'/fetch.py', email, str(feed_id)] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE) def import_opml(email, opml_content): """ diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index cfd60206..e4668f54 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -27,7 +27,6 @@ __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "AGPLv3" import os -import subprocess import datetime from flask import render_template, request, flash, session, url_for, redirect, g, current_app, make_response from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user, AnonymousUserMixin @@ -236,8 +235,7 @@ def fetch(feed_id=None): Triggers the download of news. News are downloaded in a separated process, mandatory for Heroku. """ - cmd = ['python', conf.basedir+'/fetch.py', g.user.email, str(feed_id)] - p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + utils.fetch(g.user.email, None) flash(gettext("Downloading articles..."), 'success') return redirect(redirect_url()) @@ -612,7 +610,7 @@ def edit_feed(feed_id=None): # Edit an existing feed form.populate_obj(feed) db.session.commit() - flash(gettext('Feed') + ' ' + feed.title + ' ' + gettext('successfully updated.'), 'success') + flash(gettext('Feed successfully updated.'), 'success') return redirect('/edit_feed/' + str(feed_id)) else: # Create a new feed @@ -624,10 +622,14 @@ def edit_feed(feed_id=None): g.user.feeds.append(new_feed) #user.feeds = sorted(user.feeds, key=lambda t: t.title.lower()) db.session.commit() - flash(gettext('Feed') + ' ' + new_feed.title + ' ' + gettext('successfully created.'), 'success') + flash(gettext('Feed successfully created.'), 'success') + + utils.fetch(g.user.email, Feed.query.filter(Feed.link == form.link.data).first().id) + flash(gettext("Downloading articles for the new feed..."), 'success') + return redirect('/edit_feed/' + str(new_feed.id)) else: - flash(gettext('Feed') + ' ' + existing_feed[0].title + ' ' + gettext('already in the database.'), 'warning') + flash(gettext('Feed already in the database.'), 'warning') return redirect('/edit_feed/' + str(existing_feed[0].id)) if request.method == 'GET': |