Beispiel #1
0
    def __call__(self):

        query_products=Product.get_products(User)
        products_schema=ProductSchema(many=True)
        products=products_schema.dump(query_products)

        return jsonify({'Products': products})
Beispiel #2
0
class ProductPage:
    """Class ProductPage."""
    def __init__(self, category: str):
        """Initialise."""
        self.product_model = Product()
        self.products = self.product_model.get_products(category)

    def get_input(self) -> dict:
        """Return user's product choice."""
        user_choice = None
        while user_choice not in range(len(self.products)):
            try:
                user_choice = ProductView.display_input()
                product_choice = self.products[user_choice][user_choice]
            except ValueError:
                pass
            except IndexError:
                pass
            else:
                return product_choice
class ProductPage:
    """Class ProductPage."""
    def __init__(self, category_index: int):
        """Initialise."""
        category = Category().get_categories()[category_index]

        self.product_model = Product()
        self.products = self.product_model.get_products(category)

        self.view = ProductView(self.products)

    def get_command(self) -> dict:
        """Return user's product choice."""
        user_choice = self.view.get_input()
        choices = {
            num: f"goto_product_{num}"
            for num in range(1,
                             len(self.products) + 1)
        }
        command = choices.get(command, "")
        return command