Beispiel #1
0
    def get(self, request, *args, **kwargs):
        print('i work two')
        print('.;', request.session['search_query'])
        if request.user.is_authenticated():
            try:
                self.customer = request.user.customer_set.first()
                self.opt_user = request.user.customer_set.first().opt
            except Exception as err:
                print(err)
        else:
            return redirect('login')

        if self.customer.baskets.all().exists():
            for basket in self.customer.baskets.all():
                if not basket.paid_for:
                    self.cart = basket
                    request.session['cart_id'] = basket.id
                    request.session['goods_card'] = dict()
        else:
            cart = Cart()
            cart.save()
            cart_id = cart.id
            self.customer.baskets.add(cart)
            request.session['cart_id'] = cart_id
            self.cart = Cart.objects.get(id=cart_id)

        self.form = CartItemCount

        query = request.session['search_query']
        print('asdasd', query)
        if query:
            self.list_goods = searche_good(request, query_full=query)
            print('self.list_goods', self.list_goods)

        return super(SearchGoodsFull, self).get(request, *args, **kwargs)
Beispiel #2
0
	def get(self, request, *args, **kwargs):
		self.category_id = kwargs['category_id']
		try:
			print("request.session['search_query']", request.session['search_query'])
		except:
			print("request.session['search_query']", 'netu')
		if request.user.is_authenticated():
			try:
				self.customer = request.user.customer_set.first()	
				self.opt_user = request.user.customer_set.first().opt
			except Exception as err:
				print(err)
		else:
			return redirect('login')		
		if self.customer.baskets.filter(paid_for=False).exists():
			for basket in self.customer.baskets.all():
				if not basket.paid_for:
					self.cart = basket
					request.session['cart_id'] = basket.id
					request.session['goods_card'] = dict()
		else:
			cart = Cart()
			cart.save()
			cart_id = cart.id
			self.customer.baskets.add(cart)
			request.session['cart_id'] = cart_id
			self.cart = Cart.objects.get(id=cart_id)
		self.form = CartItemCount
		self.opt_status = request.session.get('opt_status')
		return super(FilterLvlOne, self).get(request, *args, **kwargs)
Beispiel #3
0
    def get(self, request, *args, **kwargs):

        if request.user.is_authenticated():
            try:
                self.customer = request.user.customer_set.first()
                self.opt_user = request.user.customer_set.first().opt
            except Exception as err:
                print(err)
        else:
            return redirect('login')

        if self.customer.baskets.all().exists():
            for basket in self.customer.baskets.all():
                if not basket.paid_for:
                    self.cart = basket
                    request.session['cart_id'] = basket.id
        else:
            cart = Cart()
            cart.save()
            cart_id = cart.id
            self.customer.baskets.add(cart)
            request.session['cart_id'] = cart_id
            self.cart = Cart.objects.get(id=cart_id)

        self.form = CartItemCount
        self.opt_status = request.session.get('opt_status')
        return super(GoodDetailView, self).get(request, *args, **kwargs)
Beispiel #4
0
	def get_context_data(self, **kwargs):
		context = super(CourseDetailView, self).get_context_data(**kwargs)
		try:
			cart_id = self.request.session['cart_id']
			cart = Cart.objects.get(id=cart_id)
			self.request.session['total'] = cart.items.count()
		except:
			cart = Cart()
			cart.save()
			cart_id = cart.id
			self.request.session['cart_id'] = cart_id
			cart = Cart.objects.get(id=cart_id)

		context['cart'] = cart	
		return context
Beispiel #5
0
def CourseList(request):
	courses = Course.objects.all()
	try:
		cart_id = request.session['cart_id']
		cart = Cart.objects.get(id=cart_id)
		request.session['total'] = cart.items.count()
	except:
		cart = Cart()
		cart.save()
		cart_id = cart.id
		request.session['cart_id'] = cart_id
		cart = Cart.objects.get(id=cart_id)

	context = {
		'courses':courses,
		'cart': cart,
	}
	return render(request, 'home.html', context)
Beispiel #6
0
def CourseDetail(request,slug):
	course = get_object_or_404(Course,slug=slug)
	
	try:
		cart_id = request.session['cart_id']
		cart = Cart.objects.get(id=cart_id)
		request.session['total'] = cart.items.count()
	except:
		cart = Cart()
		cart.save()
		cart_id = cart.id
		request.session['cart_id'] = cart_id
		cart = Cart.objects.get(id=cart_id)


	context = {
		'course':course, 
		'cart':cart,
	}
	return render(request, 'courseDetail.html', context)
Beispiel #7
0
def viedoLessons(request, name_course):
	course = Course.objects.get(slug = name_course)
	lessons = LessonCourse.objects.all().filter(nameCourse=course.id)
	try:
		cart_id = request.session['cart_id']
		cart = Cart.objects.get(id=cart_id)
		request.session['total'] = cart.items.count()
	except:
		cart = Cart()
		cart.save()
		cart_id = cart.id
		request.session['cart_id'] = cart_id
		cart = Cart.objects.get(id=cart_id)

	paginator = Paginator(lessons, 1)
	page_number = request.GET.get('page', 1)
	page = paginator.get_page(page_number)

	if page.has_previous():
		prev_url = '?page={}'.format(page.previous_page_number())
	else:
		prev_url = ''

	if page.has_next():
		next_url = '?page={}'.format(page.next_page_number())
	else:
		next_url = ''
	context = {
		'course': course,
		'lessons': lessons,
		'page_object': page,
		'cart': cart,
		'next_url': next_url,
		'prev_url': prev_url,
	}

	return render(request, 'videoCourse.html', context)
Beispiel #8
0
def create_cart(sender, instance, created, **kwargs):
    if created:
        c = Cart(user=instance)
        w = Wallet(user=instance)
        c.save()
        w.save()