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
0a7fdb31
Commit
0a7fdb31
authored
Dec 26, 2017
by
Ahsan Ulhaq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove history usage from course
This reverts commit 51e794926c354a938c7353594530548e86b1d712.
parent
8b9a953e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
20 deletions
+108
-20
ecommerce/courses/management/commands/sync_history_with_course.py
+34
-0
ecommerce/courses/migrations/0006_auto_20171204_1036.py
+35
-0
ecommerce/courses/models.py
+2
-0
ecommerce/courses/tests/test_sync_history_with_course.py
+35
-0
ecommerce/extensions/api/serializers.py
+1
-5
ecommerce/extensions/api/v2/tests/views/test_courses.py
+1
-15
No files found.
ecommerce/courses/management/commands/sync_history_with_course.py
0 → 100644
View file @
0a7fdb31
from
__future__
import
unicode_literals
import
logging
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.management.base
import
BaseCommand
from
django.db
import
transaction
from
ecommerce.courses.models
import
Course
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
'Sync course history data with course created modified date.'
def
handle
(
self
,
*
args
,
**
options
):
courses
=
Course
.
objects
.
all
()
with
transaction
.
atomic
():
for
course
in
courses
:
try
:
course
.
created
=
course
.
history
.
earliest
()
.
history_date
course
.
modified
=
course
.
history
.
latest
()
.
history_date
course
.
save
()
except
ObjectDoesNotExist
:
logger
.
warning
(
'History object for course with course_id:
%
s does not exist'
,
course
.
id
)
course
.
created
=
None
course
.
modified
=
None
course
.
save
()
ecommerce/courses/migrations/0006_auto_20171204_1036.py
0 → 100755
View file @
0a7fdb31
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-12-04 10:36
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'courses'
,
'0005_auto_20170525_0131'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'course'
,
name
=
'created'
,
field
=
models
.
DateTimeField
(
auto_now_add
=
True
,
null
=
True
),
),
migrations
.
AddField
(
model_name
=
'course'
,
name
=
'modified'
,
field
=
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
),
),
migrations
.
AddField
(
model_name
=
'historicalcourse'
,
name
=
'created'
,
field
=
models
.
DateTimeField
(
blank
=
True
,
editable
=
False
,
null
=
True
),
),
migrations
.
AddField
(
model_name
=
'historicalcourse'
,
name
=
'modified'
,
field
=
models
.
DateTimeField
(
blank
=
True
,
editable
=
False
,
null
=
True
),
),
]
ecommerce/courses/models.py
View file @
0a7fdb31
...
...
@@ -40,6 +40,8 @@ class Course(models.Model):
help_text
=
_
(
'Last date/time on which verification for this product can be submitted.'
)
)
history
=
HistoricalRecords
()
created
=
models
.
DateTimeField
(
null
=
True
,
auto_now_add
=
True
)
modified
=
models
.
DateTimeField
(
null
=
True
,
auto_now
=
True
)
thumbnail_url
=
models
.
URLField
(
null
=
True
,
blank
=
True
)
def
__unicode__
(
self
):
...
...
ecommerce/courses/tests/test_sync_history_with_course.py
0 → 100644
View file @
0a7fdb31
import
datetime
from
django.core.management
import
call_command
from
testfixtures
import
LogCapture
from
ecommerce.courses.models
import
Course
from
ecommerce.courses.tests.factories
import
CourseFactory
from
ecommerce.tests.testcases
import
TestCase
LOGGER_NAME
=
'ecommerce.courses.management.commands.sync_history_with_course'
class
SyncHistoryTests
(
TestCase
):
def
setUp
(
self
):
super
(
SyncHistoryTests
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
(
id
=
'edx/Demo_Course/DemoX'
,
site
=
self
.
site
)
def
test_history_not_exist
(
self
):
self
.
course
.
history
.
all
()
.
delete
()
with
LogCapture
(
LOGGER_NAME
)
as
log
:
call_command
(
'sync_history_with_course'
)
log
.
check
(
(
LOGGER_NAME
,
'WARNING'
,
'History object for course with course_id: edx/Demo_Course/DemoX does not exist'
)
)
def
test_sync_history_data
(
self
):
self
.
course
.
created
=
self
.
course
.
created
+
datetime
.
timedelta
(
days
=
1
)
self
.
course
.
save
()
call_command
(
'sync_history_with_course'
)
course
=
Course
.
objects
.
get
(
id
=
'edx/Demo_Course/DemoX'
)
self
.
assertEqual
(
course
.
created
,
self
.
course
.
history
.
earliest
()
.
history_date
)
ecommerce/extensions/api/serializers.py
View file @
0a7fdb31
...
...
@@ -7,7 +7,6 @@ from decimal import Decimal
import
waffle
from
dateutil.parser
import
parse
from
django.contrib.auth
import
get_user_model
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db
import
transaction
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -298,10 +297,7 @@ class CourseSerializer(serializers.HyperlinkedModelSerializer):
self
.
fields
.
pop
(
'products'
,
None
)
def
get_last_edited
(
self
,
obj
):
try
:
return
obj
.
history
.
latest
()
.
history_date
.
strftime
(
ISO_8601_FORMAT
)
except
ObjectDoesNotExist
:
return
None
return
obj
.
modified
.
strftime
(
ISO_8601_FORMAT
)
if
obj
.
modified
else
None
def
get_products_url
(
self
,
obj
):
return
reverse
(
'api:v2:course-product-list'
,
kwargs
=
{
'parent_lookup_course_id'
:
obj
.
id
},
...
...
ecommerce/extensions/api/v2/tests/views/test_courses.py
View file @
0a7fdb31
...
...
@@ -6,7 +6,6 @@ import jwt
import
mock
from
django.conf
import
settings
from
django.contrib.auth
import
get_user_model
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.urlresolvers
import
reverse
from
oscar.core.loading
import
get_class
,
get_model
...
...
@@ -42,12 +41,7 @@ class CourseViewSetTests(ProductSerializerMixin, DiscoveryTestMixin, TestCase):
products_url
=
self
.
get_full_url
(
reverse
(
'api:v2:course-product-list'
,
kwargs
=
{
'parent_lookup_course_id'
:
course
.
id
}))
last_edited
=
None
try
:
last_edited
=
course
.
history
.
latest
()
.
history_date
.
strftime
(
ISO_8601_FORMAT
)
except
ObjectDoesNotExist
:
pass
last_edited
=
course
.
modified
.
strftime
(
ISO_8601_FORMAT
)
enrollment_code
=
course
.
enrollment_code_product
data
=
{
...
...
@@ -115,14 +109,6 @@ class CourseViewSetTests(ProductSerializerMixin, DiscoveryTestMixin, TestCase):
response
=
self
.
client
.
get
(
self
.
list_path
)
self
.
assertDictEqual
(
json
.
loads
(
response
.
content
),
{
'count'
:
0
,
'next'
:
None
,
'previous'
:
None
,
'results'
:
[]})
def
test_list_without_history
(
self
):
course
=
Course
.
objects
.
all
()[
0
]
course
.
history
.
all
()
.
delete
()
response
=
self
.
client
.
get
(
self
.
list_path
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertListEqual
(
json
.
loads
(
response
.
content
)[
'results'
],
[
self
.
serialize_course
(
self
.
course
)])
def
test_create
(
self
):
""" Verify the view can create a new Course."""
Course
.
objects
.
all
()
.
delete
()
...
...
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