コード例 #1
0
def create_store() -> Response:

    form = CreateStoreForm(request.form)

    if form.validate_on_submit():
        if request.headers.getlist("X-Forwarded-For"):
            last_ip = request.headers.getlist("X-Forwarded-For")[0]
        else:
            last_ip = request.remote_addr

        store = Store(name=form.data['name'],
                      lat=float(form.data['lat']),
                      lng=float(form.data['lng']),
                      address=form.data['address'],
                      switchable=str2bool(form.data['switchable']),
                      last_ip=last_ip)
        success = store.create()

        if success:
            result = store_schema.dump(store)
            return jsonify(result.data), 201
        else:
            return Response(status=500)
    else:
        logger.error(str(form.errors))
        return Response(status=400)
コード例 #2
0
def create_store():
    request_data = request.form
    store = Store(request_data['name'], float(request_data['lat']),
                  float(request_data['lng']),
                  request_data['address'], request_data['news'],
                  str2bool(request_data['switchable']), request.remote_addr)
    success = store.create()
    if success:
        return Response(status=201)
    else:
        return Response(status=500)