Commits

Cédric Bonhomme  committed fec9dd3

List of inavtive feeds.

  • Participants
  • Parent commits 889d8df

Comments (0)

Files changed (2)

File pyaggr3g470r/templates/layout.html

                     <ul class="dropdown-menu">
                         <li><a href="/unread/">Unread</a></li>
                         <li><a href="/favorites/">Favorites</a></li>
+                        <li><a href="/inactives/">Inactive feeds</a></li>
                         <li><a href="/history/">History</a></li>
                     </ul>
                 </li>

File pyaggr3g470r/views.py

 __copyright__ = "Copyright (c) Cedric Bonhomme"
 __license__ = "GPLv3"
 
+import datetime
 
 from flask import render_template, request, flash, session, url_for, redirect, g
 from wtforms import TextField, PasswordField, SubmitField, validators
-
 from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user, AnonymousUserMixin
-
 from collections import defaultdict
 
 from forms import SigninForm, AddFeedForm
             result.append(feed)
     return render_template('unread.html', feeds=result)
 
+@app.route('/inactives/', methods=['GET'])
+@login_required
+def inactives():
+    """
+    List of inactive feeds.
+    """
+    nb_days = int(request.args.get('nb_days', 365))
+    user = models.User.objects(email=g.user.email).first()
+    today = datetime.datetime.now()
+    inactives = []
+    for feed in user.feeds:
+        last_post = feed.articles[0].date
+        elapsed = today - last_post
+        if elapsed > datetime.timedelta(days=nb_days):
+            inactives.append((feed, elapsed))
+    return render_template('inactives.html', inactives=inactives, nb_days=nb_days)
+
 @app.route('/search/', methods=['GET'])
 @login_required
 def search():