From c5cc3e6d3f1dff98cdac855d7399b9fe8235cfef Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 1 Nov 2013 17:35:22 +0100 Subject: It is now possible to delete an article or an entire feed. --- pyaggr3g470r/models.py | 12 ------------ pyaggr3g470r/templates/feed.html | 1 + pyaggr3g470r/views.py | 28 ++++++++++++++++++++++++---- 3 files changed, 25 insertions(+), 16 deletions(-) (limited to 'pyaggr3g470r') 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 @@

This feed contains {{ feed.articles|count }} articles.

Address of the feed: {{ feed.link }}.

Address of the site: {{ feed.site_link }}.

+ {% 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/', 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/', 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/', methods=['GET']) @login_required -- cgit