def create_buy_bill(name, price, store_id): try: bill = Bill(food_name=name, food_price=str(-int(price)), store_id=store_id, created_at=datetime.now()) session.add(bill) session.commit() except SQLAlchemyError as e: session.rollback() print("we have error in create_buy_bill, {}".format(e))
def add_food(name, price): try: new_food = Food(name=name, price=int(price), created_at=datetime.now()) session.add(new_food) session.commit() except SQLAlchemyError as e: session.rollback() print("we have error in add_food, {}".format(e))
def add_address_to_costumer_in_db(costumer, addresses_list: list): try: for address in addresses_list: costumer.addresses.append(address) session.commit() except SQLAlchemyError as e: session.rollback() print("we have error in add_address_to_costumer, {}".format(e))
def delete_food_from_db(food_name): try: session.query(Food).filter(Food.name == food_name).delete() session.commit() return True except Exception as e: session.rollback() print("we have error in delete_food, {}".format(e)) return False
def create_bill(selected_foods, costumer_id): try: selected_foods_name = "@".join([food.name for food in selected_foods]) selected_foods_prices = "@".join([str(food.price) for food in selected_foods]) bill = Bill(food_name=selected_foods_name, food_price=selected_foods_prices, created_at=datetime.now(), costumer_id=costumer_id) session.add(bill) session.commit() except SQLAlchemyError as e: session.rollback() print("we have error in create bill, {}".format(e))
def post(self): username = self.get_body_argument('username') password = self.get_body_argument('password') repassword = self.get_body_argument('repassword') if password == repassword: user = User() user.username = username user.password = password session.add(user) session.commit() # self.write('用户注册成功') self.redirect(self.reverse_url('login')) else: self.render('user/register.html', msg='密码不一致')
def add_user(): user = User(username='******', password='******') session.add(user) session.commit() print('添加用户成功!')
def update_user(): user = session.query(User).filter(User.username == 'admin').update( {User.username: '******'}) # user.password='******' session.commit() print('更新成功!')
def delete_user(): user = session.query(User).filter(User.username == 'admin123')[0] session.delete(user) session.commit() print('删除用户成功!')
def update_state(self, key, value): log = Log(costumer="Create New Costumer, {}".format(datetime.now())) session.add(log) session.commit() return value
def update_state(self, key, value): log = Log(food="Create New Food, {}".format(datetime.now())) session.add(log) session.commit() return value