-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
53 lines (35 loc) · 1.28 KB
/
views.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
"""This module contains all app's routing."""
import controllers
from app import app
from config import IP_LIST
from functools import wraps
from flask import request, abort
def check_ip(func):
"""A wrapper for route functions that restrict access to wrapped routes from unknown IPs"""
@wraps(func)
def checker(*args, **kwargs):
if request.remote_addr not in IP_LIST:
return abort(403)
return func(*args, **kwargs)
return checker
@app.route("/")
def main():
return controllers.ViewMainPage().call()
@app.route("/xrates")
def view_rates():
return controllers.ViewAllRates().call()
@app.route("/api/xrates/<fmt>")
@app.route("/api")
def api_rates(fmt=None):
return controllers.GetApiRates().call(fmt)
@app.route("/update/<int:from_currency>/<int:to_currency>")
@app.route("/update/all")
def update_xrates(from_currency=None, to_currency=None):
return controllers.UpdateRates().call(from_currency, to_currency)
@app.route("/edit/<int:from_currency>/<int:to_currency>", methods=["GET", "POST"])
# @check_ip
def edit_xrate(from_currency, to_currency):
return controllers.EditRate().call(from_currency, to_currency)
@app.route("/logs/<logs_type>/<fmt>")
def view_logs(logs_type, fmt):
return controllers.ViewLogs().call(logs_type, fmt)