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
067b2b1e
Commit
067b2b1e
authored
Jul 22, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #219 from edx/extra-course-product-attributes
Exposing Additional Attributes for the Course Detail View
parents
2cc017a5
fc92d3fe
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
3 deletions
+42
-3
ecommerce/courses/models.py
+13
-0
ecommerce/courses/tests/test_models.py
+22
-0
ecommerce/extensions/api/serializers.py
+5
-3
ecommerce/extensions/api/v2/tests/views/test_courses.py
+1
-0
ecommerce/extensions/api/v2/tests/views/test_products.py
+1
-0
No files found.
ecommerce/courses/models.py
View file @
067b2b1e
...
...
@@ -81,6 +81,19 @@ class Course(models.Model):
return
mode
@property
def
type
(
self
):
""" Returns the type of the course (based on the available seat types). """
seat_types
=
[(
seat
.
attr
.
certificate_type
or
''
)
.
lower
()
for
seat
in
self
.
seat_products
]
if
'credit'
in
seat_types
:
return
'credit'
elif
'professional'
in
seat_types
or
'no-id-professional'
in
seat_types
:
return
'professional'
elif
'verified'
in
seat_types
:
return
'verified'
else
:
return
'honor'
@property
def
parent_seat_product
(
self
):
""" Returns the course seat parent Product. """
return
self
.
products
.
get
(
product_class__slug
=
'seat'
,
structure
=
Product
.
PARENT
)
...
...
ecommerce/courses/tests/test_models.py
View file @
067b2b1e
...
...
@@ -176,3 +176,25 @@ class CourseTests(CourseCatalogTestMixin, TestCase):
self
.
assertEqual
(
course
.
products
.
count
(),
2
)
seat
=
course
.
seat_products
[
0
]
self
.
assert_course_seat_valid
(
seat
,
course
,
certificate_type
,
id_verification_required
,
price
,
credit_provider
)
def
test_type
(
self
):
""" Verify the property returns a type value corresponding to the available products. """
course
=
Course
.
objects
.
create
(
id
=
'a/b/c'
,
name
=
'Test Course'
)
self
.
assertEqual
(
course
.
type
,
'honor'
)
course
.
create_or_update_seat
(
'honor'
,
False
,
0
)
self
.
assertEqual
(
course
.
type
,
'honor'
)
course
.
create_or_update_seat
(
'verified'
,
True
,
10
)
self
.
assertEqual
(
course
.
type
,
'verified'
)
seat
=
course
.
create_or_update_seat
(
'professional'
,
True
,
100
)
self
.
assertEqual
(
course
.
type
,
'professional'
)
seat
.
delete
()
self
.
assertEqual
(
course
.
type
,
'verified'
)
course
.
create_or_update_seat
(
'no-id-professional'
,
False
,
100
)
self
.
assertEqual
(
course
.
type
,
'professional'
)
course
.
create_or_update_seat
(
'credit'
,
True
,
1000
,
credit_provider
=
'SMU'
)
self
.
assertEqual
(
course
.
type
,
'credit'
)
ecommerce/extensions/api/serializers.py
View file @
067b2b1e
...
...
@@ -70,7 +70,8 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
class
Meta
(
object
):
model
=
Product
fields
=
(
'id'
,
'url'
,
'product_class'
,
'title'
,
'price'
,
'expires'
,
'attribute_values'
,
'is_available_to_buy'
,)
fields
=
(
'id'
,
'url'
,
'structure'
,
'product_class'
,
'title'
,
'price'
,
'expires'
,
'attribute_values'
,
'is_available_to_buy'
,)
extra_kwargs
=
{
'url'
:
{
'view_name'
:
PRODUCT_DETAIL_VIEW
},
}
...
...
@@ -96,7 +97,7 @@ class OrderSerializer(serializers.ModelSerializer):
fields
=
(
'number'
,
'date_placed'
,
'status'
,
'currency'
,
'total_excl_tax'
,
'lines'
,
'billing_address'
)
class
PaymentProcessorSerializer
(
serializers
.
Serializer
):
# pylint: disable=abstract-method
class
PaymentProcessorSerializer
(
serializers
.
Serializer
):
# pylint: disable=abstract-method
""" Serializer to use with instances of processors.BasePaymentProcessor """
def
to_representation
(
self
,
instance
):
...
...
@@ -120,7 +121,8 @@ class CourseSerializer(serializers.HyperlinkedModelSerializer):
class
Meta
(
object
):
model
=
Course
fields
=
(
'id'
,
'url'
,
'name'
,
'products_url'
,)
fields
=
(
'id'
,
'url'
,
'name'
,
'type'
,
'products_url'
,)
read_only_fields
=
(
'type'
,)
extra_kwargs
=
{
'url'
:
{
'view_name'
:
COURSE_DETAIL_VIEW
}
}
ecommerce/extensions/api/v2/tests/views/test_courses.py
View file @
067b2b1e
...
...
@@ -35,6 +35,7 @@ class CourseViewSetTests(TestServerUrlMixin, CourseCatalogTestMixin, UserMixin,
return
{
'id'
:
course
.
id
,
'name'
:
course
.
name
,
'type'
:
course
.
type
,
'url'
:
self
.
get_full_url
(
reverse
(
'api:v2:course-detail'
,
kwargs
=
{
'pk'
:
course
.
id
})),
'products_url'
:
products_url
,
}
...
...
ecommerce/extensions/api/v2/tests/views/test_products.py
View file @
067b2b1e
...
...
@@ -37,6 +37,7 @@ class ProductViewSetTests(TestServerUrlMixin, CourseCatalogTestMixin, UserMixin,
data
=
{
'id'
:
product
.
id
,
'url'
:
self
.
get_full_url
(
reverse
(
'api:v2:product-detail'
,
kwargs
=
{
'pk'
:
product
.
id
})),
'structure'
:
product
.
structure
,
'product_class'
:
unicode
(
product
.
get_product_class
()),
'title'
:
product
.
title
,
'expires'
:
product
.
expires
.
strftime
(
ISO_8601_FORMAT
)
if
product
.
expires
else
None
,
...
...
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