예제 #1
0
    def get(self, request, filter = ''):
        self.all_categories = Category.update_sub_category_lists()
        self.categories = Category.find_main_categories(self.all_categories)



        # here we use the filter to load the products accordingly!
        if filter != '':
            self.category_from_filter = list(Category.objects.filter(name = filter))
            self.list_of_all_categories_from_filter = Category.get_all_sub_categories(self.category_from_filter[0])
            self.list_of_all_categories_from_filter.append(self.category_from_filter[0])
            self.all_products = Product.get_products_from_list_of_categories(self.list_of_all_categories_from_filter)
        else:
            self.all_products = Product.get_all_products()



        #now we find all the images we need for each product
        self.all_product_images = []
        for product in self.all_products:
            img = list(ProductImage.find_all_product_images(product.id))
            self.all_product_images += img


        # this should be to load the homepage, so give featured products and catalog data
        return render(request, 'products/home.html', {'main_categories':self.categories, 'all_categories':self.all_categories, 'products':self.all_products, 'product_images':self.all_product_images })
예제 #2
0
    def get(self, request, filter=''):
        self.all_categories = Category.update_sub_category_lists()
        self.categories = Category.find_main_categories(self.all_categories)

        # here we use the filter to load the products accordingly!
        if filter != '':
            self.category_from_filter = Category.objects.get(name=filter)
            self.list_of_all_categories_from_filter = Category.get_all_sub_categories(
                self.category_from_filter)
            self.list_of_all_categories_from_filter.append(
                self.category_from_filter)
            self.all_products = Product.get_products_from_list_of_categories(
                self.list_of_all_categories_from_filter)
        else:
            self.all_products = Product.get_all_products()

        # update the descripton of the product
        for product in self.all_products:
            if len(product.description) > 80:
                product.description = product.description[:80] + '...'

        #now we find all the images we need for each product
        self.all_product_images = []
        for product in self.all_products:
            img = list(ProductImage.find_all_product_images(product.id))
            self.all_product_images += img

        # here we zip the product data with another list that has values to help the template determine when it should start a new card-deck as apposed to card
        card_deck_update_check = []
        i = 0
        for product in self.all_products:
            if i == 0:
                card_deck_update_check.append('first')
            elif i % 3:
                card_deck_update_check.append(False)
            else:
                card_deck_update_check.append(True)
            i += 1
        products_and_carddeck_checker = zip(self.all_products,
                                            card_deck_update_check)

        if filter == '':
            self.featured_products = Product.objects.filter(featured=True)

            self.featured_product_images = []
            for featured_product in self.featured_products:
                img = list(
                    ProductImage.find_all_product_images(featured_product.id))
                self.featured_product_images += img
        # this should be to load the homepage, so give featured products and catalog data                                                                                                                                                                                              featured_products
            return render(
                request, 'products/home.html', {
                    'main_categories': self.categories,
                    'all_categories': self.all_categories,
                    'products': self.all_products,
                    'products_and_carddeck_checker':
                    products_and_carddeck_checker,
                    'product_images': self.all_product_images,
                    'empty_list': [],
                    'featured_products': self.featured_products,
                    'featured_product_images': self.featured_product_images
                })
        return render(
            request, 'products/home.html', {
                'main_categories': self.categories,
                'all_categories': self.all_categories,
                'products': self.all_products,
                'products_and_carddeck_checker': products_and_carddeck_checker,
                'product_images': self.all_product_images,
                'empty_list': []
            })