app.py 993 Bytes
Newer Older
Dylan Jones's avatar
app.py    
Dylan Jones committed
1
from flask import Flask
Dylan Jones's avatar
no slug    
Dylan Jones committed
2
3
from sqlalchemy.orm import Session

Dylan Jones's avatar
Dylan Jones committed
4
from where.field_types import FieldType
Dylan Jones's avatar
no slug    
Dylan Jones committed
5
from . import sa
Dylan Jones's avatar
app.py    
Dylan Jones committed
6
7
8

app = Flask(__name__)

9

Dylan Jones's avatar
app.py    
Dylan Jones committed
10
11
@app.route('/')
def index():
Dylan Jones's avatar
no slug    
Dylan Jones committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    return """
<head>
</head>
<body>
    <h1>W H E R E</h1>
    <p>This is the WHERE project.</p>
    <a href='/test_data'>Click here to nuke the database and make it all be test data.</a>
</body>
    """


@app.route('/test_data')
def test_data():
    with sa.session_context() as session:
        session = Session()
        session.query(sa.Point).delete()
        session.query(sa.Field).delete()
        session.query(sa.Category).delete()
Dylan Jones's avatar
Dylan Jones committed
30
        # Water Fountain, the class.
Dylan Jones's avatar
no slug    
Dylan Jones committed
31
32
        wf = sa.Category()
        wf.name = "Water Fountain"
Dylan Jones's avatar
Dylan Jones committed
33
34
35
        wf.icon = "https://karel.pw/water.png"
        session.add(wf)
        session.commit()
Dylan Jones's avatar
Dylan Jones committed
36
        # coldness
Dylan Jones's avatar
Dylan Jones committed
37
38
39
40
        cd = sa.Field()
        cd.name = "Coldness"
        cd.type = FieldType.RATING
        cd.category_id = wf.id
Dylan Jones's avatar
Dylan Jones committed
41

Dylan Jones's avatar
app.py    
Dylan Jones committed
42
43
44
45


if __name__ == '__main__':
    app.run()