def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) product = super().get_object() serialized_product = serializers.ProductSerializer(instance=product) context['vue_product'] = serialized_product.data return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) product = super().get_object() context['post_to_view'] = reverse('dashboard:products:update', args=[product.id]) # If we clicked update from the search page, # this method allows to return that same # search page as opposed to all the products context['return_to_search'] = self.request.session.get( 'next_for_update') or None # This section allows the user # to navigate from product to # product in the updae page # <- and -> arrows queryset = super().get_queryset() queryset_list = list(queryset.values_list('id', flat=True)) queryset_list_length = len(queryset_list) current_product_index = queryset_list.index(product.id) next_product_index = current_product_index + 1 if next_product_index == queryset_list_length: next_product_index = 0 context['disable_next'] = True context['previous_product'] = reverse( 'dashboard:products:update', args=[queryset_list[current_product_index - 1]]) context['next_product'] = reverse( 'dashboard:products:update', args=[queryset_list[next_product_index]]) serialized_product = serializers.ProductSerializer(instance=product) context['vue_product'] = serialized_product.data images = models.Image.objects.all() context['images'] = images = images.exclude( id__in=product.images.values_list('id')) serialized_other_images = serializers.ImageSerializer(images, many=True) context['vue_other_images'] = serialized_other_images.data # This triggers the apparation or # not of certain features on the update # and creation page. For instance, unlinking # an image on the creation is not necessary context['vue_edit_mode'] = 'update' context['vue_unlink_image_url'] = reverse('dashboard:products:unlink', args=[product.id]) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) product = super().get_object() serialized_product = serializers.ProductSerializer(instance=product) context['vue_product'] = serialized_product.data suggested_products = self.model.objects.prefetch_related('images') \ .filter(active=True).exclude(id=product.id)[:3] context['more'] = suggested_products context['impressions'] = create_products_impressions( suggested_products) images = product.images.all() serialized_images = serializers.ImageSerializer(instance=images, many=True) context['serialized_images'] = serialized_images.data return context
def get_context_data(self, **kwargs): products = self.get_queryset(**kwargs) context = super().get_context_data(**kwargs) klass = super().get_paginator(self.get_queryset(**kwargs), self.paginate_by) serialized_products = serializers.ProductSerializer( instance=klass.object_list, many=True) context['vue_products'] = serialized_products.data # TODO collections = ['tops', 'pantalons'] random_collection = random.choice(collections) collection = models.Collection.objects.get(view_name=random_collection) proposed_products = collection.product_set.all()[:4] context['proposed_products'] = proposed_products return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) product = super().get_object() serialized_product = serializers.ProductSerializer(instance=product) context['vue_product'] = serialized_product.data suggested_products = self.model.objects\ .prefetch_related('images') \ .filter(active=True).exclude(id=product.id)[:3] context['more'] = suggested_products context['has_liked'] = False if self.request.user.is_authenticated: likes = models.Like.objects.filter(product=product, user=self.request.user) if likes.exists(): context.update({'has_liked': True}) reviews = product.review_set.all() context['reviews'] = reviews context['reviews_avg'] = reviews.aggregate(Avg('rating')) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) products = self.get_queryset(**kwargs) # Set a specific pagination number to # active depending on which page we are current_active_page = self.request.GET.get('page') if not current_active_page: current_active_page = 1 context['current_active_page'] = current_active_page klass = super().get_paginator(products, self.paginate_by) serialized_products = serializers.ProductSerializer( instance=klass.object_list, many=True) context['vue_products'] = serialized_products.data collection = self.model.objects.get( view_name__exact=self.kwargs['collection'], gender=self.kwargs['gender']) context['collection'] = collection context['impressions'] = create_products_impressions(products) return context