def shopping_cart(): if 'username' not in session: return redirect(url_for('login')) print(session['username']) print(database.get_cart(session['username'])) return render_template('shopping_cart.html', shopping_cart=database.get_cart( session['username']))
def _insert_cart(self, cart_type, minute, max_delta): """Insert a cart into the current hour according to a config entry. This function inserts a cart as close as possible to the target start time, even if the target window is not met. :param cart_type :param minute :param max_delta """ target = datetime.datetime.now().replace(minute=minute, second=0, microsecond=0) target_delta = datetime.timedelta(seconds=max_delta) # don't insert if the target minute has already passed this hour if target < datetime.datetime.now(): return # don't insert if the queue has not reached the target window last = self._queue[len(self._queue) - 1] last_length = datetime.timedelta(milliseconds=last.get_meter_data()[1]) if last.start_time + last_length < target - target_delta: return # don't insert if there are no carts of this type cart = database.get_cart(cart_type) if cart is None: print time.asctime() + " :=: CartQueue :: Could not find cart of type " + cart_type return print time.asctime() + " :=: CartQueue :: Target insert time is " + (str)(target) # find the position in queue with the closest start time to target min_index = -1 min_delta = None for i in range(1, len(self._queue)): delta = abs(target - self._queue[i].start_time) if min_delta is None or delta < min_delta: min_index = i min_delta = delta elif delta > min_delta: break print time.asctime() + " :=: CartQueue :: min_index is " + (str)(min_index) print time.asctime() + " :=: CartQueue :: min_delta is " + (str)(min_delta) if min_delta.seconds <= max_delta: print time.asctime() + " :=: CartQueue :: Cart inserted within target window" else: print time.asctime() + " :=: CartQueue :: Cart not inserted within target window" # insert cart into the queue self._queue.insert(min_index, cart) self._gen_start_times(min_index)
def open_cart(self): db = sqlite3.connect('database.db') result = database.get_cart(self.user_id, db) self.tableView.setRowCount(0) for row_number, row_data in enumerate(result): self.tableView.insertRow(row_number) for column_number, data in enumerate(row_data): self.tableView.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data))) self.stackedWidget.setCurrentIndex(1)
def _insert_cart(self, cart_type, minute, max_delta): """Insert carts into the current hour according to a config entry. This function inserts carts as close as possible to the target start time, even if the target window is not met. :param cart_type :param minute :param max_delta """ target = datetime.datetime.now().replace(minute=minute, second=0, microsecond=0) target_delta = datetime.timedelta(seconds=max_delta) # don't insert if the target minute has already passed this hour if target < datetime.datetime.now(): return # don't insert if the queue has not reached the target window last = self._queue[len(self._queue) - 1] last_length = datetime.timedelta(milliseconds=last.get_meter_data()[1]) if last.start_time + last_length < target - target_delta: return print time.asctime() + " :=: CartQueue :: Target insert time is " + (str)(target) # find the position in queue with the closest start time to target min_index = -1 min_delta = None for i in range(1, len(self._queue)): delta = abs(target - self._queue[i].start_time) if min_delta is None or delta < min_delta: min_index = i min_delta = delta elif delta > min_delta: break print time.asctime() + " :=: CartQueue :: min_index is " + (str)(min_index) print time.asctime() + " :=: CartQueue :: min_delta is " + (str)(min_delta) if min_delta.seconds <= max_delta: print time.asctime() + " :=: CartQueue :: Carts inserted within target window" else: print time.asctime() + " :=: CartQueue :: Carts not inserted within target window" # insert cart into the queue cart = database.get_cart(cart_type) self._queue.insert(min_index, cart) self._gen_start_times(min_index)
def buy_3(self): db = sqlite3.connect('database.db') name = "Kosmos Astro Telescope" price = 100 database.insert_cart(name, price, self.user_id, db) result = database.get_cart(self.user_id, db) self.tableView.setRowCount(0) for row_number, row_data in enumerate(result): self.tableView.insertRow(row_number) for column_number, data in enumerate(row_data): self.tableView.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data))) self.stackedWidget.setCurrentIndex(1)
#!/usr/bin/env python """Test suite for the database module.""" import sys sys.path.insert(0, 'app') import database print database.get_new_show_id(-1) print database.get_cart("PSA") print database.get_cart("Underwriting") print database.get_cart("StationID") print database.get_cart("Promotion") print database.get_playlist(25608) print database.get_carts() print database.search_library("mings") # print database.log_cart()
def sync_cart(self): self.clear_cart() layout = self.table.products_layout for i in database.get_cart(): self.update_total_price(i._selling_price * i._count) layout.insertWidget(layout.count() - 1, ProductTableItemWidget(i))