Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
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
ecommerce
Commits
18743016
Commit
18743016
authored
Nov 14, 2016
by
Vedran Karačić
Committed by
GitHub
Nov 14, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1010 from edx/vkaracic/SOL-2134
[SOL-2134] Add error message template.
parents
25666359
c0036400
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
64 additions
and
49 deletions
+64
-49
ecommerce/coupons/tests/test_views.py
+16
-6
ecommerce/coupons/views.py
+9
-15
ecommerce/static/sass/base/_base.scss
+0
-8
ecommerce/static/sass/base/main.scss
+1
-0
ecommerce/static/sass/partials/utilities/_variables.scss
+3
-0
ecommerce/static/sass/partials/views/_coupon_offer.scss
+2
-2
ecommerce/static/sass/partials/views/_error.scss
+12
-0
ecommerce/static/templates/_offer_error.html
+1
-1
ecommerce/templates/coupons/_offer_error.html
+1
-17
ecommerce/templates/edx/error.html
+19
-0
No files found.
ecommerce/coupons/tests/test_views.py
View file @
18743016
...
@@ -12,6 +12,7 @@ from oscar.test.factories import (
...
@@ -12,6 +12,7 @@ from oscar.test.factories import (
ConditionalOfferFactory
,
OrderFactory
,
OrderLineFactory
,
RangeFactory
,
VoucherFactory
ConditionalOfferFactory
,
OrderFactory
,
OrderLineFactory
,
RangeFactory
,
VoucherFactory
)
)
from
oscar.test.utils
import
RequestFactory
from
oscar.test.utils
import
RequestFactory
from
rest_framework
import
status
from
ecommerce.core.url_utils
import
get_lms_url
from
ecommerce.core.url_utils
import
get_lms_url
from
ecommerce.coupons.tests.mixins
import
CouponMixin
from
ecommerce.coupons.tests.mixins
import
CouponMixin
...
@@ -263,7 +264,6 @@ class CouponOfferViewTests(ApiMockMixin, CouponMixin, CourseCatalogTestMixin, Lm
...
@@ -263,7 +264,6 @@ class CouponOfferViewTests(ApiMockMixin, CouponMixin, CourseCatalogTestMixin, Lm
class
CouponRedeemViewTests
(
CouponMixin
,
CourseCatalogTestMixin
,
LmsApiMockMixin
,
TestCase
):
class
CouponRedeemViewTests
(
CouponMixin
,
CourseCatalogTestMixin
,
LmsApiMockMixin
,
TestCase
):
redeem_url
=
reverse
(
'coupons:redeem'
)
redeem_url
=
reverse
(
'coupons:redeem'
)
HTTP_MOVED
=
301
def
setUp
(
self
):
def
setUp
(
self
):
super
(
CouponRedeemViewTests
,
self
)
.
setUp
()
super
(
CouponRedeemViewTests
,
self
)
.
setUp
()
...
@@ -317,7 +317,7 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
...
@@ -317,7 +317,7 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
response
=
self
.
client
.
get
(
url_without_sku
)
response
=
self
.
client
.
get
(
url_without_sku
)
self
.
assertEqual
(
response
.
context
[
'error'
],
_
(
'SKU not provided.'
))
self
.
assertEqual
(
response
.
context
[
'error'
],
_
(
'SKU not provided.'
))
def
test_invalid_voucher
(
self
):
def
test_invalid_voucher
_code
(
self
):
""" Verify an error is returned when voucher does not exist. """
""" Verify an error is returned when voucher does not exist. """
code
=
'DOESNTEXIST'
code
=
'DOESNTEXIST'
url
=
self
.
redeem_url
+
'?code={}&sku={}'
.
format
(
code
,
self
.
stock_record
.
partner_sku
)
url
=
self
.
redeem_url
+
'?code={}&sku={}'
.
format
(
code
,
self
.
stock_record
.
partner_sku
)
...
@@ -332,6 +332,16 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
...
@@ -332,6 +332,16 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
context
[
'error'
],
_
(
'The product does not exist.'
))
self
.
assertEqual
(
response
.
context
[
'error'
],
_
(
'The product does not exist.'
))
def
test_expired_voucher
(
self
):
""" Verify an error is returned for expired coupon. """
start_datetime
=
now
()
-
datetime
.
timedelta
(
days
=
20
)
end_datetime
=
now
()
-
datetime
.
timedelta
(
days
=
10
)
code
=
'INVALID'
__
,
product
=
prepare_voucher
(
code
=
code
,
start_datetime
=
start_datetime
,
end_datetime
=
end_datetime
)
url
=
self
.
redeem_url
+
'?code={}&sku={}'
.
format
(
code
,
StockRecord
.
objects
.
get
(
product
=
product
)
.
partner_sku
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
context
[
'error'
],
_
(
'This coupon code has expired.'
))
@httpretty.activate
@httpretty.activate
def
test_basket_redirect_discount_code
(
self
):
def
test_basket_redirect_discount_code
(
self
):
""" Verify the view redirects to the basket single-item view when a discount code is provided. """
""" Verify the view redirects to the basket single-item view when a discount code is provided. """
...
@@ -345,9 +355,9 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
...
@@ -345,9 +355,9 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
def
test_basket_redirect_enrollment_code
(
self
):
def
test_basket_redirect_enrollment_code
(
self
):
""" Verify the view redirects to LMS when an enrollment code is provided. """
""" Verify the view redirects to LMS when an enrollment code is provided. """
self
.
create_and_test_coupon
()
self
.
create_and_test_coupon
()
httpretty
.
register_uri
(
httpretty
.
GET
,
self
.
student_dashboard_url
,
status
=
s
elf
.
HTTP_MOVED
)
httpretty
.
register_uri
(
httpretty
.
GET
,
self
.
student_dashboard_url
,
status
=
s
tatus
.
HTTP_301_MOVED_PERMANENTLY
)
self
.
mock_account_api
(
self
.
request
,
self
.
user
.
username
,
data
=
{
'is_active'
:
True
})
self
.
mock_account_api
(
self
.
request
,
self
.
user
.
username
,
data
=
{
'is_active'
:
True
})
self
.
assert_redemption_page_redirects
(
self
.
student_dashboard_url
,
target
=
s
elf
.
HTTP_MOVED
)
self
.
assert_redemption_page_redirects
(
self
.
student_dashboard_url
,
target
=
s
tatus
.
HTTP_301_MOVED_PERMANENTLY
)
@httpretty.activate
@httpretty.activate
def
test_multiple_vouchers
(
self
):
def
test_multiple_vouchers
(
self
):
...
@@ -356,8 +366,8 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
...
@@ -356,8 +366,8 @@ class CouponRedeemViewTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin
basket
=
Basket
.
get_basket
(
self
.
user
,
self
.
site
)
basket
=
Basket
.
get_basket
(
self
.
user
,
self
.
site
)
basket
.
vouchers
.
add
(
Voucher
.
objects
.
get
(
code
=
COUPON_CODE
))
basket
.
vouchers
.
add
(
Voucher
.
objects
.
get
(
code
=
COUPON_CODE
))
self
.
mock_account_api
(
self
.
request
,
self
.
user
.
username
,
data
=
{
'is_active'
:
True
})
self
.
mock_account_api
(
self
.
request
,
self
.
user
.
username
,
data
=
{
'is_active'
:
True
})
httpretty
.
register_uri
(
httpretty
.
GET
,
self
.
student_dashboard_url
,
status
=
s
elf
.
HTTP_MOVED
)
httpretty
.
register_uri
(
httpretty
.
GET
,
self
.
student_dashboard_url
,
status
=
s
tatus
.
HTTP_301_MOVED_PERMANENTLY
)
self
.
assert_redemption_page_redirects
(
self
.
student_dashboard_url
,
target
=
s
elf
.
HTTP_MOVED
)
self
.
assert_redemption_page_redirects
(
self
.
student_dashboard_url
,
target
=
s
tatus
.
HTTP_301_MOVED_PERMANENTLY
)
@httpretty.activate
@httpretty.activate
def
test_already_enrolled_rejection
(
self
):
def
test_already_enrolled_rejection
(
self
):
...
...
ecommerce/coupons/views.py
View file @
18743016
...
@@ -97,24 +97,16 @@ class CouponOfferView(TemplateView):
...
@@ -97,24 +97,16 @@ class CouponOfferView(TemplateView):
try
:
try
:
voucher
,
products
=
get_voucher_and_products_from_code
(
code
=
code
)
voucher
,
products
=
get_voucher_and_products_from_code
(
code
=
code
)
except
Voucher
.
DoesNotExist
:
except
Voucher
.
DoesNotExist
:
return
{
return
{
'error'
:
_
(
'Coupon does not exist'
)}
'error'
:
_
(
'Coupon does not exist'
),
}
except
exceptions
.
ProductNotFoundError
:
except
exceptions
.
ProductNotFoundError
:
return
{
return
{
'error'
:
_
(
'The voucher is not applicable to your current basket.'
)}
'error'
:
_
(
'The voucher is not applicable to your current basket.'
),
}
valid_voucher
,
msg
=
voucher_is_valid
(
voucher
,
products
,
self
.
request
)
valid_voucher
,
msg
=
voucher_is_valid
(
voucher
,
products
,
self
.
request
)
if
valid_voucher
:
if
valid_voucher
:
self
.
template_name
=
'coupons/offer.html'
self
.
template_name
=
'coupons/offer.html'
return
return
return
{
return
{
'error'
:
msg
}
'error'
:
msg
,
return
{
'error'
:
_
(
'This coupon code is invalid.'
)}
}
return
{
'error'
:
_
(
'This coupon code is invalid.'
),
}
@method_decorator
(
login_required_for_credit
)
@method_decorator
(
login_required_for_credit
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -158,9 +150,11 @@ class CouponRedeemView(EdxOrderPlacementMixin, View):
...
@@ -158,9 +150,11 @@ class CouponRedeemView(EdxOrderPlacementMixin, View):
return
render
(
request
,
template_name
,
{
'error'
:
_
(
'You are not eligible to use this coupon.'
)})
return
render
(
request
,
template_name
,
{
'error'
:
_
(
'You are not eligible to use this coupon.'
)})
if
not
request
.
user
.
account_details
(
request
)[
'is_active'
]:
if
not
request
.
user
.
account_details
(
request
)[
'is_active'
]:
return
render
(
request
,
template_name
,
{
return
render
(
'error'
:
_
(
'You need to activate your account in order to redeem this coupon.'
)
request
,
})
template_name
,
{
'error'
:
_
(
'You need to activate your account in order to redeem this coupon.'
)}
)
if
request
.
user
.
is_user_already_enrolled
(
request
,
product
):
if
request
.
user
.
is_user_already_enrolled
(
request
,
product
):
return
render
(
request
,
template_name
,
{
'error'
:
_
(
'You are already enrolled in the course.'
)})
return
render
(
request
,
template_name
,
{
'error'
:
_
(
'You are already enrolled in the course.'
)})
...
...
ecommerce/static/sass/base/_base.scss
View file @
18743016
...
@@ -34,14 +34,6 @@ a {
...
@@ -34,14 +34,6 @@ a {
}
}
}
}
.message-error
{
border-top
:
4px
solid
#B20610
;
h3
{
margin-bottom
:
10px
;
font-weight
:
bold
;
}
}
.depth
{
.depth
{
padding
:
1
.25rem
1
.25rem
;
padding
:
1
.25rem
1
.25rem
;
}
}
...
...
ecommerce/static/sass/base/main.scss
View file @
18743016
...
@@ -34,5 +34,6 @@
...
@@ -34,5 +34,6 @@
@import
'views/course_admin'
;
@import
'views/course_admin'
;
@import
'views/coupon_admin'
;
@import
'views/coupon_admin'
;
@import
'views/coupon_offer'
;
@import
'views/coupon_offer'
;
@import
'views/error'
;
@import
"default"
;
@import
"default"
;
ecommerce/static/sass/partials/utilities/_variables.scss
View file @
18743016
...
@@ -54,3 +54,6 @@ $small-input-width: 174px;
...
@@ -54,3 +54,6 @@ $small-input-width: 174px;
$input-addon-width
:
40px
;
$input-addon-width
:
40px
;
$coupon-grid-item-height
:
75px
;
$coupon-grid-item-height
:
75px
;
$container-padding-top
:
60px
;
$container-padding-bottom
:
spacing-vertical
(
small
);
ecommerce/static/sass/partials/views/_coupon_offer.scss
View file @
18743016
#offer
{
#offer
{
.container
{
.container
{
padding-top
:
60px
;
padding-top
:
$container-padding-top
;
padding-bottom
:
spacing-vertical
(
small
)
;
padding-bottom
:
$container-padding-bottom
;
.row
{
.row
{
.pagination-block
{
.pagination-block
{
...
...
ecommerce/static/sass/partials/views/_error.scss
0 → 100644
View file @
18743016
#error-message
{
padding-top
:
$container-padding-top
;
padding-bottom
:
$container-padding-bottom
;
}
.message-error-content
{
border-top
:
4px
solid
#B20610
;
h3
{
margin-bottom
:
10px
;
font-weight
:
bold
;
}
}
ecommerce/static/templates/_offer_error.html
View file @
18743016
<div
class=
"depth depth-2 message-error offer-error"
>
<div
class=
"depth depth-2 message-error
-content
offer-error"
>
<h3><
%=
error_msg
%
></h3>
<h3><
%=
error_msg
%
></h3>
<
%
-
gettext
('
If
you
need
assistance
,
contact
edX
support
.')
%
>
<
%
-
gettext
('
If
you
need
assistance
,
contact
edX
support
.')
%
>
</div>
</div>
ecommerce/templates/coupons/_offer_error.html
View file @
18743016
{% extends 'edx/
base
.html' %}
{% extends 'edx/
error
.html' %}
{% load i18n %}
{% load i18n %}
{% block title %}{% trans "Redeem" %}{% endblock %}
{% block title %}{% trans "Redeem" %}{% endblock %}
{% block navbar %}
{% include 'edx/partials/_student_navbar.html' %}
{% endblock navbar %}
{% block content %}
<div
id=
"offer"
>
<div
class=
"container"
>
<div
class=
"depth depth-2 message-error"
>
<h3>
{{ error }}
</h3>
{% trans "If you need assistance, contact edX support." %}
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
ecommerce/templates/edx/error.html
0 → 100644
View file @
18743016
{% extends 'edx/base.html' %}
{% load i18n %}
{% block title %}{% endblock %}
{% block navbar %}
{% include 'edx/partials/_student_navbar.html' %}
{% endblock navbar %}
{% block content %}
<div
id=
"error-message"
>
<div
class=
"container"
>
<div
class=
"depth depth-2 message-error-content"
>
<h3>
{{ error }}
</h3>
{% trans "If you need assistance, contact edX support." %}
</div>
</div>
</div>
{% endblock %}
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