Esempio n. 1
0
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))
Esempio n. 2
0
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))
Esempio n. 3
0
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))
Esempio n. 4
0
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
Esempio n. 5
0
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))
Esempio n. 6
0
    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='密码不一致')
Esempio n. 7
0
def add_user():
    user = User(username='******', password='******')
    session.add(user)
    session.commit()
    print('添加用户成功!')
Esempio n. 8
0
def update_user():
    user = session.query(User).filter(User.username == 'admin').update(
        {User.username: '******'})
    # user.password='******'
    session.commit()
    print('更新成功!')
Esempio n. 9
0
def delete_user():
    user = session.query(User).filter(User.username == 'admin123')[0]
    session.delete(user)
    session.commit()
    print('删除用户成功!')
Esempio n. 10
0
 def update_state(self, key, value):
     log = Log(costumer="Create New Costumer, {}".format(datetime.now()))
     session.add(log)
     session.commit()
     return value
Esempio n. 11
0
 def update_state(self, key, value):
     log = Log(food="Create New Food, {}".format(datetime.now()))
     session.add(log)
     session.commit()
     return value