-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.py
46 lines (31 loc) · 1.24 KB
/
application.py
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
from flask import Flask, g, render_template, request
from book import Book
from calibre import Calibre
application = Flask(__name__)
application.config.from_pyfile('configuration.py')
@application.route('/')
def main_page():
return render_template('main_page.html', guide_url=application.config['GUIDE_URL'], calibre_url=application.config['CALIBRE_URL'])
@application.route('/<int:id>/')
def show_book_info(id):
book = Book(g.calibre, id)
return render_book_info(book)
@application.before_request
def before_request():
library_path = None
if 'LIBRARY_PATH' in application.config:
library_path = application.config['LIBRARY_PATH']
g.calibre = Calibre(library_path)
def render_book_info(book):
return render_template('book_info.html', book=book, shelves=application.config['SHELVES'], calibre_url=application.config['CALIBRE_URL'])
@application.route('/<int:id>/update_location', methods=['POST'])
def update_location(id):
book = Book(g.calibre, id)
if 'update_person' in request.form:
new_location = request.form['location']
else:
new_location = request.form['shelf']
book.update_location(new_location)
return render_book_info(book)
if __name__ == '__main__':
application.run()