def addItem(): item = main.get_inventory() createItemForm = CreateItemForm(request.form) if request.method == 'POST': filename = str(uuid.uuid4()) + createItemForm.item_id.data + '.jpg' cost = float(f'{createItemForm.item_cost.data :.2f}') if createItemForm.item_type.data == "W": item = Item.Wired(createItemForm.item_id.data, createItemForm.item_name.data, cost, filename) elif createItemForm.item_type.data == "WL": item = Item.Wireless(createItemForm.item_id.data, createItemForm.item_name.data, cost, filename) item.set_stock(createItemForm.item_quantity.data) main.product_management.update_item(item) print(request.files) print(request.files['file']) print(filename) file = request.files['file'] file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return redirect(url_for('adminItemDashboard')) return render_template('adminCreateItem.html', form=createItemForm)
def updateItem(id): inventory = main.get_inventory() updateItemForm = CreateItemForm(request.form) if request.method == 'POST' and updateItemForm.validate(): item = inventory.get(id) item.set_id(updateItemForm.item_id.data) item.set_name(updateItemForm.item_name.data) item.set_cost(updateItemForm.item_cost.data) item.set_stock(updateItemForm.item_quantity.data) main.product_management.modify_product(item) return redirect(url_for('adminItemDashboard')) else: item = inventory.get(id) updateItemForm.item_id.data = item.get_id() updateItemForm.item_name.data = item.get_name() updateItemForm.item_quantity.data = item.get_stock() updateItemForm.item_cost.data = item.get_cost() updateItemForm.item_type.data = item.get_type() return render_template('adminUpdateItem.html', form=updateItemForm)
def home(): itemDict = main.get_inventory().values() ItemList = [] for i in itemDict: ItemList.append(i) print(ItemList) return render_template('home.html', ItemList=ItemList)
def removeItem(id): inventory = main.get_inventory() removedItem = inventory[id] try: os.remove(f'files/{removedItem.get_file()}') except: print('error. file not found') main.product_management.delete_item(removedItem.get_id()) return redirect(url_for('adminItemDashboard'))
def adminItemDashboard(): inventory = main.get_inventory().values() search_function = SearchForm(request.form) key = "" if request.method == 'POST': key = search_function.search.data print(f'key is {key}') return render_template('adminItemDashboard.html', ItemList=inventory, input=search_function, key_search=key, alarm_stock=10)
def productDisplay(): inventory = main.get_inventory().values() username = "" if "username" in session: username = session["username"] if request.method == 'POST': product_info = request.form["item_button"].split( ",") # List 0 = ID, 1 = Name, 2 = Price product = Product.Product(product_info[0], product_info[1], float(product_info[2])) main.cart_management.add_to_cart(username, product) # # Get User cart -JH # username = "" # if 'username' in session: # username = session['username'] # u_cart = main.db.return_object("Cart") # try: # u_cart = u_cart[username] # product_list = u_cart # except: # product_list = [] # # # Add product to cart -JH # # Also check if item already is in cart, if it is, +1 quantity -JH # item_exist = False # if request.method == 'POST': # product_info = request.form["item_button"].split(",") # List 0 = ID, 1 = Name, 2 = Price # for i in range(len(product_list)): # if product_info[1] == product_list[i].get_name(): # product_list[i].add_quantity() # main.db.update_cart("Cart", username, product_list) # item_exist = True # break # if not item_exist: # product = Product.Product(product_info[0], product_info[1], float(product_info[2])) # product_list.append(product) # main.db.update_cart("Cart", username, product_list) return render_template('productDisplay.html', ItemList=inventory)
def addItemExcel(): inventory = main.get_inventory() if request.method == 'POST': file = request.files['file'] data = pd.read_excel(file) # read the file for i in range(len(data.index.values)): id = data['ID'][i] name = data['Name'][i] cost = data['Cost'][i] stock = data['Stock'][i] image = 'none' type = data['Type'][ i] # to determine the type of product for sorting purpose wired = ['w', 'wired', 'W', 'Wired'] wireless = ['wl', 'wireless', 'Wl', 'Wireless', 'WL'] if type in wired: item = Item.Wired(id, name, cost, image) elif type in wireless: item = Item.Wireless(id, name, cost, image) if item.get_id() in inventory: print('existing item. updating stock.') existing_item = inventory[item.get_id()] new_stock = existing_item.get_stock() + stock print(new_stock) existing_item.set_stock(new_stock) print(existing_item.get_stock()) main.product_management.modify_product(existing_item) else: item.set_stock(stock) main.product_management.update_item(item) return redirect(url_for('adminItemDashboard')) return redirect(url_for('addItem'))
def admin(): return render_template('admin.html', ItemList=main.get_inventory().values(), alarm_stock=10)