Moved gif_apology and setup_symbols to helpers.py and imported from there. Setup gif_apology to randomly choose gifs to display
This commit is contained in:
parent
23293eb503
commit
918699fe13
Binary file not shown.
14
app.py
14
app.py
|
|
@ -1,6 +1,6 @@
|
||||||
from flask import Flask, render_template, request, redirect, Response
|
from flask import Flask, render_template, request, redirect, Response
|
||||||
from sympy import *
|
from sympy import *
|
||||||
from helpers import apology
|
from helpers import apology, setup_symbols, gif_apology
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib
|
import matplotlib
|
||||||
matplotlib.use('Agg')
|
matplotlib.use('Agg')
|
||||||
|
|
@ -251,18 +251,6 @@ def errorhandler(e):
|
||||||
e = InternalServerError()
|
e = InternalServerError()
|
||||||
return apology(e.name, e.code)
|
return apology(e.name, e.code)
|
||||||
|
|
||||||
def setup_symbols(f):
|
|
||||||
f = sympify(f)
|
|
||||||
|
|
||||||
# replace commonly used variables with x
|
|
||||||
for letter in [x, y, z, t, X, Y, Z, T]:
|
|
||||||
f = f.subs(letter, x)
|
|
||||||
return f
|
|
||||||
|
|
||||||
def gif_apology(message="oopsy", code=400):
|
|
||||||
"Render gif failure"
|
|
||||||
PATH = 'static/img/gifs/reaction' + str(2) + '.gif'
|
|
||||||
return render_template("gif_apology.html", PATH=PATH)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
18
helpers.py
18
helpers.py
|
|
@ -1,7 +1,10 @@
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from flask import redirect, render_template, request, session
|
from flask import redirect, render_template, request, session
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from sympy import *
|
||||||
|
import random
|
||||||
|
|
||||||
|
x, y, z, t, X, Y, Z, T = symbols('x y z t X Y Z T')
|
||||||
|
|
||||||
|
|
||||||
def apology(message, code=400):
|
def apology(message, code=400):
|
||||||
|
|
@ -36,3 +39,16 @@ def login_required(f):
|
||||||
def usd(value):
|
def usd(value):
|
||||||
"""Format value as USD."""
|
"""Format value as USD."""
|
||||||
return f"${value:,.2f}"
|
return f"${value:,.2f}"
|
||||||
|
|
||||||
|
def setup_symbols(f):
|
||||||
|
f = sympify(f)
|
||||||
|
|
||||||
|
# replace commonly used variables with x
|
||||||
|
for letter in [x, y, z, t, X, Y, Z, T]:
|
||||||
|
f = f.subs(letter, x)
|
||||||
|
return f
|
||||||
|
|
||||||
|
def gif_apology(message="oopsy", code=400):
|
||||||
|
"Render gif failure"
|
||||||
|
PATH = 'static/img/gifs/reaction' + str(random.randint(1,5)) + '.gif'
|
||||||
|
return render_template("gif_apology.html", PATH=PATH)
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 21 KiB |
Loading…
Reference in New Issue