aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyaggr3g470r/models.py12
-rw-r--r--pyaggr3g470r/templates/feed.html1
-rw-r--r--pyaggr3g470r/views.py28
3 files changed, 25 insertions, 16 deletions
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py
index 629cc4c2..82c0be15 100644
--- a/pyaggr3g470r/models.py
+++ b/pyaggr3g470r/models.py
@@ -77,18 +77,6 @@ if __name__ == "__main__":
user1 = User(firstname="Cédric", lastname="Bonhomme", \
email="kimble.mandel@gmail.com", pwdhash=generate_password_hash("admin"))
user1.save()
- user2 = User(firstname="Carole", lastname="Niesel", \
- email="carole.niesel@gmail.com", pwdhash=generate_password_hash("secret"))
- user2.save()
-
- user2 = User.objects(email="carole.niesel@gmail.com").first()
- feed1user2 = Feed(title='Zaubette - une maitresse qui ouvre son cartable', \
- link='http://zaubette.eklablog.com/rss/', \
- site_link='http://zaubette.eklablog.com/', \
- mail = False)
- user2.feeds.append(feed1user2)
- user2.save()
-
import mongodb
mongo = mongodb.Articles("127.0.0.1", 27017, \
diff --git a/pyaggr3g470r/templates/feed.html b/pyaggr3g470r/templates/feed.html
index 972966ee..caa3415d 100644
--- a/pyaggr3g470r/templates/feed.html
+++ b/pyaggr3g470r/templates/feed.html
@@ -6,6 +6,7 @@
<p>This feed contains {{ feed.articles|count }} <a href="/articles/{{ feed.id }}">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>
+ <a href="/delete_feed/{{ feed.oid }}"><i class="glyphicon glyphicon-remove"></i></a>
</div>
</div><!-- /.container -->
{% endblock %} \ No newline at end of file
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 0d6fcf21..9b940381 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -116,10 +116,30 @@ def article(article_id=None):
@app.route('/delete/<article_id>', methods=['GET'])
@login_required
def delete(article_id=None):
- article = models.Article.objects(id=article_id).first()
- article.delete()
- article.save()
- return redirect(url_for('home'))
+ user = models.User.objects(email=g.user.email).first()
+ # delete the article
+ for feed in user.feeds:
+ for article in feed.articles:
+ if str(article.id) == article_id:
+ feed.articles.remove(article)
+ article.delete()
+ 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, feeds__oid=feed_id).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)
+ models.User.objects(email=g.user.email, feeds__oid=feed_id).update_one(pull__feeds__oid = feed_id)
+ user.save()
+ return redirect(url_for('home'))
@app.route('/articles/<feed_id>', methods=['GET'])
@login_required
bgstack15