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
2f57bea5
Commit
2f57bea5
authored
Jul 27, 2015
by
Tyler Nickerson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #229 from edx/nickersoft/last-edited-api
Added last edited date to courses API
parents
cc0d109d
77c50382
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletions
+10
-1
ecommerce/extensions/api/serializers.py
+5
-1
ecommerce/extensions/api/v2/tests/views/test_courses.py
+5
-0
No files found.
ecommerce/extensions/api/serializers.py
View file @
2f57bea5
...
@@ -114,6 +114,10 @@ class RefundSerializer(serializers.ModelSerializer):
...
@@ -114,6 +114,10 @@ class RefundSerializer(serializers.ModelSerializer):
class
CourseSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
CourseSerializer
(
serializers
.
HyperlinkedModelSerializer
):
products_url
=
serializers
.
SerializerMethodField
()
products_url
=
serializers
.
SerializerMethodField
()
last_edited
=
serializers
.
SerializerMethodField
()
def
get_last_edited
(
self
,
obj
):
return
obj
.
history
.
latest
()
.
history_date
.
strftime
(
ISO_8601_FORMAT
)
def
get_products_url
(
self
,
obj
):
def
get_products_url
(
self
,
obj
):
return
reverse
(
'api:v2:course-product-list'
,
kwargs
=
{
'parent_lookup_course_id'
:
obj
.
id
},
return
reverse
(
'api:v2:course-product-list'
,
kwargs
=
{
'parent_lookup_course_id'
:
obj
.
id
},
...
@@ -121,7 +125,7 @@ class CourseSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -121,7 +125,7 @@ class CourseSerializer(serializers.HyperlinkedModelSerializer):
class
Meta
(
object
):
class
Meta
(
object
):
model
=
Course
model
=
Course
fields
=
(
'id'
,
'url'
,
'name'
,
'type'
,
'products_url'
,)
fields
=
(
'id'
,
'url'
,
'name'
,
'type'
,
'products_url'
,
'last_edited'
)
read_only_fields
=
(
'type'
,)
read_only_fields
=
(
'type'
,)
extra_kwargs
=
{
extra_kwargs
=
{
'url'
:
{
'view_name'
:
COURSE_DETAIL_VIEW
}
'url'
:
{
'view_name'
:
COURSE_DETAIL_VIEW
}
...
...
ecommerce/extensions/api/v2/tests/views/test_courses.py
View file @
2f57bea5
...
@@ -7,6 +7,7 @@ import mock
...
@@ -7,6 +7,7 @@ import mock
from
oscar.core.loading
import
get_model
,
get_class
from
oscar.core.loading
import
get_model
,
get_class
from
waffle
import
Switch
from
waffle
import
Switch
from
ecommerce.core.constants
import
ISO_8601_FORMAT
from
ecommerce.courses.models
import
Course
from
ecommerce.courses.models
import
Course
from
ecommerce.courses.publishers
import
LMSPublisher
from
ecommerce.courses.publishers
import
LMSPublisher
from
ecommerce.extensions.api.v2.tests.views
import
JSON_CONTENT_TYPE
,
TestServerUrlMixin
from
ecommerce.extensions.api.v2.tests.views
import
JSON_CONTENT_TYPE
,
TestServerUrlMixin
...
@@ -35,12 +36,16 @@ class CourseViewSetTests(TestServerUrlMixin, CourseCatalogTestMixin, UserMixin,
...
@@ -35,12 +36,16 @@ class CourseViewSetTests(TestServerUrlMixin, CourseCatalogTestMixin, UserMixin,
""" Serializes a course to a Python dict. """
""" Serializes a course to a Python dict. """
products_url
=
self
.
get_full_url
(
reverse
(
'api:v2:course-product-list'
,
products_url
=
self
.
get_full_url
(
reverse
(
'api:v2:course-product-list'
,
kwargs
=
{
'parent_lookup_course_id'
:
course
.
id
}))
kwargs
=
{
'parent_lookup_course_id'
:
course
.
id
}))
last_edited
=
course
.
history
.
latest
()
.
history_date
.
strftime
(
ISO_8601_FORMAT
)
return
{
return
{
'id'
:
course
.
id
,
'id'
:
course
.
id
,
'name'
:
course
.
name
,
'name'
:
course
.
name
,
'type'
:
course
.
type
,
'type'
:
course
.
type
,
'url'
:
self
.
get_full_url
(
reverse
(
'api:v2:course-detail'
,
kwargs
=
{
'pk'
:
course
.
id
})),
'url'
:
self
.
get_full_url
(
reverse
(
'api:v2:course-detail'
,
kwargs
=
{
'pk'
:
course
.
id
})),
'products_url'
:
products_url
,
'products_url'
:
products_url
,
'last_edited'
:
last_edited
}
}
def
test_list
(
self
):
def
test_list
(
self
):
...
...
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