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:
tsb1995 2019-12-26 18:06:38 -08:00
parent 23293eb503
commit 918699fe13
4 changed files with 18 additions and 14 deletions

Binary file not shown.

14
app.py
View File

@ -1,6 +1,6 @@
from flask import Flask, render_template, request, redirect, Response
from sympy import *
from helpers import apology
from helpers import apology, setup_symbols, gif_apology
import numpy as np
import matplotlib
matplotlib.use('Agg')
@ -251,18 +251,6 @@ def errorhandler(e):
e = InternalServerError()
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__':

View File

@ -1,7 +1,10 @@
import requests
from flask import redirect, render_template, request, session
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):
@ -36,3 +39,16 @@ def login_required(f):
def usd(value):
"""Format value as USD."""
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