예제 #1
0
def checkout():
    form = OrderForm()
    cart = get_cart()
    categories = get_categories()
    return render_template('checkout.html',
                           form=form,
                           categories=categories,
                           cart=cart)
예제 #2
0
def home(request):
    now = timezone.now()

    user_info = Order.objects.filter(user=request.user.id).aggregate(
        spend_money_year=Sum(
            'price',
            filter=Q(ticket__start_date__gte=now - timezone.timedelta(days=365))
        ),
        bought_last_year=Count(
            'id',
            filter=Q(ticket__start_date__gte=now - timezone.timedelta(days=365))
        ),
        spend_money_month=Sum(
            'price',
            filter=Q(ticket__start_date__gte=now - timezone.timedelta(weeks=4))
        ),
        bought_last_month=Count(
            'id',
            filter=Q(ticket__start_date__gte=now - timezone.timedelta(weeks=4))
        ),
        spend_money_week=Sum(
            'price',
            filter=Q(ticket__start_date__gte=now - timezone.timedelta(days=7))
        ),
        bought_last_week=Count(
            'id',
            filter=Q(ticket__start_date__gte=now - timezone.timedelta(days=7))
        )
    )
    form = OrderForm(data=request.POST)
    if form.is_valid():
        order = form.save(commit=False)
        order.user_id = request.user.id
        order.save()
        return redirect('ecommerce:home')
    return render(request, 'ecommerce/home.html', context={"form": form,
                                                           'user_info': user_info})
예제 #3
0
def make_order(request, pk):
    order_form = OrderForm()

    if request.method == 'POST':
        order_form = OrderForm(request.POST)
        if order_form.is_valid():
            order = order_form.save(commit=False)
            order.user_id = pk

    context = {'order_form': order_form}

    return render(request=request,
                  template_name='order/make_order.html',
                  context=context)
예제 #4
0
 def test_from_validation_on_email_field(self):
     """Form should validate user's email if it is filled."""
     form = OrderForm(data=invalid_form_email)
     self.assertFalse(form.is_valid())
예제 #5
0
 def test_valid_form(self):
     """Form is valid, if there all required fields are filled."""
     form = OrderForm(data=required_fields)
     self.assertTrue(form.is_valid())
예제 #6
0
 def test_filled_form_without_required_field(self):
     """Form is still not valid, if there are some required fields left unfilled."""
     form = OrderForm(data=no_phone)
     self.assertFalse(form.is_valid())
예제 #7
0
 def test_empty_form(self):
     """Empty form shouldn't be valid."""
     form = OrderForm()
     self.assertFalse(form.is_valid())
예제 #8
0
 def test_from_validation_on_email_field(self):
     """Form should validate user's email if it is filled."""
     form = OrderForm(data=invalid_form_email)
     self.assertFalse(form.is_valid())
예제 #9
0
 def test_valid_form(self):
     """Form is valid, if there all required fields are filled."""
     form = OrderForm(data=required_fields)
     self.assertTrue(form.is_valid())
예제 #10
0
 def test_filled_form_without_required_field(self):
     """Form is still not valid, if there are some required fields left unfilled."""
     form = OrderForm(data=no_phone)
     self.assertFalse(form.is_valid())
예제 #11
0
 def test_empty_form(self):
     """Empty form shouldn't be valid."""
     form = OrderForm()
     self.assertFalse(form.is_valid())