def restaurant_add_update_product(): user = get_user() if (user): restaurant = Restaurant.get_from_id(user.restaurant_id) if (restaurant): name = get_header("name") description = get_header("description") price = get_header_float("price") id = get_header_int("id") if (is_int(id)): product = Product.get_from_id(id) if (product): if (get_header("remove")): product.remove() else: if (name and description and is_float(price) and len(name) <= 50 and len(description) <= 100): product.name = name product.description = description product.price = price get_session().commit() else: abort(400) return "true" else: abort(404) else: categoryId = get_header_int("category") if (is_int(categoryId) and len(name) <= 50 and len(description) <= 100): category = Category.get_from_id(restaurant, categoryId) if (category): Product.add(name, description, price, restaurant, category) return "true" else: abort(404) else: abort(400) else: abort(404) else: abort(404)
def addProductType(): # form : product_id, bar_code form = request.form.to_dict() print('form', form) # 上传图片 file = request.files['file'] if file is not None: # 储存图片获取数据 data = Img.save_one(file, form) print('upload data', data) if data['src'] is not None and base_url not in data['src']: data['src'] = base_url + '/' + data['src'] form['cover'] = data['src'] if data is not None: r = Res.success(data) else: r = Res.fail({}, msg='图片已存在') print('新图片', form) product = Product.add(form) if type(product) is str: r = Res.fail(msg=product) else: all = Product.all() print('all', all) r = Res.success(all) return make_response(jsonify(r))
def doAdd(): f = request.files.get('f') f.save('static/photos/' + f.filename) a = (request.form.get('Cat'), request.form.get('name'), request.form.get('pri'), f.filename, request.form.get('des'), request.form.get('qty')) pro = Product() ret = pro.add(a) print('-----', ret) if ret > 0: return redirect('/product') return 'Failed'
def doAdd(): f = request.files.get("f") f.save("static/image/" + f.filename) name = request.form.get("name") cat = request.form.get("cat") brand = request.form.get("brand") price = request.form.get("price") des = request.form.get("des") qty = request.form.get("qty") a = (name, brand, cat, price, f.filename, qty, des) pro = Product() ret = pro.add(a) if ret > 0: return redirect("/product") return "Failed"
def first_run(): from models.client import Client from models.category import Category from models.orders import Order from models.product import Product from models.restaurants import Restaurant from models.user import User meta = sqlalchemy.MetaData(engine) meta.reflect() #meta.drop_all() print("First run, please wait while the db is being populated...") # Create tables Base.metadata.create_all(engine) testClient = Client.add("6977988551") testClient2 = Client.add("8891155521") restaurant = Restaurant.add( "Restaurant 1", "The best food you'll find in the city\nWe make sandwiches, salads and burgers" ) sandwichesCategory = Category.add("Sandwiches", restaurant) Product.add("Pulled Pork", "With tangy barbecue sauce on an onion knot", 9.50, restaurant, sandwichesCategory) Product.add( "Turkey Club", "Roasted turkey breast, bacon, lettuce, avocado and tomato on baguette", 8, restaurant, sandwichesCategory) Product.add( "Reuben", "Corned beef, melted swiss, sauerkraut and thousand island on marbled rye", 8, restaurant, sandwichesCategory) Product.add( "Shrimp Cilantro Wrap", "Shrimp, avocado, mixed greens, salsa, cilantro and may on a tomato tortilla", 8.5, restaurant, sandwichesCategory) burgerCategory = Category.add("Burgers", restaurant) Product.add( "Grass-fed Beef Burger", "With sharp cheddar, heirloom tomatoes and caramelized onions", 9.5, restaurant, burgerCategory) Product.add( "Mushroom Swiss Burger", "With sautéed mushrooms and melted swiss on a home-baked roll", 10, restaurant, burgerCategory) Product.add( "Hickory Burger", "Topped with cheddar, hickory smoked bacon and smoked barbecue sauce", 10, restaurant, burgerCategory) Product.add( "Chicken Burger", "Grilled chicken breast with heirloom tomatoes, avocado and sprouts on a home-baked roll", 9, restaurant, burgerCategory) saladCategory = Category.add("Salads", restaurant) Product.add( "Caesar Salad", "Romaine, fresh parmesan, seasoned croutons and black pepper with garlic anchovy dressing", 6.75, restaurant, saladCategory) Product.add("Red Iceberg Salad", "With sweet corn, blackberries, goat cheese and fresh basil", 9.25, restaurant, saladCategory) Product.add( "House Salad", "With green olives, green peppers, onions, cucumbers, and tomato", 6.75, restaurant, saladCategory) Product.add( "Blue Chicken Salad", "Mesclun greens, apple, grilled chicken, gorgonzola, chesse and balsamic vinagrette", 9.25, restaurant, saladCategory) # Add an user for the restaurant we just created User.add("restaurant1", "restaurant1", 0, restaurant) streets = [ "Oak Street", "Madison Avenue", "Bridle Lane", "Jefferson Street", "Lafayette Avenue", "Grove Street", "Chestnut Avenue" ] # Simulate some orders on a different client originalDate = time.time() - 57600000 for i in range(87): productCount = randint(1, 2) used = {} products = [] price = 0 originalDate += randint(376000, 576000) for y in range(productCount): id = randint(0, 11) while (id in used): id = randint(0, 11) used[id] = True amount = randint(1, 2) products.append({"id": id + 1, "count": amount}) product = Product.get_from_id(id + 1) price += amount * product.price order = Order.add( random.choice(streets) + " " + str(randint(1, 5000)), price, "", products, [-34.601874, -58.432611], testClient2, restaurant) order.date = originalDate order.status = 2 get_session().commit() Order.add("Bridle Lane 1775", 9.50, "", [{ 'id': 1, 'count': 1 }], [-34.601874, -58.432611], testClient, restaurant)
def generate_fake_date(): print('测试开始') # 增加 类型 product1 = dict( name='AIR JORDAN 11 RETRO', code='AR0715 200', cover= 'https://c.static-nike.com/a/images/t_prod_ss/w_960,c_limit,f_auto/c0k2mkpdrvz3caggsm7f/womens-air-jordan-11-neutral-olive-sail-gum-light-brown-release-date.jpg', note='橄榄 女款', ) product2 = dict( name='AIR JORDAN 1 MID', code='AR0715 200', cover='https://inews.gtimg.com/newsapp_bt/0/9964332871/1000', note='黒曜石 黑白', ) p = Product.add(product1) p2 = Product.add(product1) Product.add(product2) print('p', p.id) # 增加子类型 product1_attr1 = dict(bar_code='191888280841', size="38.5", product_id=p.id) product1_attr2 = dict(bar_code='191888280858', size="39", product_id=p.id) ProductAttr.new(product1_attr1) ProductAttr.new(product1_attr2) p3 = dict(bar_code="191888280841") p3 = ProductAttr.queryByBarCode(p3) print('p3', p3) p4 = ProductAttr.all() print('p444444444444', p4) # 增加用户 u = dict( openid="oACYX0d8qtLPAZ6Mtx0sgBY3AtGw", identity=0, ) User.login(u) tester = dict( username='******', password='******', openid='tester', identity=2, ) User.new(tester) # 增加字典表 d1 = [ { 'key': 0, 'value': '管理员', 'alias': 'admin', 'status': 0, 'type': 'USER_TYPE', 'note': '用户权限', }, { 'key': 1, 'value': '普通用户', 'alias': 'normal', 'status': 0, 'type': 'USER_TYPE', 'note': '用户权限', }, { 'key': 2, 'value': '微信测试账号', 'alias': 'tester', 'status': 0, 'type': 'USER_TYPE', 'note': '用户权限', }, { 'key': 0, 'value': '出售中', 'alias': 'sale', 'status': 0, 'type': 'STOCK_STATUS', 'note': '出售状态', }, { 'key': 1, 'value': '已出售', 'alias': 'sell', 'status': 0, 'type': 'STOCK_STATUS', 'note': '出售状态', }, { 'key': 2, 'value': '寄售', 'alias': 'consignment', 'status': 0, 'type': 'STOCK_STATUS', 'note': '出售状态', }, { 'key': 3, 'value': '退回中', 'alias': 'return', 'status': 0, 'type': 'STOCK_STATUS', 'note': '出售状态', }, { 'key': 0, 'value': '未上传', 'alias': 'unupload', 'status': 0, 'type': 'BATCH_UPLOAD', 'note': '批次表格导入状态', }, { 'key': 1, 'value': '已上传', 'alias': 'uploaded', 'status': 0, 'type': 'BATCH_UPLOAD', 'note': '批次表格导入状态', }, ] DictMap.new_by_list_dict(d1) # # 新增批次 b1 = dict(purchase_time='2019-8-26', name='测试', proportion=5) b2 = dict(purchase_time='2019-9-1', name='批次2', proportion=10) Batch.new(b1) Batch.new(b2)