Beispiel #1
0
def new_item(category_id):
    """
    Get: Show the form allowing an authenticated user to create an item
        in specified category
    Post: Allow an authenticated user to create an item in specified category
    """
    if 'username' not in login_session:
        return redirect('/login')
    category = session.query(Category).filter_by(id=category_id).one()
    categories = session.query(Category).order_by(Category.name).all()
    user = getUserInfo(login_session['user_id'])
    if request.method == 'POST':
        newItem = Item(
            name=request.form['inputItemName'],
            description=request.form['inputItemDescription'],
            price=request.form['inputItemPrice'],
            image="",
            category_id=category_id,
            user_id=user.id
        )
        session.add(newItem)
        session.commit()
        file = request.files['inputItemImage']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_extension = os.path.splitext(filename)[1]
            image_path = os.path.join(app.config['UPLOAD_FOLDER'],
                                      str(newItem.id) + file_extension)
            file.save(image_path)
            newItem.image = "/" + image_path
            session.add(newItem)
            session.commit()
        flash(u'Item added successfully', 'success')
        return redirect(url_for('category_items',
                                category_id=category_id))
    else:
        user = getUserInfo(login_session['user_id'])
        return render_template('new_item.html',
                               category=category,
                               categories=categories,
                               user=user)
cat1 = Category(name="Apparel", image="")
cat2 = Category(name="Kitchen", image="")
cat3 = Category(name="Swag", image="")
cat4 = Category(name="Office", image="")
cat5 = Category(name="Books", image="")
cat6 = Category(name="Stickers", image="")
cat7 = Category(name="Electronics", image="")
cat8 = Category(name="Umbrellas", image="")
cat = [cat1, cat2, cat3, cat4, cat5, cat6, cat7, cat8]
session.add_all(cat)
session.commit()

items = [
    Item(
        title="Gray Hooded Sweatshirt",
        description=
        "Unless you live in a nudist colony, there are moments when the chill you feel demands that you put on something warm, and for those times, there's nothing better than this sharp MongoDB hoodie. Made of 100% cotton, this machine washable, mid-weight hoodie is all you need to stay comfortable when the temperature drops. And, since being able to keep your vital stuff with you is important, the hoodie features two roomy kangaroo pockets to ensure nothing you need ever gets lost.",
        image="/img/products/hoodie.jpg",
        category=cat1),
    Item(
        title="Coffee Mug",
        description=
        "A mug is a type of cup used for drinking hot beverages, such as coffee, tea, hot chocolate or soup. Mugs usually have handles, and hold a larger amount of fluid than other types of cup. Usually a mug holds approximately 12 US fluid ounces (350 ml) of liquid; double a tea cup. A mug is a less formal style of drink container and is not usually used in formal place settings, where a teacup or coffee cup is preferred.",
        image="/img/products/mug.jpg",
        category=cat2),
    Item(
        title="Stress Ball",
        description=
        "The moment life piles more onto your already heaping plate and you start feeling hopelessly overwhelmed, take a stress ball in hand and squeeze as hard as you can. Take a deep breath and just let that tension go. Repeat as needed. It will all be OK! Having something small, portable and close at hand is a must for stress management.",
        image="/img/products/stress-ball.jpg",
        category=cat3),
    Item(
Beispiel #3
0
User1 = User(username="******", email="*****@*****.**")
session.add(User1)
session.commit()
User2 = User(username="******", email="*****@*****.**")
session.add(User2)
session.commit()
User3 = User(username="******", email="*****@*****.**")
session.add(User3)
session.commit()

# Soccer
c1 = Category(name="Soccer")
session.add(c1)
session.commit()

item1 = Item(itemName="Soccer Cleats", description="A lightweight synthetic leather upper offers them enhanced touch and feel while a Phylon heel wedge and die-cut EVA sockliner delivers the ideal combination of padding and support for match long comfort. The soccer cleat has a rubber studded outsole that provides exceptional acceleration and traction on synthetic grass surfaces.", user_id=1, category_id=1)
session.add(item1)
session.commit()

item2 = Item(itemName="Jersey", description="This Soccer Jersey will keep you dry and comfortable from practice to the game. Constructed of sweat-wicking polyester fabric, this short sleeve features contrast side panels and neckline to add a pop of color to this simple design. Show off your pride and rush the field in style wearing this Soccer Jersey.", user_id=1, category_id=1)
session.add(item2)
session.commit()

item3 = Item(itemName="Two shinguards", description="For ultimate protection where you need it most, the Soccer Shin Guards boast a durable shell with ankle discs and foam backing that provides comfortable support and relief from impact.", user_id=1, category_id=1)
session.add(item3)
session.commit()

# Items for Basketball
c2 = Category(name="Basketball")
session.add(c2)
session.commit()
Beispiel #4
0
engine = create_engine('sqlite:///catalog.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()

# create myself as a user
User1 = User(name="Cr2712", email="*****@*****.**")
session.add(User1)
session.commit()

# Cornhole category
category1 = Category(user_id=1,
                     name="Cornhole",
                     description="Corhhole is a sport I love")

session.add(category1)
session.commit()

cornhole_item1 = Item(user_id=1,
                      name="Cornhole boards",
                      description="These are cornhole boards",
                      category=category1)

session.add(cornhole_item1)
session.commit()

print "Good job...database records created."
# session.rollback()
session = DBSession()

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


#items for soccer categ
categ1 = Category(name = "soccer")

session.add(categ1)
session.commit()


item1 = Item(name = "two shingurads", description = "thatis warse for body gras", category = categ1, user_id= 1)

session.add(item1)
session.commit()

item2 = Item(name = "shingurands", description = "Juicy grilled chicken patty with tomato mayo and lettuce", category = categ1, user_id = 1)

session.add(item2)
session.commit()

item3 = Item(name = "jersy", description = "fresh baked and served with ice cream", category = categ1, user_id = 1)

session.add(item3)
session.commit()

#items for bascetball categ
session.add(c1)

c2 = Category(name="Lumber")
session.add(c2)

c3 = Category(name="Plywood")
session.add(c3)

c4 = Category(name="Decking")
session.add(c4)

session.commit()

# Add initial Items
i1 = Item(name="Raised Panel",
          description="Classic Look",
          category=c1,
          user=u1)
i2 = Item(name="Flat Panel",
          description="Traditional Look",
          category=c1,
          user=u1)

i3 = Item(name="2x4", description="Wall Framing", category=c2, user=u1)
i4 = Item(name="2x10", description="Floor Joists", category=c2, user=u1)

i5 = Item(name="4x8 Flooring",
          description="Finished One Side",
          category=c3,
          user=u1)
i6 = Item(name="4x8 Cherry",
          description="Finished Both Sides",
Beispiel #7
0
session.add(category2)
session.commit()

category3 = Category(name="Frisbee")
session.add(category3)
session.commit()

category4 = Category(name="Snowboarding")
session.add(category4)
session.commit()

category5 = Category(name="Skating")
session.add(category5)
session.commit()

menuItem1 = Item(name="Soccer Ball", description="A soccer ball, duh.",
                 category=category1, user_id=0, filename=None)
session.add(menuItem1)
session.commit()
menuItem2 = Item(name="Socks", description="Very comfy.",
                 category=category1, user_id=0, filename=None)
session.add(menuItem2)
session.commit()
menuItem3 = Item(name="Shinguards", description="Protect your shins.",
                 category=category1, user_id=0, filename=None)
session.add(menuItem3)
session.commit()
menuItem4 = Item(name="Basket Ball", description="A basket ball, duh.",
                 category=category2, user_id=0, filename=None)
session.add(menuItem4)
session.commit()
menuItem5 = Item(name="Basket",
Beispiel #8
0
category9 = Category(name="Stickers")
session.add(category9)
session.commit()

# category10 = Category(name="T-Shirts")
# session.add(category10)
# session.commit()

# category11 = Category(name="Shoes")
# session.add(category11)
# session.commit()

item1 = Item(
    name="CCS Logo Skateboard Complete - Black",
    description=
    "There’s something great in the transformation of a deck the more you skate it. Whether you draw, paint, stencil your own graphic, or let your skating create its own graphic, the CCS Logo deck only gets better with time.",
    category_id=1)
session.add(item1)
session.commit()

item2 = Item(
    name="Birdhouse Ben Raybourn Mexipulp Skateboard Complete - 8.25\"",
    description="Gotta look out for the killa trees!",
    category_id=1)
session.add(item2)
session.commit()

item3 = Item(
    name="Alien Workshop Guevara No Evil Skateboard Complete - 8.00\"",
    description="Joey gpt the pro nod!",
      "t_itemName": "test12",
      "t_itemDescription": "Ipsum aute qui anim",
      "t_userId": 1,
      "t_catId": 1
    },
    {
      "t_itemName": "test13",
      "t_itemDescription": "Ipsum aute qui anim",
      "t_userId": 1,
      "t_catId": 1
    },
    {
      "t_itemName": "test14",
      "t_itemDescription": "Qui officia ea dolor id nostrud.",
      "t_userId": 1,
      "t_catId": 1
    }
  ]
}""")

for x_item in new_items['all_items']:
    print(x_item)
    new_item = Item(t_itemName=str(x_item['t_itemName']),
                    t_itemDescription=str(x_item['t_itemDescription']),
                    t_userId=1,
                    t_catId=1)
    print(x_item)

session.add(new_item)
session.commit()
engine = create_engine('sqlite:///cafemenu.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

# Menu Items:
# 1. Coffe menu items:
category_coffee = Category(name='Coffee')

session.add(category_coffee)
session.commit()

citem1 = Item(name='Italian Coffee',
              description='Good Italian coffee',
              date=datetime.datetime.now(),
              category=category_coffee)

session.add(citem1)
session.commit()

citem2 = Item(name='Frensh Coffee',
              description='Good Frensh coffee',
              date=datetime.datetime.now(),
              category=category_coffee)

session.add(citem2)
session.commit()

citem3 = Item(name='Turkish Coffee',
              description='Good Turkish coffee',
DBSession = sessionmaker(bind=engine)
session = DBSession()

newCategory = Category(name="Category 1", description="Description Category 1")

session.add(newCategory)
session.commit()

newCategory = Category(name="Category 2", description="Description Category 2")

session.add(newCategory)
session.commit()

newItem = Item(name="Item 1",
               description="Description Item 1",
               price="10",
               image="/static/images/test.jpg",
               category_id=1)

session.add(newItem)
session.commit()

newItem = Item(name="Item 2",
               description="Description Item 2",
               price="20",
               image="/static/images/test.jpg",
               category_id=2)

session.add(newItem)
session.commit()
Beispiel #12
0
session.query(Category).delete()
session.query(User).delete()
# Create dummy user
User1 = User(name="ZGH", email="*****@*****.**")
session.add(User1)
session.commit()

# Create a cagetory
###############
cate1 = Category(user_id=User1.id, name="NHL", description="National Hockey Leagure",)

session.add(cate1)
session.commit()


item1 = Item(user_id=User1.id, name="Boston Bruins", description="Atlantic",
                     category=cate1)
session.add(item1)
session.commit()

item2 = Item(user_id=User1.id, name="Anaheim Ducks", description="Pacific",
                     category=cate1)
session.add(item2)
session.commit()

item3 = Item(user_id=User1.id, name="Chicago Blackhawks", description="Central",
                     category=cate1)
session.add(item3)
session.commit()


###############