예제 #1
0
def hello_world():
    product = Product(name="product_1")
    category = Category(name="category_1", description='description')
    product.categories = [category]

    session.add(product)
    session.commit()

    return 'Hello, World!'
예제 #2
0
 def update(cls, _id: int, new_name: str, new_price: int, new_category: str,
            new_off: float) -> (bool, str):
     if new_category:
         if not Category().exist(new_category):
             return False, f"category [{new_category}] not found please first add new category"
     if _id:
         for product in cls.__db:
             if product.get("id") == int(_id):
                 if new_name:
                     product["name"] = new_name
                 if new_price:
                     product["price"] = int(new_price)
                 if new_category:
                     ca = Category.get_one_category(new_category)
                     product["category_id"] = ca.get("id")
                 if new_off:
                     product["off"] = float(new_off)
                 return True, ""
         return False, f"id: {_id} not found"
예제 #3
0
def create_db():
    db.drop_all()
    db.create_all()
    source = Source('wikidich', 'https://wikidich.com/')
    category = Category('Tiên hiệp')
    author = Author('Ngô Thiên')
    book = Book('Ngã Thị Phong Thiên')
    chapter = Chapter(1, 'lời giới thiệu', 'this is content')
    # append relation
    book.chapters.append(chapter)
    book.categories.append(category)
    book.authors.append(author)
    source.books.append(book)

    db.session.add_all([book, chapter, category, author, source])
    db.session.commit()
예제 #4
0
 def save(cls,
          name: str = None,
          price: int = None,
          category: str = None,
          off: float = None) -> bool:
     new_category = Category.get_one_category(category)
     if new_category:
         g = {
             "id": next(Product.__id),
             "name": name,
             "price": int(price),
             "category_id": new_category.get("id"),
             "off": float(off)
         }
         cls.__db.append(g)
         return True
     else:
         return False
예제 #5
0
def createCategory():
    message = {
        "success": False,
    }
    if request.method == 'POST':

        form_data = json.loads(request.form.get('form'))
        # update or create new

        new_category = Category(
            name=form_data["name"],
            showname=form_data["showname"],
            user_id=current_user.id,
        )
        # add category id and restaurant id
        db.session.add(new_category)

        db.session.commit()
        message['success'] = True
        message['category'] = new_category.id

    return jsonify(message)
예제 #6
0
 def add_category(cls):
     name = input("name: ")
     if Category.save(name):
         print(f"Successfully add category: {name}")
     else:
         print(f"This category exists with {name}")
예제 #7
0
 def __init__(self, data, recipe):
     self.name = data.get("product_name")
     self.price_excluding_tax = data.get("price_excluding_tax")
     self.vat = Vat(data)
     self.category = Category(data)
     self.data = data
예제 #8
0
 def test_name_none(self):
     with pytest.raises(TypeError):
         c = Category(None, 'Bebida')
예제 #9
0
 def test_description_len(self):
     with pytest.raises(ValueError):
         c = Category('Bebida', 'Nacional' * 255)      
예제 #10
0
 def test_description_type(self):
     with pytest.raises(TypeError):
         c = Category('Bebida', 10.6)       
예제 #11
0
 def test_name_type(self):
     with pytest.raises(TypeError):
         c = Category(100, 'Nacional')                   
예제 #12
0
 def test_name_len(self):
     with pytest.raises(ValueError):
         c = Category('Bebida' * 100, 'Nacional')