Skip to content

Commit 35fc7f0

Browse files
committed
Implemented handlers
1 parent db6cd30 commit 35fc7f0

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

models/article.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Article(db.Model):
99
guid = db.Column(db.String(255), nullable=False)
1010
unread = db.Column(db.Boolean, default=True, nullable=False)
1111
source_id = db.Column(db.Integer, db.ForeignKey('source.id'), nullable=False)
12-
source = db.relationship('Source', db.backref('articles', lazy=True))
12+
source = db.relationship('Source', backref=db.backref('articles', lazy=True))
1313
date_added = db.Column(db.DateTime, default=datetime.datetime.utcnow)
1414
date_published = db.Column(db.DateTime)
1515
__table_args__ = (

routes/__init__.py

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1-
from flask import redirect, request
1+
from flask import abort, redirect, request
22
from app import app
3+
from db import db
4+
from models.article import Article
5+
from models.source import Source
6+
import feed
37

4-
@app.route('/test', methods=['GET'])
5-
def test_get():
6-
return '<form method="POST"><input name="username"></form>'
8+
@app.route('/', methods=['GET'])
9+
def index_get():
10+
query = Article.query
11+
query = query.filter(Article.unread == True)
12+
query = query.order_by(Article.date_added.desc())
13+
articles = query.all()
14+
return str([article.title for article in articles])
715

8-
@app.route('/test', methods=['POST'])
9-
def test_post():
10-
username = request.form.get('username', '???')
11-
return 'Hello ' + username
16+
@app.route('/read/<int:article_id>', methods=['GET'])
17+
def read_article_get(article_id):
18+
article = Article.query.get(article_id)
19+
article.unread = False
20+
db.session.commit()
21+
return redirect(article.link)
22+
23+
@app.route('/sources', methods=['GET'])
24+
def sources_get():
25+
query = Source.query
26+
query = query.order_by(Source.title)
27+
sources = query.all()
28+
return str([source.title for source in sources])
29+
30+
@app.route('/sources', methods=['POST'])
31+
def sources_post():
32+
feed_url = request.form['feed']
33+
parsed = feed.parse(feed_url)
34+
feed_source = feed.get_source(parsed)
35+
source = Source.insert_from_feed(feed_url, feed_source)
36+
return redirect('/sources')

0 commit comments

Comments
 (0)