1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#! /usr/bin/env python
# -*- coding: utf-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
import feedgetter
import models
mail = Mail()
@app.route('/')
def home():
#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'])
def fetch():
feed_getter = feedgetter.FeedGetter()
feed_getter.retrieve_feed()
return redirect(url_for('home'))
@app.route('/about/', methods=['GET'])
def about():
return render_template('about.html')
@app.route('/feeds/', methods=['GET'])
def feeds():
feeds = models.Feed.objects()
return render_template('feeds.html', feeds=feeds)
@app.route('/feed/<feed_id>', methods=['GET'])
def feed(feed_id=None):
feed = models.Article.objects(id=feed_id).first()
return render_template('feed.html', feed=feed)
@app.route('/article/<article_id>', 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('/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)
return render_template('articles.html', feed=feed)
@app.route('/favorites/', methods=['GET'])
def favorites():
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)
@app.route('/management/', methods=['GET'])
def management():
nb_article = len(models.Article.objects())
return render_template('management.html', nb_article=nb_article)
|