controller.py 943 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python
  2. import argparse
  3. from flask import Flask, render_template, request
  4. from model import InputForm
  5. app = Flask(__name__)
  6. @app.route("/", methods=["GET", "POST"])
  7. def index():
  8. form = InputForm(request.form)
  9. if request.method == "POST" and form.validate():
  10. result = compute(form.A.data, form.b.data, form.w.data, form.T.data)
  11. else:
  12. result = None
  13. return render_template(TEMPLATE, form=form, result=result)
  14. if __name__ == "__main__":
  15. parser = argparse.ArgumentParser(description="Damped sinusoidal wave")
  16. parser.add_argument("--fmt", choices=["png", "svg"], default="png", help="Image file format")
  17. args = parser.parse_args()
  18. if args.fmt == "png":
  19. from compute import compute_png as compute
  20. TEMPLATE = "view_png.html"
  21. if args.fmt == "svg":
  22. from compute import compute_svg as compute
  23. TEMPLATE = "view_svg.html"
  24. app.run(debug=True)