Exemple #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 })
Exemple #2
0
def product_search(request):
    all_categories = Category.update_sub_category_lists()
    categories = Category.find_main_categories(all_categories)

    found_products = search_for_something(request)

    all_product_images = []
    for product in found_products:
        img = list(ProductImage.find_all_product_images(product.id))
        all_product_images += img

    return render(request, 'products/home.html', {'main_categories':categories, 'all_categories':all_categories, 'products':found_products, 'product_images':all_product_images })
def product_search(request):
    all_categories = Category.update_sub_category_lists()
    categories = Category.find_main_categories(all_categories)

    # this function here uses whats in the search bar and uses that string to find all products related to it, the search results are not ordered in anyway, its random, which should be changed
    found_products = search_for_something(request)

    if found_products:
        for product in found_products:
            if len(product.description) > 80:
                product.description = product.description[:80] + '...'

    # 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
    products_and_carddeck_checker = []
    if found_products:
        card_deck_update_check = []
        i = 0
        for product in found_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(found_products,
                                            card_deck_update_check)

    all_product_images = []
    if found_products:
        for product in found_products:
            img = list(ProductImage.find_all_product_images(product.id))
            all_product_images += img

    search_string = request.GET['search_string']
    return render(
        request, 'products/home.html', {
            'main_categories': categories,
            'all_categories': all_categories,
            'products': found_products,
            'products_and_carddeck_checker': products_and_carddeck_checker,
            'product_images': all_product_images,
            'empty_list': [],
            'search_string': search_string
        })
Exemple #4
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': []
            })