forked from itucsdb1920/itucsdb1920
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
58 lines (46 loc) · 2.62 KB
/
server.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
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask
from flask_login import LoginManager
import views
from database import Database
from book import Book
from user import get_user
lm = LoginManager()
@lm.user_loader
def load_user(user_id):
return get_user(user_id)
def create_app():
app = Flask(__name__)
app.config.from_object("settings")
app.add_template_global(name="zip", f=zip)
app.add_url_rule("/", view_func=views.home_page)
app.add_url_rule("/register", view_func=views.registration_page, methods=["GET", "POST"])
app.add_url_rule("/login", view_func=views.login_page, methods=["GET", "POST"])
app.add_url_rule("/logout", view_func=views.logout_page)
app.add_url_rule("/books/", view_func=views.books_page, methods=["GET", "POST"])
app.add_url_rule("/books/<int:book_id>", view_func=views.book_page, methods=["GET", "POST"])
app.add_url_rule("/books/<int:book_id>/edit", view_func=views.book_edit_page, methods=["GET", "POST"])
app.add_url_rule("/books/<int:book_id>/delete", view_func=views.delete_book, methods=["POST"])
app.add_url_rule("/new-book", view_func=views.book_add_page, methods=["GET", "POST"])
app.add_url_rule("/reviews/<int:review_id>/delete", view_func=views.delete_review, methods=["POST"])
app.add_url_rule("/reviews/<int:review_id>/edit", view_func=views.review_edit_page, methods=["GET", "POST"])
app.add_url_rule("/profile/<int:user_id>", view_func=views.profile_page)
app.add_url_rule("/profile/<int:user_id>/edit", view_func=views.profile_edit_page, methods=["GET", "POST"])
app.add_url_rule("/profile/<int:user_id>/delete", view_func=views.delete_profile, methods=["POST"])
app.add_url_rule("/profile/<int:user_id>/delete_profile_picture", view_func=views.delete_profile_picture, methods=["POST"])
app.add_url_rule("/profile/<int:user_id>/make_admin", view_func=views.make_admin, methods=["POST"])
app.add_url_rule("/profile/<int:user_id>/revoke_admin", view_func=views.revoke_admin, methods=["POST"])
app.add_url_rule("/author/<int:author_id>", view_func=views.author_page)
app.add_url_rule("/author/<int:author_id>/edit", view_func=views.author_edit_page, methods=["GET", "POST"])
app.add_url_rule("/author/<int:author_id>/delete", view_func=views.delete_author, methods=["POST"])
app.add_url_rule("/search", view_func=views.search_page, methods=["GET"])
lm.init_app(app)
lm.login_view = "login_page"
db = Database(app.config["DATABASE_URL"])
app.config["db"] = db
return app
if __name__ == "__main__":
app = create_app()
port = app.config.get("PORT", 5000)
app.run(host="0.0.0.0", port=port)
else:
app = create_app()