예제 #1
0
    def post(self):
        json_data = request.get_json()
        if not json_data:
            print('No data in this post. aborting')
            abort(400)

        username = json_data['username']
        age = int(json_data['age'])
        birthday = datetime.strptime(json_data['birthday'], "%Y-%m-%d")

        if not username or not age or not birthday:
            print("API-Create-post: Username or age or birthday missing")
            abort(400)
        if User.query_single_by_username(username):
            print("API-Create-post: Username already exists")
            abort(500)

        user = User(
            username=username,
            age=age,
            birthday=birthday
        )
        print(user)
        user.put()
        return user.to_json()