def setUp(self) -> None: self.manufacture = Manufacture() self.manufacture_name = "Lol" self.manufacture.set_name(self.manufacture_name) self.product_name1 = "Product 1" self.product_sku1 = "a001" self.product_price1 = 5 self.product1 = Product( name=self.product_name1, sku=self.product_sku1, price=self.product_price1, manufacture=self.manufacture, ) self.product_name2 = "Product 2" self.product_sku2 = "a002" self.product_price2 = 10 self.product2 = Product( name=self.product_name2, sku=self.product_sku2, price=self.product_price2, manufacture=self.manufacture, )
def public_category(category=None): listProduct = [] where = "refcategory = '" + category + "' AND active = '1'" where = where + getFilterPrice() pro_result = SelectDBWhere('product', where) # return str(len(pro_result)) for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9], prd[10], prd[11])) cat_result = load_all_category() img_result = load_all_images() trm_result = load_all_trademark() bc = parseBreadCrumbCategory(cat_result, "/public/category/" + category, category) return render_template('/public/category.html', products=listProduct, category=cat_result, images=img_result, trademark=trm_result, breadcrumb=bc)
def public_trademark(trademark=None): listProduct = [] if 'filter_price' in request.form: filterprice = request.form['filter_price'] else: filterprice = None where = "reftrademark = '" + trademark + "' AND active = '1'" if filterprice != None: where = where + getFilterPrice(filterprice) pro_result = SelectDBWhere('product', where) # return str(len(pro_result)) for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9], prd[10], prd[11])) cat_result = load_all_category() img_result = load_all_images() trm_result = load_all_trademark() bc = parseBreadCrumbTrademark(trm_result, cat_result, "/public/category/" + trademark, trademark) return render_template('/public/category.html', products=listProduct, category=cat_result, images=img_result, trademark=trm_result, breadcrumb=bc)
def load_all_product(): listProduct = [] pro_result = SelectDB('product') for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9])) return listProduct
def productInput(): name = input("상품명 : ") while True: price = input("가격 : ") if not price.isdecimal(): print("숫자로 다시 입력하세요") else: price = int(price) return Product(name, price)
def load_single_product(id=None): listProduct = [] pro_result = SelectDBWhere('product', 'id = ' + id) for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9], prd[10], prd[11])) return listProduct[0]
def input_display(): print("====== 제품 등록 ======") id = input("제품 번호를 입력하세요 : ") name = input("제품 이름 입력하세요 : ") price = input("제품 가격 입력하세요 : ") while not price.isdecimal(): # while절로, 변수.isdecimal() print("제품의 가격을 숫자로 입력해주세요.") price = input("제품 가격 입력하세요 : ") description = input("제품 소개 입력하세요 : ") return Product(id, name, int(price), description) # 생성자로 객체화함.
def load_random_product(): listProduct = [] pro_result = Execute( 'SELECT * FROM `product` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `product` ) AND active = 1 ORDER BY id LIMIT 5' ) for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9], prd[10], prd[11])) return listProduct
def test_remove_product(self): # must by empty self.assertEqual(0, len(self.category.products)) product1 = Product(sku="a001", name="Product 1", price=10, manufacture=self.manufacturer) product2 = Product(sku="a002", name="Product 2", price=9, manufacture=self.manufacturer) self.category.add_product(product1) self.category.add_product(product2) self.assertEqual(2, len(self.category.products)) # remove product2 self.category.remove_product(product2) self.assertFalse(self.category.has_product(product2)) self.assertFalse(product2.has_category(self.category)) # assert that product1 is not affected self.assertTrue(self.category.has_product(product1)) self.assertTrue(product1.has_category(self.category))
def test_add_product(self): # must by empty self.assertEqual(0, len(self.category.products)) product1 = Product(sku="a001", name="Product 1", price=10, manufacture=self.manufacturer) product2 = Product(sku="a002", name="Product 2", price=9, manufacture=self.manufacturer) # add product1 self.category.add_product(product1) self.assertTrue(self.category.has_product(product1)) self.assertEqual(1, len(self.category.products)) self.assertFalse(self.category.has_product(product2)) self.assertTrue(product1.has_category(self.category)) self.assertEqual(1, len(product1.categories)) # add product2 self.category.add_product(product2) self.assertTrue(self.category.has_product(product2)) self.assertEqual(2, len(self.category.products)) self.assertTrue(product2.has_category(self.category)) self.assertEqual(1, len(product2.categories))
def create_new(self, data): product = Product(productCode=data['productCode'], productName=data['productName'], productLine=data['productLine'], productScale=data['productScale'], productVendor=data['productVendor'], productDescription=data['productDescription'], quantityInStock=data['quantityInStock'], buyPrice=data['buyPrice'], MSRP=data['MSRP']) # TODO: Error Handling self.session.add(product) return self.session.commit()
def setUp(self) -> None: self.manufacture = Manufacture() self.manufacture_name = "Lol" self.manufacture.set_name(self.manufacture_name) self.product_name = "Product 1" self.product_sku = "a001" self.product_price = 5 self.product = Product( name=self.product_name, sku=self.product_sku, price=self.product_price, manufacture=self.manufacture, )
def public_search(): listProduct = [] input = request.form['input'] query = "SELECT * FROM product WHERE name LIKE '%" + input + "%'" pro_result = Execute(query) for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9], prd[10], prd[11])) cat_result = load_all_category() img_result = load_all_images() return render_template('/public/search_result.html', products=listProduct, category=cat_result, images=img_result)
def init_data_load(): # 객체를 list에 담아서 return. products = [] fileExist = os.path.isfile("product.dat") # os.path if fileExist: read_file = open("product.dat", "r") # file open while True: # while 위치선정 당연히 data 위에죠~ data = read_file.readline() if len(data.split(" ")) > 1: product = data.split(" ") products.append( Product( product[0].strip(), product[1].strip(), product[2].strip(), product[3].strip())) # 객체의 생성자를 통해서 객체화 하여 list에 저장. if not data: break read_file.close() # file 닫기를 잊지 말기 return products
def setUp(self) -> None: self.manufacture = Manufacture() self.manufacture_name = "Lol" self.manufacture.set_name(self.manufacture_name) self.product_name1 = "Product 1" self.product_sku1 = "a001" self.product_price1 = 5 self.product1 = Product( name=self.product_name1, sku=self.product_sku1, price=self.product_price1, manufacture=self.manufacture, ) self.quantity = 10 self.item = Item(product=self.product1, quantity=self.quantity)
def public_category(category=None): listProduct = [] if (int(category) >= 10): pro_result = SelectDBWhere( 'product', "refcategory = '" + category + "' AND active = '1'") else: pro_result = SelectDBWhere( 'product', "refcategory in (SELECT id FROM category WHERE refparent = '" + category + "') AND active = '1'") for prd in pro_result: listProduct.append( Product(prd[0], prd[1], prd[2], prd[3], prd[4], prd[5], prd[6], prd[7], prd[8], prd[9])) cat_result = load_all_category() return render_template('/public/product.html', products=listProduct, category=cat_result)
def loadData(): products = [] fileExist = os.path.isfile( "C:/Users/OWNER/Desktop/cloud_msa/cloud_msa_assignment/Python/product/product_data.txt" ) if fileExist: read_file = open( "C:/Users/OWNER/Desktop/cloud_msa/cloud_msa_assignment/Python/product/product_data.txt", "r") while True: data = read_file.readline() if not data: break else: data = data.split(sep='.')[1] products.append( Product( data.split(sep=',')[0][7:], data.split(sep=',')[1][8:].strip('\n'))) read_file.close() return products