diff options
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/models.py | 2 | ||||
-rw-r--r-- | pyaggr3g470r/templates/favorites.html | 28 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 11 |
3 files changed, 38 insertions, 3 deletions
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index 8ce361bb..996ea1d4 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -32,7 +32,7 @@ class Feed(Document): articles = ListField(ReferenceField('Article', dbref = False)) created_date = DateTimeField(required=True, default=datetime.now) - def __unicode__(self): + def __str__(self): return 'Feed: %s' % self.title class Article(Document): diff --git a/pyaggr3g470r/templates/favorites.html b/pyaggr3g470r/templates/favorites.html new file mode 100644 index 00000000..0b912286 --- /dev/null +++ b/pyaggr3g470r/templates/favorites.html @@ -0,0 +1,28 @@ +{% extends "layout.html" %} +{% block content %} +<div class="container"> + {% for feed in favorites %} + <div class="row"> + <div class="col-md-6 col-md-offset-3"> + <h1>{{ feed }}</h1> + </div> + </div> + {% for number in range(0, favorites[feed]|length-2, 3) %} + <div class="row"> + <div class="col-xs-6 col-sm-4 col-md-4"> + <h2><a href="/article/{{ favorites[feed][number].id }}">{{ favorites[feed][number].title }}</a><h2> + <h6>{{ favorites[feed][number].date }}</h6> + </div> + <div class="col-xs-6 col-sm-4 col-md-4"> + <h2><a href="/article/{{ favorites[feed][number+1].id }}">{{ favorites[feed][number+1].title }}</a><h2> + <h6>{{ favorites[feed][number+1].date }}</h6> + </div> + <div class="col-xs-6 col-sm-4 col-md-4"> + <h2><a href="/article/{{ favorites[feed][number+2].id }}">{{ favorites[feed][number+2].title }}</a><h2> + <h6>{{ favorites[feed][number+2].date }}</h6> + </div> + </div> + {% endfor %} + {% endfor %} +</div><!-- /.container --> +{% endblock %}
\ No newline at end of file diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 642609c9..7d5eeb30 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -5,6 +5,8 @@ from flask import render_template, request, flash, session, url_for, redirect from wtforms import TextField, PasswordField, SubmitField, validators from flask.ext.mail import Message, Mail +from collections import defaultdict + #from forms import ContactForm, SignupForm, SigninForm from pyaggr3g470r import app, db @@ -53,5 +55,10 @@ def articles(feed_id=None): @app.route('/favorites/', methods=['GET']) def favorites(): - feed = models.Feed.objects().fields(articles.like=True) - return render_template('favorites.html', feed=feed)
\ No newline at end of file + favorites = defaultdict(list) + for feed in models.Feed.objects(): + for article in feed.articles: + if article.like: + favorites[feed.title].append(article) + + return render_template('favorites.html', favorites=favorites)
\ No newline at end of file |