From eecfc41ad7b85fe9dba2fc6344c67d76c6e7a17b Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 2 Apr 2020 22:35:30 +0200 Subject: Improved the feed creation form. --- newspipe/templates/edit_feed.html | 81 +++++++++++++++++++++++---------------- newspipe/web/forms.py | 7 +--- newspipe/web/views/feed.py | 24 ++++++++++-- 3 files changed, 70 insertions(+), 42 deletions(-) diff --git a/newspipe/templates/edit_feed.html b/newspipe/templates/edit_feed.html index a439c78d..41de789d 100644 --- a/newspipe/templates/edit_feed.html +++ b/newspipe/templates/edit_feed.html @@ -1,65 +1,79 @@ {% extends "layout.html" %} {% block content %}
-

{{ action }}

-
+ {{ form.hidden_tag() }} -
- -
- {{ form.link(class_="form-control", size="100%") }} +

Enter the URL of the website or the URL of the feed (RSS/ATOM).

+
+
+ +
+ {{ form.site_link(class_="form-control", size="100%") }} +
+ {% for error in form.site_link.errors %} {{ error }}
{% endfor %} +
+
+ +
+ {{ form.link(class_="form-control", size="100%") }} +
+ {% for error in form.link.errors %} {{ error }}
{% endfor %}
- {% for error in form.link.errors %} {{ error }}
{% endfor %}
-
- -
- {{ form.title(class_="form-control", size="100%", placeholder=_('Optional')) }} +
+ {{ form.submit(class_="btn btn-primary") }}
- {% for error in form.title.errors %} {{ error }}
{% endfor %}
+
+
- -
- {{ form.site_link(class_="form-control", size="100%", placeholder=_('Optional')) }} + +
+ {{ form.title(class_="form-control", size="100%", placeholder=_('Will be retrieved automatically but you can specify a custom title.')) }}
- {% for error in form.site_link.errors %} {{ error }}
{% endfor %} + {% for error in form.title.errors %} {{ error }}
{% endfor %}
- -
+ +
{{ form.category_id(class_="form-control", placeholder=_('Optional')) }}
{% for error in form.category_id.errors %} {{ error }}
{% endfor %}
-
- -
-
- {{ form.enabled(class_="checkbox", style="margin-left: 0px;") }} +
+
+ +
+ {{ form.enabled(class_="form-check-input", style="margin-left: 0px;") }} +
+ {{ _("If unchecked, this feed won't be retrieved by the aggregator.") }} +
-
- -
- -
-
- {{ form.private(class_="checkbox", style="margin-left: 0px;") }} +
+ +
+ {{ form.private(class_="form-check-input", style="margin-left: 0px;") }} +
+ {{ _("If checked, this feed won't be listed on your profile page.", url=url_for('user.profile_public', nickname=current_user.nickname) ) }} + {{ _("Check this box if there is a private token in the link of the feed.") }} +
- {{ _("If checked, articles of this feed won't be available to others and the feed won't be listed on your profile page.", url=url_for('user.profile_public', nickname=current_user.nickname) ) }} - {{ _("Check this box if there is a private token in the link of the feed.") }}
-
+
+
+ {{ _("Here you can define actions to perform on newly retrieved items.") }} +
+
@@ -93,6 +107,5 @@
-
{% endblock %} diff --git a/newspipe/web/forms.py b/newspipe/web/forms.py index 0b992e2b..6c69eb58 100644 --- a/newspipe/web/forms.py +++ b/newspipe/web/forms.py @@ -222,11 +222,8 @@ class ProfileForm(FlaskForm): class AddFeedForm(FlaskForm): title = TextField(lazy_gettext("Title"), [validators.Optional()]) - link = TextField( - lazy_gettext("Feed link"), - [validators.Required(lazy_gettext("Please enter the URL."))], - ) - site_link = TextField(lazy_gettext("Site link"), [validators.Optional()]) + link = TextField(lazy_gettext("Feed link")) + site_link = TextField(lazy_gettext("Site link")) enabled = BooleanField(lazy_gettext("Check for updates"), default=True) submit = SubmitField(lazy_gettext("Save")) category_id = SelectField( diff --git a/newspipe/web/views/feed.py b/newspipe/web/views/feed.py index 0a659b17..11c91b52 100644 --- a/newspipe/web/views/feed.py +++ b/newspipe/web/views/feed.py @@ -242,11 +242,11 @@ def process_form(feed_id=None): if not form.validate(): return render_template("edit_feed.html", form=form) - existing_feeds = list(feed_contr.read(link=form.link.data)) + existing_feeds = list(feed_contr.read(link=form.link.data, site_link=form.site_link.data)) if existing_feeds and feed_id is None: flash(gettext("Couldn't add feed: feed already exists."), "warning") return redirect(url_for("feed.form", feed_id=existing_feeds[0].id)) - # Edit an existing feed + feed_attr = { "title": form.title.data, "enabled": form.enabled.data, @@ -266,6 +266,7 @@ def process_form(feed_id=None): feed_attr["filters"][i][filter_attr] = value if feed_id is not None: + # Edit an existing feed feed_contr.update({"id": feed_id}, feed_attr) flash( gettext( @@ -277,7 +278,24 @@ def process_form(feed_id=None): return redirect(url_for("feed.form", feed_id=feed_id)) # Create a new feed - new_feed = feed_contr.create(**feed_attr) + url = form.site_link.data if form.site_link.data else form.link.data + try: + feed = construct_feed_from(url) + except requests.exceptions.ConnectionError: + flash( + gettext("Impossible to connect to the address: {}.".format(url)), "danger" + ) + return redirect(url_for("home")) + except Exception: + logger.exception("something bad happened when fetching %r", url) + return redirect(url_for("home")) + + del feed_attr["link"] + del feed_attr["site_link"] + # remove keys with empty strings + feed_attr = {k: v for k, v in feed_attr.items() if v is not ""} + feed.update(feed_attr) + new_feed = feed_contr.create(**feed) flash( gettext("Feed %(feed_title)r successfully created.", feed_title=new_feed.title), -- cgit