예제 #1
0
def newCar(dealership_id):
    if 'username' not in login_session:
        return redirect('/login')
    dealership = session.query(Dealership).filter_by(id=dealership_id).one()
    if login_session['user_id'] != dealership.user_id:
        return "<script>function myFunction() {alert('You are not authorized  \
               to add inventory items to this dealership. Please create your \
               own dealership in order to add cars.');} \
               </script><body onload='myFunction()''>"

    if request.method == 'POST':
        newCar = Car(name=request.form['name'],
                     brand=request.form['brand'],
                     year=request.form['year'],
                     color=request.form['color'],
                     description=request.form['description'],
                     price=request.form['price'],
                     type=request.form['type'],
                     dealership_id=dealership_id,
                     user_id=dealership.user_id)
        if newCar.name != []:
            session.add(newCar)
            session.commit()
            flash('New %s Car Successfully Created' % (newCar.name))
            return redirect(
                url_for('showInventory', dealership_id=dealership_id))
        else:
            return render_template('newcar.html', dealership_id=dealership_id)
    else:
        return render_template('newcar.html', dealership_id=dealership_id)
예제 #2
0
def post_new():
    if request.method == 'POST':
        new_car = Car(model=request.json["model"],
                      color=request.json["color"],
                      year=request.json["year"],
                      license_plate=request.json["license_plate"])
        session.add(new_car)
        session.commit()
        return "201, OK"
        session.commit()
        return "201, OK"
예제 #3
0
def addCar():
    if request.method == 'POST':
        name = request.form['name']
        description = request.form['desc']
        manf = request.form['cat']
        user = session.query(User).filter_by(
            username=login_session['username']).one()
        addCar = Car(user_id=user.id,
                     name=name,
                     description=description,
                     manufacturer=manf)
        session.add(addCar)
        session.commit()
        return redirect(url_for('loggedIn'))
    else:
        return render_template('addCar.html')
예제 #4
0
def create_car():
    if 'username' not in login_session:
        return redirect(url_for('show_login'))
    else:
        if request.method == 'POST':
            if len(request.files) > 0:
                file = request.files['image']
                hashed_filename = hashlib.md5(
                    str(uuid.uuid4()) + file.filename).hexdigest()
                f = os.path.join(app.config['UPLOAD_FOLDER'], hashed_filename)
                file.save(f)
            else:
                hashed_filename = 'placeholder.png'
            newCar = Car(category=request.form['category'],
                         year=request.form['year'],
                         make=request.form['make'],
                         model=request.form['model'],
                         mileage=request.form['mileage'],
                         price=request.form['price'],
                         description=request.form['description'],
                         image=hashed_filename,
                         user_id=login_session['user_id'],
                         dt_created=calendar.timegm(time.gmtime()))
            session.add(newCar)
            session.commit()
            print newCar.mileage
            print newCar.price

            car = session.query(Car).filter_by(
                user_id=login_session['user_id']).order_by(
                    Car.dt_created.desc()).first()
            flash_message = (
                "You successfully created a post for a %s %s %s!" %
                (car.year, car.make, car.model))
            flash(flash_message, 'success')

            return redirect(
                url_for('read_car', category=car.category, car_id=car.id))
        else:
            return render_template('create.html')
예제 #5
0
# Create dummy users
for user in users:
    new_user = User(name=user[0], email=user[1])
    session.add(new_user)
    session.commit()
    print('Added dummy user: %s!' % new_user.name)

print "Creating dummy cars"
# Create dummy cars
for i in range(0, len(categories)):
    src_filename = images[i]
    src_file = os.path.join(src_dir, src_filename)
    dst_file = os.path.join(dst_dir, src_filename)
    shutil.copy(src_file, dst_dir)
    hashed_filename = hashlib.md5(str(uuid.uuid4()) + src_filename).hexdigest()
    dst_renamed = os.path.join(dst_dir, hashed_filename)
    os.rename(dst_file, dst_renamed)
    new_car = Car(category=categories[i],
                  year=random.randint(1900, 2015),
                  make=makes[i],
                  model=models[i],
                  mileage=random.randint(1, 500000),
                  price=random.randint(500, 80000),
                  description=description,
                  image=hashed_filename,
                  user_id=random.randint(1, 4),
                  dt_created=calendar.timegm(time.gmtime()))
    session.add(new_car)
    session.commit()
    print('Added %s %s %s!' % (new_car.year, new_car.make, new_car.model))
예제 #6
0
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

user1 = User(username='******', email='*****@*****.**')
session.add(user1)
session.commit()

manuf1 = Manufacturer(manufacturer="Toyota")
session.add(manuf1)
session.commit()

car1 = Car(
    user_id=user1.id,
    name="Fortuner",
    description=
    "The Toyota Fortuner, also known as the Toyota SW4,is a mid-size SUV manufactured by Toyota.",
    manufacturer=manuf1.manufacturer)
session.add(car1)
session.commit()
car2 = Car(
    user_id=user1.id,
    name="Camry",
    description=
    '''HYBRID ELECTRIC VEHICLE EXCLUSIVE INTERIOR ORNAMENTATION, HIGH DENSITY DASH SILENCER & ACOUSTIC WINDSHIELD GLASS''',
    manufacturer=manuf1.manufacturer)
session.add(car2)
session.commit()
car3 = Car(
    user_id=user1.id,
    name="Inova",
예제 #7
0
session.commit()

# Inventory for Marin Classic Mercedes
dealership1 = Dealership(user_id=1,
                         name="Marin Classic Mercedes",
                         address="23 Industrial Way Greenbrae 94904",
                         phone="415-456-2341")

session.add(dealership1)
session.commit()

Car1 = Car(user_id=1,
           name="190",
           brand="Mercedes",
           year="1961",
           color="Maroon",
           description="UP FOR SALE IS A VERY BEAUTIFUL \
           CLASSIC 1961 MERCEDES 190D PONTON.",
           price="$8,999",
           type="Sedan",
           dealership=dealership1)

session.add(Car1)
session.commit()

# Inventory for San Francisco Classics
dealership2 = Dealership(user_id=1,
                         name="San Francisco Classics",
                         address="23 Vanness Ave, San Francisco 94132",
                         phone="415-585-2341")

session.add(dealership2)
예제 #8
0
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(
    name="Robo Barista",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User1)
session.commit()

# Menu for Ferrari
car1 = Car(user_id=1, name="Ferrari")

session.add(car1)
session.commit()

cartype1 = CarType(
    user_id=1,
    name="488 Pista",
    description=
    "Model Year: 2020,State: New ,color: gold, CC: 6500, only 1 piece available, for offer call : 01113722390",
    price="$3.350.000.00",
    car=car1)

session.add(cartype1)
session.commit()