Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
33bdf935
Commit
33bdf935
authored
Aug 05, 2014
by
asadiqbal08
Committed by
Chris Dodge
Aug 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retrieving active coupon codes from model
parent
fc8ec1cc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
15 deletions
+12
-15
lms/djangoapps/shoppingcart/tests/test_views.py
+2
-2
lms/djangoapps/shoppingcart/views.py
+10
-13
No files found.
lms/djangoapps/shoppingcart/tests/test_views.py
View file @
33bdf935
...
...
@@ -142,8 +142,8 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
self
.
add_coupon
(
self
.
course_key
,
False
)
self
.
add_course_to_user_cart
()
resp
=
self
.
client
.
post
(
reverse
(
'shoppingcart.views.use_code'
),
{
'code'
:
self
.
coupon_code
})
self
.
assertEqual
(
resp
.
status_code
,
40
0
)
self
.
assertIn
(
"
Coupon '{0}' is inactive
."
.
format
(
self
.
coupon_code
),
resp
.
content
)
self
.
assertEqual
(
resp
.
status_code
,
40
4
)
self
.
assertIn
(
"
Discount does not exist against code '{0}'
."
.
format
(
self
.
coupon_code
),
resp
.
content
)
def
test_course_does_not_exist_in_cart_against_valid_coupon
(
self
):
course_key
=
self
.
course_key
.
to_deprecated_string
()
+
'testing'
...
...
lms/djangoapps/shoppingcart/views.py
View file @
33bdf935
...
...
@@ -160,7 +160,7 @@ def use_code(request):
"""
code
=
request
.
POST
[
"code"
]
try
:
coupon
=
Coupon
.
objects
.
get
(
code
=
code
)
coupon
=
Coupon
.
objects
.
get
(
code
=
code
,
is_active
=
True
)
except
Coupon
.
DoesNotExist
:
# If not coupon code then we check that code against course registration code
try
:
...
...
@@ -192,18 +192,15 @@ def use_coupon_code(coupon, user):
"""
This method utilize course coupon code
"""
if
coupon
.
is_active
:
try
:
cart
=
Order
.
get_cart_for_user
(
user
)
CouponRedemption
.
add_coupon_redemption
(
coupon
,
cart
)
except
CouponAlreadyExistException
:
return
HttpResponseBadRequest
(
_
(
"Coupon '{0}' already used."
.
format
(
coupon
.
code
)))
except
ItemDoesNotExistAgainstCouponException
:
return
HttpResponseNotFound
(
_
(
"Coupon '{0}' is not valid for any course in the shopping cart."
.
format
(
coupon
.
code
)))
return
HttpResponse
(
json
.
dumps
({
'response'
:
'success'
}),
content_type
=
"application/json"
)
else
:
return
HttpResponseBadRequest
(
_
(
"Coupon '{0}' is inactive."
.
format
(
coupon
.
code
)))
try
:
cart
=
Order
.
get_cart_for_user
(
user
)
CouponRedemption
.
add_coupon_redemption
(
coupon
,
cart
)
except
CouponAlreadyExistException
:
return
HttpResponseBadRequest
(
_
(
"Coupon '{0}' already used."
.
format
(
coupon
.
code
)))
except
ItemDoesNotExistAgainstCouponException
:
return
HttpResponseNotFound
(
_
(
"Coupon '{0}' is not valid for any course in the shopping cart."
.
format
(
coupon
.
code
)))
return
HttpResponse
(
json
.
dumps
({
'response'
:
'success'
}),
content_type
=
"application/json"
)
@login_required
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment