aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-04-02 22:35:30 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-04-02 22:35:30 +0200
commiteecfc41ad7b85fe9dba2fc6344c67d76c6e7a17b (patch)
tree2628ca78c18a615b73762b3eb7350036b1a660de
parentdisplay feeds icon in public pages for feeds (diff)
downloadnewspipe-eecfc41ad7b85fe9dba2fc6344c67d76c6e7a17b.tar.gz
newspipe-eecfc41ad7b85fe9dba2fc6344c67d76c6e7a17b.tar.bz2
newspipe-eecfc41ad7b85fe9dba2fc6344c67d76c6e7a17b.zip
Improved the feed creation form.
-rw-r--r--newspipe/templates/edit_feed.html81
-rw-r--r--newspipe/web/forms.py7
-rw-r--r--newspipe/web/views/feed.py24
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 %}
<div class="container">
- <div class="well">
<h3>{{ action }}</h3>
- <form action="" method="post" name="save" class="form-horizontal">
+ <form action="" method="POST" name="save" class="form-horizontal">
{{ form.hidden_tag() }}
- <div class="form-group">
- <label for="{{ form.link.id }}" class="col-sm-3 control-label">{{ form.link.label }}</label>
- <div class="col-sm-9">
- {{ form.link(class_="form-control", size="100%") }}
+ <p>Enter the URL of the website or the URL of the feed (RSS/ATOM).</p>
+ <div class="form-row">
+ <div class="form-group col-md-6">
+ <label for="{{ form.site_link.id }}" class="col-sm-3 control-label">{{ form.site_link.label }}</label>
+ <div class="col">
+ {{ form.site_link(class_="form-control", size="100%") }}
+ </div>
+ {% for error in form.site_link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+ </div>
+ <div class="form-group col-md-6">
+ <label for="{{ form.link.id }}" class="col-sm-3 control-label">{{ form.link.label }}</label>
+ <div class="col">
+ {{ form.link(class_="form-control", size="100%") }}
+ </div>
+ {% for error in form.link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
</div>
- {% for error in form.link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
</div>
-
<div class="form-group">
- <label for="{{ form.title.id }}" class="col-sm-3 control-label">{{ form.title.label }}</label>
- <div class="col-sm-9">
- {{ form.title(class_="form-control", size="100%", placeholder=_('Optional')) }}
+ <div class="col-sm-offset-3 col-sm-9">
+ {{ form.submit(class_="btn btn-primary") }}
</div>
- {% for error in form.title.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
</div>
+ <hr />
+
<div class="form-group">
- <label for="{{ form.site_link.id }}" class="col-sm-3 control-label">{{ form.site_link.label }}</label>
- <div class="col-sm-9">
- {{ form.site_link(class_="form-control", size="100%", placeholder=_('Optional')) }}
+ <label for="{{ form.title.id }}" class="col control-label">{{ form.title.label }}</label>
+ <div class="col">
+ {{ form.title(class_="form-control", size="100%", placeholder=_('Will be retrieved automatically but you can specify a custom title.')) }}
</div>
- {% for error in form.site_link.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+ {% for error in form.title.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
</div>
<div class="form-group">
- <label for="{{ form.category_id.id }}" class="col-sm-3 control-label">{{ form.category_id.label }}</label>
- <div class="col-sm-9">
+ <label for="{{ form.category_id.id }}" class="col control-label">{{ form.category_id.label }}</label>
+ <div class="col">
{{ form.category_id(class_="form-control", placeholder=_('Optional')) }}
</div>
{% for error in form.category_id.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
</div>
- <div class="form-group">
- <label for="{{ form.enabled.id }}" class="col-sm-3 control-label">{{ form.enabled.label }}</label>
- <div class="col-sm-9">
- <div class="checkbox">
- {{ form.enabled(class_="checkbox", style="margin-left: 0px;") }}
+ <div class="form-check form-check-inline">
+ <div class="form-group col-md-6">
+ <label for="{{ form.enabled.id }}" class="form-check-label">{{ form.enabled.label }}</label>
+ <div class="col-sm-9">
+ {{ form.enabled(class_="form-check-input", style="margin-left: 0px;") }}
+ <div class="text-muted text-justify">
+ {{ _("If unchecked, this feed won't be retrieved by the aggregator.") }}
+ </div>
</div>
</div>
- </div>
-
- <div class="form-group">
- <label for="{{ form.private.id }}" class="col-sm-3 control-label">{{ form.private.label }}</label>
- <div class="col-sm-9">
- <div class="checkbox">
- {{ form.private(class_="checkbox", style="margin-left: 0px;") }}
+ <div class="form-group col-md-6">
+ <label for="{{ form.private.id }}" class="form-check-label">{{ form.private.label }}</label>
+ <div class="col-sm-9">
+ {{ form.private(class_="form-check-input", style="margin-left: 0px;") }}
+ <div class="text-muted text-justify">
+ {{ _("If checked, this feed won't be listed on <a href='%(url)s'>your profile page</a>.", 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.") }}
+ </div>
</div>
- <span class="text-muted">{{ _("If checked, articles of this feed won't be available to others and the feed won't be listed on <a href='%(url)s'>your profile page</a>.", url=url_for('user.profile_public', nickname=current_user.nickname) ) }}</span>
- <span class="text-muted">{{ _("Check this box if there is a private token in the link of the feed.") }}</span>
</div>
-
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{{ _("Filters") }}</label>
+ <div class="col-sm-9">
+ <div class="text-muted text-justify">
+ {{ _("Here you can define actions to perform on newly retrieved items.") }}
+ </div>
+ </div>
<div class="col-sm-1">
<input value="+" type="button" class="form-control" id="add-feed-filter-row" />
</div>
@@ -93,6 +107,5 @@
</div>
</div>
</form>
- </div>
</div><!-- /.container -->
{% 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),
bgstack15