def groceryApp(): groceries = [] groceries_to_json = [] app_running = True first_run = True while app_running: if first_run: choice = first_menu() if choice == "q": return else: choice = 1 first_run = False if choice == 0: choice = main_menu() if choice == 1: store, location = prompt_store_and_location() shoppingList = ShoppingList(store, location) adding_items_in_list = True choice = 0 if choice == 2: index = prompt_edit_list(groceries) edit_list(index, groceries) adding_items_in_list = True if choice == 3: printStoreLists(groceries) choice = 0 while adding_items_in_list: print("#############################") add_item_list(shoppingList) print("#############################") keep_adding = add_items_continue(shoppingList) if not keep_adding: adding_items_in_list = False groceries.append(shoppingList) groceries_to_json.append({ f"{shoppingList.store}, {shoppingList.storeLoc}": shoppingList.items_to_json }) printStoreLists(groceries) user_input = app_continue() keep_running = True if user_input == "e": index = prompt_edit_list(groceries) edit_list(index, groceries) choice = 2 if user_input == "q": keep_running = False if not keep_running: app_running = False add_json_to_file("groceryList", groceries_to_json)
def generateFromProducts(self, products, realSum = 0): shopping_list = ShoppingList() shopping_list.realSum = realSum groupFactory = OwnerGroupFactory() infoFactory = OwnerInfoFactory() infoList = [infoFactory.create(person, 1/len(self.persons)) for person in self.persons] defaultGroup = groupFactory.create(infoList) for (name, price) in products: product = Product(name, price, defaultGroup) shopping_list.addProduct(product) return shopping_list
def create_shopping_list(title, address): shopping_list = ShoppingList(title, address) return shopping_list
#grocery items def view_list_items(lst): print(f"Shopping List: {lst.title}") print("Item: - Quantity: - Price:") shopping_list = lst.contents for item in shopping_list: print(f"{item.title} - {item.quantity} - {item.price}") def intake_grocery_item(): grocery_list_title = input("Enter an item to add to your list: ") grocery_list_quantity = input("Enter the quantity of this item you need to buy: ") grocery_list_price = input("Enter the price of the item you need to buy or press \"Enter\" to continue: ") return (grocery_list_title, grocery_list_quantity, grocery_list_price) def create_grocery_item(title, quantity, price): grocery_item = GroceryItem(title, quantity, price) return grocery_item def new_grocery_item(): (item_title, item_quantity, item_price) = intake_grocery_item() grocery_item = create_grocery_item(item_title, item_quantity, item_price) selected_list.contents.append(grocery_item) #execute shopping_lists = [] selected_list = ShoppingList("","") main_menu()
def setUp(self): # ran before each test self.shoppingList = ShoppingList("Kroger", "Spring Branch") self.groceryItem = GroceryItem("milk", (1.99))
def __init__(self, **kwargs): super().__init__(**kwargs) self.entry_widgets = [] self.shoppingList = ShoppingList() self.expectedSum = 0
class ProductListWidget(FloatLayout, Observer): layout = ObjectProperty(None) def __init__(self, **kwargs): super().__init__(**kwargs) self.entry_widgets = [] self.shoppingList = ShoppingList() self.expectedSum = 0 def update(self, instance, value): self.notify(instance, value) def addShoppingList(self, shoppingList): self.shoppingList.merge(shoppingList) for product in shoppingList.getProducts(): self.__addProductWidget(product) self.expectedSum += shoppingList.realSum def addProduct(self, product): self.shoppingList.addProduct(product) self.__addProductWidget(product) self.notify(self, product) def __addProductWidget(self, product): new_entry = ProductEntryWidget() new_entry.setProduct(product) new_entry.setOwners(product.getOwners()) new_entry.attachObserver(self) self.entry_widgets.append(new_entry) self.layout.add_widget(new_entry) def removeProduct(self, product): for widget in self.entry_widgets: if widget.getProduct() == product: self.layout.remove_widget(widget) self.entry_widgets.remove(widget) self.shoppingList.removeProduct(product) self.notify(self, None) def clear(self): self.shoppingList.clear() self.expectedSum = 0 for widget in self.entry_widgets: self.layout.remove_widget(widget) self.entry_widgets = [] OwnerGroupFactory().clear() OwnerInfoFactory().clear() def getTotalSum(self): return self.shoppingList.getTotalSum() def getRealSum(self): return self.expectedSum def getBill(self): bill = self.shoppingList.generateBill() compactBill = {} for person in bill: if not person.name in compactBill: compactBill[person.name] = bill[person] else: compactBill[person.name] += bill[person] return compactBill
from flask import Flask, request, redirect, url_for, render_template import config from Users import User from ShoppingList import ShoppingList app = Flask(__name__) app.config.from_object(config) new_user = User() new_list = ShoppingList() @app.route('/') def index(): return 'hello' @app.route('/add_user', methods=['GET', 'POST']) def add_user(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] content = new_user.add_user(username, password) print(content) return render_template('adduser.html', data=None) @app.route('/deleteuser/<id>', methods=['GET'])