def marshallingDataToObject(self, data_products=None, onlyPredict=False, isMongoDB=False): object_products = [] for x in data_products: product = Product() if (isMongoDB == False): if (onlyPredict == False): product.title = x[0] product.author = x[1] product.description = x[2] product.price = x[3] product.link = x[4] else: product.predict = x[4] else: product.title = x['title'] product.author = x['author'] product.description = x['description'] product.price = x['price'] product.link = x['link'] object_products.append(product) return object_products
def addNewProduct(): form = AddNewProductForm() if request.method == "POST" and form.validate(): # Add the new product. newProduct = Product(form.name.data, float(form.price.data), int(form.stock.data)) newProduct.category = form.category.data newProduct.description = form.description.data db.session.add(newProduct) db.session.commit() # We should, also, add the product specifications. # Specifications are sent as a json string. We do this because it # is really hard to generate dynamic for fields on the client with wtforms. # The solution is to have a single string field generated with wtforms and # to simulate the rest of the string fields on the client, when the client # will submit the form, the values of that fields will be collected and saved # in that master field. We use a javascript object on the client to track # the fields an their values, so at the submission the master field will # contain the json representation of that object. specifications = json.loads(form.specifications.data) for spec_name, spec_value in specifications.iteritems(): db.session.add(ProductSpecifications(newProduct.id, spec_name, spec_value)) db.session.commit() # Now add the images. pictures = json.loads(form.pictures.data) for pictureLink in pictures: db.session.add(ProductPictures(pictureLink, newProduct.id)) db.session.commit() # Now that the product has an id we can add the rest of the components. # First, if the product's category is not already in the database we should add it. category = Categories.query.filter_by(name=newProduct.category).first() if category is None: newCategory = Categories(newProduct.category) db.session.add(newCategory) db.session.commit() else: # The product category may exist, but is unavailable, because there # are no products available left in it. We should make it available. if not category.available: category.available = True db.session.add(category) db.session.commit() return redirect(url_for('productAddedSuccessfully', name=newProduct.name)) flashErrors(form.errors, flash) return render_template('add_new_product.html', form=form)
def get_product(product_id, lang='ru'): conn = sqlite3.connect(PRODUCTS_DATABASE_PATH) cur = conn.cursor() cur.execute("SELECT * FROM product WHERE id = ?", (product_id, )) product_sql_tpl = cur.fetchone() cproduct = Product() cproduct.id = product_id cproduct.name = get_name(product_id, lang) cproduct.description = get_description(product_id, lang) cproduct.dimension = get_dimension(product_sql_tpl[1], lang) cproduct.default_amount = product_sql_tpl[2] cproduct.image_filename = product_sql_tpl[3] cproduct.price = product_sql_tpl[4] conn.close() return cproduct
def add_product(): product = Product() product.id = randint(0, 999999) product.name = request.form['name'] product.description = request.form['description'] if request.form['available'] == 'on': product.available = 1 else: product.available = 0 product.price = request.form['price'] product.amount = request.form['amount'] product.category_id = request.form['category_id'] ProductSerializer().add_product(product) return render_template("admin.html")
def send(self): while 1: msg_input = input("$:") if msg_input == "exit": pu.broadcastJS(self.udp_socket, { "type": "exit", "data": self.myid }, self.peers) break if msg_input == "friends": print(self.peers) continue if msg_input == 'product': #TODO print('print product infomation here') newProduct = Product() newProduct.name = input('Your product name: ') newProduct.description = input( 'Please descript your product status:') newProduct.price = input('what is the price of the product:') newProduct.owner = self.myid newProduct.printInfo() smsg = newProduct.jsonFile() smsg.update({'type': 'newProduct'}) print(smsg) pu.broadcastJS(self.udp_socket, smsg, self.peers) continue if msg_input == 'products info': for p_lst in self.product_lst: print(p_lst) for p in p_lst: p.printInfo() continue l = msg_input.split() if l[-1] in self.peers.keys(): toA = self.peers[l[-1]] s = ' '.join(l[:-1]) pu.sendJS(self.udp_socket, toA, {"type": "input", "data": s}) else: pu.broadcastJS(self.udp_socket, { "type": "input", "data": msg_input }, self.peers) continue
import sys sys.path.insert(0, "model") from item import Item from product import Product if __name__ == "__main__": # Inserting products products = {} n = int(input()) for _ in range(n): product = Product() product.name = input() product.description = input() product.value = input() products[product.name] = product for product in products.values(): if not product.is_valid(): exit(1) # Inserting items items = {} n = int(input()) for _ in range(n): product_name = input() amount = input() if product_name in products.keys():
category.parent = "" category.name = "zapatos" print "save : {}".format(category.Save()) print "list : {}".format(category.GetAllCategories()) print "\n\n" #################################### ########### product.py ############# #################################### product = Product() product.name = "nuevo producto" product.description = "a product description" product.sku = "123" product.brand = "a brand" product.color = "red" product.size = "10" product.image = "an image" product.manufacturer = "giani" product.category = "zapatos" product.brand = "giani" print "product.py" print "print : {}".format(product.Print()) print "save: {}".format(product.Save()) print "print : {}".format(product.Print()) print "init : {}".format(product.InitBySku("123")) print "list : {}".format(product.GetList(0, 10))
def send(self): while 1: msg_input = input("$:") msg_input = msg_input.strip() if msg_input == "exit": pu.broadcastJS(self.udp_socket, { "type":"exit", "data":self.myid },self.peers) self.save() break if msg_input == "friends": print(self.peers) continue if msg_input == 'product': # implement create Product later #newProduct = self.createProduct() newProduct = Product() newProduct.name = input('Your product name: ') newProduct.description = input('Please descript your product status:') newProduct.price = input('what is the price of the product:') newProduct.owner = self.myid newProduct.uid = self.getUID() newProduct.printInfo() smsg = newProduct.jsonFile() smsg.update({'type': 'newProduct', 'sync': False}) print('Product added') pu.broadcastJS(self.udp_socket, smsg, self.peers) continue if msg_input == 'save': self.save() continue if msg_input == 'products info': # print format here, todo later self.printProductInfo() continue if msg_input == 'update': p, attr, value = self.update() if p != None: #print('debug: send a update command to peers') pu.broadcastJS(self.udp_socket, { "type": "update", "Name": p.name, "UID": p.uid, "Attribute": attr, "Value": value}, self.peers) else: pass #print('debug: update canceled, nothing happend') #end if continue if msg_input == 'remove': p = self.remove() if p != None: #print('debug: send a remove command to peers') pu.broadcastJS(self.udp_socket, { "type": "remove", "Name": p.name, "UID": p.uid}, self.peers) else: pass #print('debug: Remove canceled, nothing happened') continue if msg_input == 'search': self.search() continue if msg_input == 'guide': self.printGuide() continue l = msg_input.split() if l[-1] in self.peers.keys(): toA = self.peers[l[-1]] s = ' '.join(l[:-1]) pu.sendJS(self.udp_socket, toA,{ "type":"input", "data":s }) else : pu.broadcastJS(self.udp_socket, { "type":"input", "data":msg_input },self.peers) continue #end while if self.myid == 'helper': dist = self.udp_socket.getsockname() pu.sendJS(self.udp_socket, dist, {'type': 'exit', 'data': self.myid})
def send(self): while 1: msg_input = input("$:") msg_input = msg_input.strip() if msg_input == "exit": if self.myid != 'helper': self.save() pu.broadcastJS(self.udp_socket, { "type": "exit", "data": self.myid }, self.peers) break if msg_input == "friends": print(self.peers) continue if msg_input == 'product': # implement create Product later #newProduct = self.createProduct() newProduct = Product() newProduct.name = input('Your product name: ') newProduct.description = input( 'Please descript your product status: ') newProduct.price = float( input('what is the price of the product: ')) newProduct.phone = input( 'what is your phone number(enter None to skip this question): ' ) newProduct.email = input('what is your email address: ') newProduct.owner = self.myid newProduct.uid = self.getUID() newProduct.printInfo() smsg = newProduct.jsonFile() smsg.update({ 'type': 'newProduct', 'sync': False, 'data': self.myid }) # add to list if newProduct.name in self.product_lst: self.product_lst[newProduct.name].append(newProduct) else: self.product_lst[newProduct.name] = [newProduct] print('Product added') pu.broadcastJS(self.udp_socket, smsg, self.peers) self.version += 1 continue if msg_input == 'save': self.save() continue if msg_input == 'products info': # print format here, todo later self.printProductInfo() continue if msg_input == 'update': p, attr, value = self.update() if p != None: print('Update successfully') pu.broadcastJS( self.udp_socket, { "type": "update", "data": self.myid, "Name": p.name, "UID": p.uid, "Attribute": attr, "Value": value }, self.peers) if attr == 'name': p_lst = self.product_lst[p.name] p_lst.remove(p) if value in self.product_lst: self.product_lst[value].append(p) else: self.product_lst[value] = [p] #end if #end if p.setAttr(attr, value) self.version += 1 else: pass #print('debug: update canceled, nothing happend') #end if continue if msg_input == 'remove': p = self.remove() if p != None: #print('debug: send a remove command to peers') pu.broadcastJS( self.udp_socket, { "type": "remove", "data": self.myid, "Name": p.name, "UID": p.uid }, self.peers) else: pass #print('debug: Remove canceled, nothing happened') self.version += 1 continue #end remove command if msg_input == 'search': self.search() continue if msg_input == 'guide': self.printGuide() continue l = msg_input.split() if l[-1] in self.peers.keys(): toA = self.peers[l[-1]] s = ' '.join(l[:-1]) pu.sendJS(self.udp_socket, toA, {"type": "input", "data": s}) else: pu.broadcastJS(self.udp_socket, { "type": "input", "data": msg_input }, self.peers) continue #end while pu.sendJS(self.udp_socket, self.seed, { 'type': 'exit', 'data': self.myid })