aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/forms.py2
-rw-r--r--pyaggr3g470r/templates/edit_feed.html22
-rw-r--r--pyaggr3g470r/templates/feed.html1
-rw-r--r--pyaggr3g470r/templates/management.html18
-rw-r--r--pyaggr3g470r/views.py70
5 files changed, 70 insertions, 43 deletions
diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py
index 161d8d4c..e13dde96 100644
--- a/pyaggr3g470r/forms.py
+++ b/pyaggr3g470r/forms.py
@@ -54,7 +54,7 @@ class AddFeedForm(Form):
title = TextField("Title", [validators.Required("Please enter a title.")])
link = TextField("Feed link", [validators.Required("Please enter a link.")])
site_link = TextField("Site link", [validators.Required("Please enter a site URL.")])
- submit = SubmitField("Add feed")
+ submit = SubmitField("Save")
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)
diff --git a/pyaggr3g470r/templates/edit_feed.html b/pyaggr3g470r/templates/edit_feed.html
new file mode 100644
index 00000000..7bdf2717
--- /dev/null
+++ b/pyaggr3g470r/templates/edit_feed.html
@@ -0,0 +1,22 @@
+{% extends "layout.html" %}
+{% block content %}
+<div class="container">
+ <div class="jumbotron">
+ <h1>{{ action }}</h1>
+ <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 }}</span>{% endfor %}
+
+ {{ form.link.label }}
+ {{ form.link(class_="form-control") }} {% for error in form.link.errors %} <span style="color: red;">{{ error }}</span>{% endfor %}
+
+ {{ form.site_link.label }}
+ {{ form.site_link(class_="form-control") }} {% for error in form.site_link.errors %} <span style="color: red;">{{ error }}</span>{% endfor %}
+
+ {{ form.submit(class_="btn") }}
+ </form>
+ </div>
+</div><!-- /.container -->
+{% endblock %} \ No newline at end of file
diff --git a/pyaggr3g470r/templates/feed.html b/pyaggr3g470r/templates/feed.html
index 5808f233..e08ac159 100644
--- a/pyaggr3g470r/templates/feed.html
+++ b/pyaggr3g470r/templates/feed.html
@@ -4,6 +4,7 @@
<div class="jumbotron">
<h2>{{ feed.title }}</h2>
<a href="/delete_feed/{{ feed.oid }}"><i class="glyphicon glyphicon-remove" title="Delete this feed"></i></a>
+ <a href="/edit_feed/{{ feed.oid }}"><i class="glyphicon glyphicon-edit" title="Edit this feed"></i></a>
<p>This feed contains {{ feed.articles|count }} <a href="/articles/{{ feed.oid }}">articles</a>.</p>
<p>Address of the feed: <a href="{{ feed.link }}">{{ feed.link }}</a>.</p>
<p>Address of the site: <a href="{{ feed.site_link }}">{{ feed.site_link }}</a>.</p>
diff --git a/pyaggr3g470r/templates/management.html b/pyaggr3g470r/templates/management.html
index c1e5ba64..031e3e7e 100644
--- a/pyaggr3g470r/templates/management.html
+++ b/pyaggr3g470r/templates/management.html
@@ -2,24 +2,6 @@
{% block content %}
<div class="container">
<div class="jumbotron">
- <h1>Add a feed</h1>
- <form action="/add_feed/" 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 }}</span>{% endfor %}
-
- {{ form.link.label }}
- {{ form.link(class_="form-control") }} {% for error in form.link.errors %} <span style="color: red;">{{ error }}</span>{% endfor %}
-
- {{ form.site_link.label }}
- {{ form.site_link(class_="form-control") }} {% for error in form.site_link.errors %} <span style="color: red;">{{ error }}</span>{% endfor %}
-
- {{ form.submit(class_="btn") }}
- </form>
- </div>
-
- <div class="jumbotron">
<h1>Your subscriptions</h1>
<p>You are subscribed to {{ nb_feeds }} <a href="/feeds">feeds</a>.</p>
<p>{{ nb_articles }} articles are stored in the database with {{ nb_unread_articles }} <a href="/unread/">unread articles</a>.</p>
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index f0ed4103..6a232d0e 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -159,21 +159,6 @@ def delete(article_id=None):
user.save()
return redirect(url_for('home'))
-@app.route('/delete_feed/<feed_id>', methods=['GET'])
-@login_required
-def delete_feed(feed_id=None):
- user = models.User.objects(email=g.user.email).first()
- # delete all articles (Document objects)
- for feed in user.feeds:
- if str(feed.oid) == feed_id:
- for article in feed.articles:
- article.delete()
- feed.articles = []
- # delete the feed (EmbeddedDocument object)
- user.feeds.remove(feed)
- user.save()
- return redirect(url_for('home'))
-
@app.route('/articles/<feed_id>', methods=['GET'])
@login_required
def articles(feed_id=None):
@@ -215,19 +200,56 @@ def management():
return render_template('management.html', form=form, \
nb_feeds=nb_feeds, nb_articles=nb_articles, nb_unread_articles=nb_unread_articles)
-@app.route('/add_feed/', methods=['GET', 'POST'])
+@app.route('/edit_feed/', methods=['GET', 'POST'])
+@app.route('/edit_feed/<feed_id>', methods=['GET', 'POST'])
@login_required
-def add_feed():
+def edit_feed(feed_id=None):
+ """
+ Add or edit a feed.
+ """
user = models.User.objects(email=g.user.email).first()
form = AddFeedForm()
if request.method == 'POST':
if form.validate() == False:
- return render_template('management.html', form=form)
- new_feed = models.Feed(title=form.title.data, link=form.link.data, site_link=form.site_link.data)
+ return render_template('edit_feed.html', form=form)
+ if feed_id != None:
+ # Edit an existing feed
+ for feed in user.feeds:
+ if str(feed.oid) == feed_id:
+ form.populate_obj(feed)
+ user.save()
+ flash('Feed "' + feed.title + '" successfully updated', 'success')
+ return redirect('/feed/'+feed_id)
+ else:
+ # Create a new feed
+ new_feed = models.Feed(title=form.title.data, link=form.link.data, site_link=form.site_link.data)
+ user.feeds.append(new_feed)
+ user.feeds = sorted(user.feeds, key=lambda t: t.title.lower())
+ user.save()
+ return redirect(url_for('home'))
- user.feeds.append(new_feed)
- user.feeds = sorted(user.feeds, key=lambda t: t.title.lower())
- user.save()
- return redirect(url_for('home'))
- return render_template('management.html', form=form) \ No newline at end of file
+ if request.method == 'GET':
+ if feed_id != None:
+ for feed in user.feeds:
+ if str(feed.oid) == feed_id:
+ form = AddFeedForm(obj=feed)
+ return render_template('edit_feed.html', action="Edit the feed", form=form, feed=feed)
+
+ # Return an empty form in order to create a new feed
+ return render_template('edit_feed.html', action="Add a feed", form=form)
+
+@app.route('/delete_feed/<feed_id>', methods=['GET'])
+@login_required
+def delete_feed(feed_id=None):
+ user = models.User.objects(email=g.user.email).first()
+ # delete all articles (Document objects)
+ for feed in user.feeds:
+ if str(feed.oid) == feed_id:
+ for article in feed.articles:
+ article.delete()
+ feed.articles = []
+ # delete the feed (EmbeddedDocument object)
+ user.feeds.remove(feed)
+ user.save()
+ return redirect(url_for('home')) \ No newline at end of file
bgstack15