app.py 1.73 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

Dylan Jones's avatar
Dylan Jones committed
3
4
from where.model import sa
from where.model.field_types import FieldType
Dylan Jones's avatar
app.py    
Dylan Jones committed
5
6
7

app = Flask(__name__)

8

Dylan Jones's avatar
app.py    
Dylan Jones committed
9
10
@app.route('/')
def index():
Dylan Jones's avatar
no slug    
Dylan Jones committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    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:
Dylan Jones's avatar
Dylan Jones committed
25
        # session = Session()
Dylan Jones's avatar
no slug    
Dylan Jones committed
26
27
28
        session.query(sa.Point).delete()
        session.query(sa.Field).delete()
        session.query(sa.Category).delete()
Dylan Jones's avatar
Dylan Jones committed
29
        # Water Fountain, the class.
Dylan Jones's avatar
no slug    
Dylan Jones committed
30
31
        wf = sa.Category()
        wf.name = "Water Fountain"
Dylan Jones's avatar
Dylan Jones committed
32
33
34
        wf.icon = "https://karel.pw/water.png"
        session.add(wf)
        session.commit()
Dylan Jones's avatar
Dylan Jones committed
35
        # coldness
Dylan Jones's avatar
Dylan Jones committed
36
37
        cd = sa.Field()
        cd.name = "Coldness"
Dylan Jones's avatar
Dylan Jones committed
38
        cd.slug = "coldness"
Dylan Jones's avatar
Dylan Jones committed
39
40
        cd.type = FieldType.RATING
        cd.category_id = wf.id
Dylan Jones's avatar
Dylan Jones committed
41
42
43
44
45
46
47
48
49
50
51
52
        # 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
Dylan Jones's avatar
Dylan Jones committed
53
54
55
56
        fn.lat = 38.829791
        fn.lon = -77.307043
        # fn.category_id = wf.id
        fn.category = wf
Dylan Jones's avatar
Dylan Jones committed
57
58
59
60
61
62
63
64
65
66
67
68
        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
Dylan Jones committed
69
        return "Success!"
Dylan Jones's avatar
app.py    
Dylan Jones committed
70
71
72
73


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