From 9fdc9836902f0b1bb8cd9f087cdd238b2e96c6de Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 13 Oct 2013 12:37:17 +0200 Subject: Mark an article as read. --- pyaggr3g470r/__init__.py | 6 +++--- pyaggr3g470r/models.py | 21 +++++++++------------ pyaggr3g470r/views.py | 3 +++ 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/__init__.py b/pyaggr3g470r/__init__.py index 41986fb4..f1c26025 100644 --- a/pyaggr3g470r/__init__.py +++ b/pyaggr3g470r/__init__.py @@ -9,7 +9,7 @@ from flask.ext.mongoengine import MongoEngine from flask.ext.admin import Admin from flask.ext.admin.contrib.mongoengine import ModelView -from flask_debugtoolbar import DebugToolbarExtension +#from flask_debugtoolbar import DebugToolbarExtension import conf from models import * @@ -36,8 +36,8 @@ from views import mail mail.init_app(app) # For Flask-DebugToolbar -app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False -toolbar = DebugToolbarExtension(app) +#app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False +#toolbar = DebugToolbarExtension(app) # Administration panel admin = Admin(app, name='pyAggr3g470r') diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index a36c27fe..8ce361bb 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -24,21 +24,18 @@ class User(Document, UserMixin): def __unicode__(self): return self.nickname -class Feed(DynamicDocument): +class Feed(Document): title = StringField(required=True) link = StringField(required=True) - image = StringField(required=True) site_link = StringField(required=True) mail = BooleanField() - #articles = ListField(EmbeddedDocumentField('Article')) articles = ListField(ReferenceField('Article', dbref = False)) created_date = DateTimeField(required=True, default=datetime.now) def __unicode__(self): return 'Feed: %s' % self.title -#class Article(EmbeddedDocument): -class Article(DynamicDocument): +class Article(Document): date = DateTimeField(required=True) link = StringField(required=True) title = StringField(required=True) @@ -61,10 +58,9 @@ if __name__ == "__main__": except: pass - import conf import mongodb - mongo = mongodb.Articles(conf.MONGODB_ADDRESS, conf.MONGODB_PORT, \ - conf.MONGODB_DBNAME, conf.MONGODB_USER, conf.MONGODB_PASSWORD) + mongo = mongodb.Articles("127.0.0.1", 27017, \ + "pyaggr3g470r", "***", "") feeds = mongo.get_all_feeds() for feed in feeds: articles = [] @@ -72,7 +68,8 @@ if __name__ == "__main__": for article in mongo.get_articles(feed["feed_id"]): article1 = Article(date=article["article_date"], link=article["article_link"], \ title=article["article_title"], content=article["article_content"], \ - readed=article["article_readed"], like=article["article_like"]) + readed=article["article_readed"], like=article["article_like"], \ + retrieved_date=article["article_date"]) articles.append(article1) try: @@ -82,10 +79,10 @@ if __name__ == "__main__": pass feed1 = Feed(title=feed["feed_title"], link=feed["feed_link"], - image=feed["feed_image"], site_link=feed["site_link"], mail=feed["mail"], + site_link=feed["site_link"], mail=feed["mail"], articles=articles) feed1.save() - for feed in Feed.objects: - print(feed.articles[0].title) \ No newline at end of file + #for feed in Feed.objects: + #print(feed.articles[0].title) \ No newline at end of file diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index b4f93ddf..78e89633 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -41,6 +41,9 @@ def feed(feed_id=None): @app.route('/article/', methods=['GET']) def article(article_id=None): article = models.Article.objects(id=article_id).first() + if not article.readed: + article.readed = True + article.save() return render_template('article.html', article=article) @app.route('/articles/', methods=['GET']) -- cgit