aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-10-13 23:31:14 +0200
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-10-13 23:31:14 +0200
commit153724fc133f461dd800e4af2e591752489204b5 (patch)
tree6f283d389a89856ad57b988c7b0713047ef23fa5
parentfixed bug in /articles page. (diff)
downloadnewspipe-153724fc133f461dd800e4af2e591752489204b5.tar.gz
newspipe-153724fc133f461dd800e4af2e591752489204b5.tar.bz2
newspipe-153724fc133f461dd800e4af2e591752489204b5.zip
Trying to sort articles (SortedListField(ReferenceField('Article')).
-rw-r--r--pyaggr3g470r/feedgetter.py2
-rw-r--r--pyaggr3g470r/models.py24
-rw-r--r--pyaggr3g470r/templates/article.html3
-rw-r--r--pyaggr3g470r/templates/articles.html2
-rw-r--r--pyaggr3g470r/templates/home.html2
-rw-r--r--pyaggr3g470r/views.py14
6 files changed, 37 insertions, 10 deletions
diff --git a/pyaggr3g470r/feedgetter.py b/pyaggr3g470r/feedgetter.py
index 487fa3b0..491d110c 100644
--- a/pyaggr3g470r/feedgetter.py
+++ b/pyaggr3g470r/feedgetter.py
@@ -102,7 +102,6 @@ class FeedGetter(object):
exist = models.Article.objects(link=article.link).first()
if exist != None:
- print("Already downloaded!")
continue
description = ""
@@ -149,6 +148,7 @@ class FeedGetter(object):
article_title, description)).start()
"""
feed.articles.extend(articles)
+ feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True)
feed.save()
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py
index 996ea1d4..e9f115d1 100644
--- a/pyaggr3g470r/models.py
+++ b/pyaggr3g470r/models.py
@@ -29,9 +29,13 @@ class Feed(Document):
link = StringField(required=True)
site_link = StringField(required=True)
mail = BooleanField()
- articles = ListField(ReferenceField('Article', dbref = False))
+ articles = SortedListField(ReferenceField('Article', dbref = False))
created_date = DateTimeField(required=True, default=datetime.now)
+ meta = {
+ 'ordering': ['+title']
+ }
+
def __str__(self):
return 'Feed: %s' % self.title
@@ -44,12 +48,21 @@ class Article(Document):
like = BooleanField()
retrieved_date = DateTimeField(required=True, default=datetime.now)
+ meta = {
+ 'ordering': ['-date'],
+ 'indexes': [
+ {'fields': ['-date'],
+ 'sparse': True, 'types': False },
+ ]
+ }
+
def __str__(self):
return 'Article: %s' % self.title
if __name__ == "__main__":
# Point of entry in execution mode
- connect('pyaggr3g470r1')
+ db = connect('pyaggr3g470r1')
+ db.drop_database('pyaggr3g470r1')
Feed.drop_collection()
try:
@@ -64,8 +77,9 @@ if __name__ == "__main__":
feeds = mongo.get_all_feeds()
for feed in feeds:
articles = []
-
- for article in mongo.get_articles(feed["feed_id"]):
+ feed_articles = mongo.get_articles(feed["feed_id"])
+ #feed_articles = sorted(feed_articles, key=lambda t: t['article_date'], reverse=True)
+ for article in feed_articles:
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"], \
@@ -78,6 +92,8 @@ if __name__ == "__main__":
# pas de méthode save() pour un objet EmbeddedDocument.
pass
+ sorted(articles, key=lambda t: t.date, reverse=True)
+
feed1 = Feed(title=feed["feed_title"], link=feed["feed_link"],
site_link=feed["site_link"], mail=feed["mail"],
articles=articles)
diff --git a/pyaggr3g470r/templates/article.html b/pyaggr3g470r/templates/article.html
index 28c53714..d695a423 100644
--- a/pyaggr3g470r/templates/article.html
+++ b/pyaggr3g470r/templates/article.html
@@ -2,9 +2,10 @@
{% block content %}
<div class="container">
<div class="jumbotron">
- <h1>{{ article.title }}</h1>
+ <h2>{{ article.title }}</h2>
<h4>{{ article.link }}</h4>
<h6>{{ article.date }}</h6>
+ <a href="/delete/{{ article.id }}"><i class="glyphicon glyphicon-remove"></i></a>
</div>
<div class="jumbotron">
{{ article.content|safe }}
diff --git a/pyaggr3g470r/templates/articles.html b/pyaggr3g470r/templates/articles.html
index 146769ac..c0abccdf 100644
--- a/pyaggr3g470r/templates/articles.html
+++ b/pyaggr3g470r/templates/articles.html
@@ -1,7 +1,7 @@
{% extends "layout.html" %}
{% block content %}
<div class="container">
- {% for number in range(0, feed.articles|sort(attribute='date')|length-2, 3) %}
+ {% for number in range(0, feed.articles|length-2, 3) %}
<div class="row">
{% for n in range(number, number+3) %}
<div class="col-xs-6 col-sm-4 col-md-4">
diff --git a/pyaggr3g470r/templates/home.html b/pyaggr3g470r/templates/home.html
index aa390d2d..0344263f 100644
--- a/pyaggr3g470r/templates/home.html
+++ b/pyaggr3g470r/templates/home.html
@@ -8,7 +8,7 @@
<a href="/articles/{{ feed.id }}"><i class="glyphicon glyphicon-th-list"></i></a>
</div>
</div>
- {% for number in range(0, feed.articles|sort(attribute='date')|length-2, 3) %}
+ {% for number in range(0, feed.articles|length-2, 3) %}
<div class="row">
{% for n in range(number, number+3) %}
<div class="col-xs-6 col-sm-4 col-md-4">
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index a1a2055f..fa67393a 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -17,7 +17,8 @@ mail = Mail()
@app.route('/')
def home():
- feeds = models.Feed.objects().order_by('title').fields(slice__articles=[0,9])
+ #feeds = models.Feed.objects().order_by('title').fields(slice__articles=[0,9])
+ feeds = models.Feed.objects().fields(slice__articles=[0,9])
return render_template('home.html', feeds=feeds)
@app.route('/fetch/', methods=['GET'])
@@ -33,7 +34,7 @@ def about():
@app.route('/feeds/', methods=['GET'])
def feeds():
feeds = models.Feed.objects()
- return render_template('feedss.html', feeds=feeds)
+ return render_template('feeds.html', feeds=feeds)
@app.route('/feed/<feed_id>', methods=['GET'])
def feed(feed_id=None):
@@ -48,9 +49,18 @@ def article(article_id=None):
article.save()
return render_template('article.html', article=article)
+@app.route('/delete/<article_id>', methods=['GET'])
+def delete(article_id=None):
+ article = models.Article.objects(id=article_id).first()
+ article.delete()
+ article.save()
+ return redirect(url_for('home'))
+
@app.route('/articles/<feed_id>', methods=['GET'])
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)
+ #feed.save()
return render_template('articles.html', feed=feed)
@app.route('/favorites/', methods=['GET'])
bgstack15