-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
90 lines (64 loc) · 2.01 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
import os
import sys
import click
from flask import Flask, render_template, request, url_for, redirect, flash
from flask_sqlalchemy import SQLAlchemy
# SQLite URI compatible
WIN = sys.platform.startswith('win')
if WIN:
prefix = 'sqlite:///'
else:
prefix = 'sqlite:////'
app = Flask(__name__)
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'dev')
app.config['SQLALCHEMY_DATABASE_URI'] = prefix + os.path.join(os.path.dirname(app.root_path), os.getenv('DATABASE_FILE', 'data.db'))
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
@app.cli.command()
@click.option('--drop', is_flag=True, help='Create after drop.')
def initdb(drop):
"""Initialize the database."""
if drop:
db.drop_all()
db.create_all()
click.echo('Initialized database.')
@app.cli.command()
def forge():
"""Generate fake data."""
db.create_all()
name = 'Q-Classification'
user = User(name=name)
# res = 0
db.session.add(user)
# db.session.add(res)
db.session.commit()
click.echo('Done.')
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
# class Movie(db.Model):
# id = db.Column(db.Integer, primary_key=True)
# title = db.Column(db.String(60))
# year = db.Column(db.String(4))
@app.context_processor
def inject_user():
user = User.query.first()
return dict(user=user)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
x = int(request.form['group'])
y = int(request.form['group1'])
z = int(request.form['group2'])
if not x > 0 or not y >0:
flash('Invalid input.')
return redirect(url_for('index'))
res = x*y*z
# return redirect(url_for('index'))
return render_template('edit.html')
# movies = Movie.query.all()
return render_template('index.html')