예제 #1
0
def startup():
    db.create_all()
    # create settings object if it doesn't exist
    settings = Settings.query.first()
    if not settings:
        s = Settings()
        # load example questions json
        with open("data/question_example.json", "r") as example:
            s.questions = example.read()
        # detect number of response IDs required
        data = json.loads(s.questions)
        ids = len(data)
        for d in data:
            if "data" in d.keys():
                ids += len(d["data"])
        s.required_ids = ids
        # set example response text
        with open("data/response_example.txt", "r") as resp:
            s.response_body = resp.read()
        db.session.add(s)
        db.session.commit()