コード例 #1
0
ファイル: cars.py プロジェクト: uday1bhanu/it490-car-calendar
def add_car(user_id: int, make: str, model: str, year: int, mileage: int,
            weekly_mileage: int):
    """
    Insert a car row into the cars table.
    """
    message = lambda m, s=False: {'message': m, 'success': s}
    query = """
        INSERT INTO `cars` (
            `user_id`,  `make`, `model`, `year`, `mileage`, `weekly_mileage`
        ) VALUES (%s, %s, %s, %s, %s, %s);
    """

    user = users.get_by_id(user_id)
    if not user:
        return message('USER_NOT_FOUND')

    try:
        db.execute(query,
                   (user_id, make, model, year, mileage, weekly_mileage))
        conn.commit()
        return message('Car added!', True)

    except IntegrityError:
        ez_log('DATA', 'DATA_WARNING',
               'Car could not be added for user "%s".' % user_id)
        return message('Something went wrong while adding your car.', False)
コード例 #2
0
 def post(self):
     body = request.get_json()
     title = body["title"]
     try:
         cursor.execute("INSERT INTO categories (title) VALUES(%s)",
                        (title, ))
         conn.commit()
         return {"body": body}, 200
     except:
         conn.rollback()
         print("already exists..")
         abort(403, error_message='This already exists')
     return last_id
コード例 #3
0
 def post(self):
     body = request.get_json()
     username = body["username"]
     password = hash_password(body["password"])
     email = body["email"]
     cursor.execute(
         "INSERT INTO users (username, user_password, email, user_point, badge_id) VALUES(%s, %s, %s, %s, %s)",
         (username, password, email, 1000, 1))
     conn.commit()
     return {
         "username": username,
         "password": password,
         "email": email
     }, 200
コード例 #4
0
ファイル: badges.py プロジェクト: frkntplglu/flask-react-app
 def post(self):
     body = request.get_json()
     title = body["title"]
     cursor.execute("INSERT INTO badges (title) VALUES(%s)", (title, ))
     conn.commit()
     return {"body": body}, 200