Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
907c3b4e
Commit
907c3b4e
authored
Apr 14, 2016
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70 from edx/clintonb/seat-data-loader-fix
Updated E-Commerce API data loader
parents
e1dc2fca
52370d8f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
37 deletions
+84
-37
course_discovery/apps/course_metadata/data_loaders.py
+23
-20
course_discovery/apps/course_metadata/tests/test_data_loaders.py
+61
-17
No files found.
course_discovery/apps/course_metadata/data_loaders.py
View file @
907c3b4e
...
...
@@ -343,19 +343,21 @@ class EcommerceApiDataLoader(AbstractDataLoader):
logger
.
warning
(
'Could not find course run [
%
s]'
,
course_run_key
)
return
None
for
product
in
body
[
'products'
]:
if
product
[
'structure'
]
!=
'child'
:
for
product
_body
in
body
[
'products'
]:
if
product
_body
[
'structure'
]
!=
'child'
:
continue
product
=
self
.
clean_strings
(
product
)
self
.
update_seat
(
course_run
,
product
)
product
_body
=
self
.
clean_strings
(
product_body
)
self
.
update_seat
(
course_run
,
product
_body
)
# Remove seats which no longer exist for that course run
certificate_types
=
[
self
.
get_certificate_type
(
product
)
for
product
in
body
[
'products'
]
if
product
[
'structure'
]
==
'child'
]
course_run
.
seats
.
exclude
(
type__in
=
certificate_types
)
.
delete
()
def
update_seat
(
self
,
course_run
,
product
):
currency_code
=
product
[
'stockrecords'
][
0
][
'price_currency'
]
def
update_seat
(
self
,
course_run
,
product_body
):
stock_record
=
product_body
[
'stockrecords'
][
0
]
currency_code
=
stock_record
[
'price_currency'
]
price
=
Decimal
(
stock_record
[
'price_excl_tax'
])
try
:
currency
=
Currency
.
objects
.
get
(
code
=
currency_code
)
...
...
@@ -363,22 +365,23 @@ class EcommerceApiDataLoader(AbstractDataLoader):
logger
.
warning
(
"Could not find currency [
%
s]"
,
currency_code
)
return
None
product_values
=
{
'type'
:
Seat
.
AUDIT
,
'currency'
:
currency
,
'upgrade_deadline'
:
product
.
get
(
'expires'
),
'price'
:
Decimal
(
product
.
get
(
'price'
,
0.0
)),
}
attributes
=
{
attribute
[
'name'
]:
attribute
[
'value'
]
for
attribute
in
product_body
[
'attribute_values'
]}
seat_type
=
attributes
.
get
(
'certificate_type'
,
Seat
.
AUDIT
)
credit_provider
=
attributes
.
get
(
'credit_provider'
)
credit_hours
=
attributes
.
get
(
'credit_hours'
)
if
credit_hours
:
credit_hours
=
int
(
credit_hours
)
for
att
in
product
[
'attribute_values'
]:
if
att
[
'name'
]
==
'certificate_type'
:
product_values
[
'type'
]
=
att
[
'value'
]
elif
att
[
'name'
]
==
'credit_provider'
:
product_values
[
'credit_provider'
]
=
att
[
'value'
]
elif
att
[
'name'
]
==
'credit_hours'
:
product_values
[
'credit_hours'
]
=
att
[
'value'
]
defaults
=
{
'price'
:
price
,
'upgrade_deadline'
:
self
.
parse_date
(
product_body
.
get
(
'expires'
)),
'credit_hours'
:
credit_hours
,
}
course_run
.
seats
.
update_or_create
(
type
=
product
.
get
(
'type'
),
defaults
=
product_values
)
course_run
.
seats
.
update_or_create
(
type
=
seat_type
,
credit_provider
=
credit_provider
,
currency
=
currency
,
defaults
=
defaults
)
def
get_certificate_type
(
self
,
product
):
return
next
(
...
...
course_discovery/apps/course_metadata/tests/test_data_loaders.py
View file @
907c3b4e
This diff is collapsed.
Click to expand it.
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