diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-11-01 12:32:30 +0100 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-11-01 12:32:30 +0100 |
commit | d92f44e5667222c6dbf3d32b5577b2bee20d6d00 (patch) | |
tree | 70f08f8960970652b7584488000de1c1bc4bc6e1 | |
parent | Added new template to display information about a feed. (diff) | |
download | newspipe-d92f44e5667222c6dbf3d32b5577b2bee20d6d00.tar.gz newspipe-d92f44e5667222c6dbf3d32b5577b2bee20d6d00.tar.bz2 newspipe-d92f44e5667222c6dbf3d32b5577b2bee20d6d00.zip |
Added users management.
-rw-r--r-- | pyaggr3g470r/__init__.py | 2 | ||||
-rw-r--r-- | pyaggr3g470r/models.py | 23 | ||||
-rw-r--r-- | pyaggr3g470r/templates/feeds.html | 2 | ||||
-rw-r--r-- | pyaggr3g470r/templates/home.html | 2 | ||||
-rw-r--r-- | pyaggr3g470r/templates/unread.html | 2 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 32 |
6 files changed, 37 insertions, 26 deletions
diff --git a/pyaggr3g470r/__init__.py b/pyaggr3g470r/__init__.py index 64b25b96..a26135ac 100644 --- a/pyaggr3g470r/__init__.py +++ b/pyaggr3g470r/__init__.py @@ -51,7 +51,7 @@ class ArticleView(ModelView): column_searchable_list = ('title', 'link') admin.add_view(FeedView(Feed)) admin.add_view(ArticleView(Article)) -admin.add_view(UserView(User)) +#admin.add_view(UserView(User)) from pyaggr3g470r import views
\ No newline at end of file diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index 23222909..0f7ab008 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -7,12 +7,14 @@ from datetime import datetime from werkzeug import generate_password_hash, check_password_hash from flask.ext.login import UserMixin +import bson.objectid + class User(Document, UserMixin): firstname = StringField(required=True) lastname = StringField(required = True) email = EmailField(required=True, unique=True) pwdhash = StringField(required=True) - #feeds = ListField(DocumentField('Article')) + feeds = ListField(EmbeddedDocumentField('Feed')) created_at = DateTimeField(required=True, default=datetime.now) def get_id(self): @@ -28,7 +30,8 @@ class User(Document, UserMixin): def __unicode__(self): return self.email -class Feed(Document): +class Feed(EmbeddedDocument): + oid = ObjectIdField(default=bson.objectid.ObjectId , primary_key=True) title = StringField(required=True) link = StringField(required=True) site_link = StringField(required=True) @@ -68,12 +71,12 @@ if __name__ == "__main__": db = connect('pyaggr3g470r1') db.drop_database('pyaggr3g470r1') - Feed.drop_collection() - try: - Article.drop_collection() - # pas de méthode save() pour un objet EmbeddedDocument. - except: - pass + + from werkzeug import generate_password_hash + password = generate_password_hash("admin") + user1 = User(firstname="Cédric", lastname="Bonhomme", \ + email="kimble.mandel@gmail.com", pwdhash=password) + import mongodb mongo = mongodb.Articles("127.0.0.1", 27017, \ @@ -97,4 +100,6 @@ if __name__ == "__main__": feed1 = Feed(title=feed["feed_title"], link=feed["feed_link"], site_link=feed["site_link"], mail=feed["mail"], articles=articles) - feed1.save()
\ No newline at end of file + #feed1.save() + user1.feeds.append(feed1) + user1.save()
\ No newline at end of file diff --git a/pyaggr3g470r/templates/feeds.html b/pyaggr3g470r/templates/feeds.html index 0893f982..1efa0b1f 100644 --- a/pyaggr3g470r/templates/feeds.html +++ b/pyaggr3g470r/templates/feeds.html @@ -4,7 +4,7 @@ <h1>You are subscribed to the following feeds</h1> <ul> {% for feed in feeds %} - <li><a href="/feed/{{ feed.id }}">{{ feed.title }}</a></li> + <li><a href="/feed/{{ feed.oid }}">{{ feed.title }}</a></li> {% endfor %} </ul> </div><!-- /.container --> diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html index bf17356f..46842382 100644 --- a/pyaggr3g470r/templates/home.html +++ b/pyaggr3g470r/templates/home.html @@ -5,7 +5,7 @@ <div class="row"> <div class="col-md-6 col-md-offset-3"> <h1>{{ feed.title }}</h1> - <a href="/articles/{{ feed.id }}"><i class="glyphicon glyphicon-th-list"></i></a> + <a href="/articles/{{ feed.oid }}"><i class="glyphicon glyphicon-th-list"></i></a> </div> </div> {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %} diff --git a/pyaggr3g470r/templates/unread.html b/pyaggr3g470r/templates/unread.html index bf17356f..46842382 100644 --- a/pyaggr3g470r/templates/unread.html +++ b/pyaggr3g470r/templates/unread.html @@ -5,7 +5,7 @@ <div class="row"> <div class="col-md-6 col-md-offset-3"> <h1>{{ feed.title }}</h1> - <a href="/articles/{{ feed.id }}"><i class="glyphicon glyphicon-th-list"></i></a> + <a href="/articles/{{ feed.oid }}"><i class="glyphicon glyphicon-th-list"></i></a> </div> </div> {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %} diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index f33ae425..12cff975 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -73,9 +73,9 @@ def logout(): @app.route('/') @login_required def home(): - #feeds = models.Feed.objects().order_by('title').fields(slice__articles=[0,9]) user = g.user - feeds = models.Feed.objects().fields(slice__articles=9) + #feeds = models.User.objects(email=g.user.email).order_by('title').fields(slice__feeds__articles=9).first().feeds + feeds = models.User.objects(email=g.user.email).fields(slice__feeds__articles=9).first().feeds return render_template('home.html', user=user, feeds=feeds) @app.route('/fetch/', methods=['GET']) @@ -93,18 +93,21 @@ def about(): @app.route('/feeds/', methods=['GET']) @login_required def feeds(): - feeds = models.Feed.objects() + feeds = models.User.objects(email=g.user.email).first().feeds return render_template('feeds.html', feeds=feeds) @app.route('/feed/<feed_id>', methods=['GET']) @login_required def feed(feed_id=None): - feed = models.Feed.objects(id=feed_id).first() - return render_template('feed.html', feed=feed) + user = models.User.objects(email=g.user.email, feeds__oid=feed_id).first() + for feed in user.feeds: + if str(feed.oid) == feed_id: + return render_template('feed.html', feed=feed) @app.route('/article/<article_id>', methods=['GET']) @login_required def article(article_id=None): + #user = models.User.objects(email=g.user.email, feeds__oid=feed_id).first() article = models.Article.objects(id=article_id).first() if not article.readed: article.readed = True @@ -122,9 +125,11 @@ def delete(article_id=None): @app.route('/articles/<feed_id>', methods=['GET']) @login_required def articles(feed_id=None): - feed = models.Feed.objects(id=feed_id).first() - #feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True) - return render_template('articles.html', feed=feed) + user = models.User.objects(email=g.user.email, feeds__oid=feed_id).first() + for feed in user.feeds: + if str(feed.oid) == feed_id: + #feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True) + return render_template('articles.html', feed=feed) @app.route('/favorites/', methods=['GET']) @login_required @@ -140,9 +145,9 @@ def favorites(): @app.route('/unread/', methods=['GET']) @login_required def unread(): - feeds = models.Feed.objects() + user = models.User.objects(email=g.user.email).first() result = [] - for feed in feeds: + for feed in user.feeds: feed.articles = [article for article in feed.articles if not article.readed] if len(feed.articles) != 0: result.append(feed) @@ -151,7 +156,8 @@ def unread(): @app.route('/management/', methods=['GET']) @login_required def management(): - nb_feeds = models.Feed.objects().count() - nb_articles = models.Article.objects().count() - nb_unread_articles = models.Article.objects(readed=False).count() + user = models.User.objects(email=g.user.email).first() + nb_feeds = len(user.feeds) + nb_articles = sum([len(feed) for feed in user.feeds]) + nb_unread_articles = sum([len([article for article in feed.articles if not article.readed]) for feed in user.feeds]) return render_template('management.html', nb_feeds=nb_feeds, nb_articles=nb_articles, nb_unread_articles=nb_unread_articles)
\ No newline at end of file |