app.py 1.64 KB
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
        cd = sa.Field()
        cd.name = "Coldness"
Dylan Jones's avatar
Dylan Jones committed
39
        cd.slug = "coldness"
Dylan Jones's avatar
Dylan Jones committed
40
41
        cd.type = FieldType.RATING
        cd.category_id = wf.id
Dylan Jones's avatar
Dylan Jones committed
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
        # filler
        fl = sa.Field()
        fl.slug = "bottle_filler"
        fl.name = "Has Bottle Filler"
        fl.type = FieldType.BOOLEAN
        fl.category_id = wf.id
        session.add(cd)
        session.add(fl)
        session.commit()
        # an actual instance!
        fn = sa.Point()
        fn.name = None
        fn.category_id = wf.id
        fn.parent_id = None
        fn.attributes = {
            "coldness": {
                "num_reviews": 32,
                "average_rating": 0.5
            },
            "bottle_filler": {
                "value": True
            }
        }
        session.add(fn)
        session.commit()
Dylan Jones's avatar
app.py    
Dylan Jones committed
67
68
69
70


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