-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb2025a
commit 2cc6a6e
Showing
7 changed files
with
144 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django import forms | ||
|
||
|
||
class CouponApplyForm(forms.Form): | ||
''' | ||
This class is for Apply Coupon Code in Orders. | ||
''' | ||
|
||
code = forms.CharField(max_length=50) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from django.urls import path | ||
from coupon import views | ||
|
||
|
||
app_name = 'coupon' | ||
|
||
urlpatterns = [ | ||
|
||
path('apply/', views.CouponApply.as_view(), name='apply'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
from django.shortcuts import render | ||
from django.shortcuts import render, redirect | ||
from django.utils import timezone | ||
from django.views import View | ||
|
||
# Create your views here. | ||
from .models import Coupon | ||
from .forms import CouponApplyForm | ||
|
||
|
||
|
||
class CouponApply(View): | ||
''' | ||
This class is for apply coupon. | ||
''' | ||
|
||
def post(self, request): | ||
now = timezone.now() | ||
form = CouponApplyForm(request.POST) | ||
|
||
if form.is_valid(): | ||
try: | ||
coupon = Coupon.objects.get( | ||
code__iexact=form['code'], | ||
valid_from__lte=now, | ||
valid_to__gte=now, | ||
active=True | ||
) | ||
request.session['coupon_id'] = coupon.id | ||
except Coupon.DoesNotExist: | ||
request.session['coupon_id'] = None | ||
return redirect('cart:cart_detail') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters