Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
6aeb6d47
Commit
6aeb6d47
authored
Oct 17, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addressed data migration issues
parent
23c72e73
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
205 deletions
+145
-205
lms/djangoapps/api_manager/management/commands/migrate_courseids_v2.py
+27
-28
lms/djangoapps/api_manager/management/commands/tests/test_migrate_courseids_v2.py
+26
-52
lms/djangoapps/gradebook/management/commands/migrate_gradebook_courseids_v2.py
+25
-8
lms/djangoapps/gradebook/management/commands/tests/test_migrate_gradebook_courseids_v2.py
+13
-41
lms/djangoapps/projects/management/commands/migrate_project_courseids_v2.py
+27
-22
lms/djangoapps/projects/management/commands/tests/test_migrate_project_courseids_v2.py
+27
-54
No files found.
lms/djangoapps/api_manager/management/commands/migrate_courseids_v2.py
View file @
6aeb6d47
...
@@ -10,6 +10,26 @@ from api_manager import models as api_models
...
@@ -10,6 +10,26 @@ from api_manager import models as api_models
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
_migrate_course_id
(
old_course_id
):
course_id
=
old_course_id
.
replace
(
"slashes:"
,
""
)
course_id
=
course_id
.
replace
(
"course-v1:"
,
""
)
course_id
=
course_id
.
replace
(
"+"
,
"/"
)
return
course_id
def
_migrate_content_id
(
old_content_id
):
if
"slashes:"
in
old_content_id
or
"course-v1:"
in
old_content_id
:
new_content_id
=
self
.
_migrate_course_id
(
old_content_id
)
else
:
content_id
=
old_content_id
.
replace
(
"location:"
,
""
)
content_components
=
content_id
.
split
(
'+'
)
new_content_id
=
"i4x:/"
for
x
in
range
(
0
,
len
(
content_components
)):
if
x
!=
2
:
new_content_id
=
"{}/{}"
.
format
(
new_content_id
,
content_components
[
x
])
return
new_content_id
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
"""
Migrates legacy course/content identifiers across several models to the new format
Migrates legacy course/content identifiers across several models to the new format
...
@@ -20,45 +40,24 @@ class Command(BaseCommand):
...
@@ -20,45 +40,24 @@ class Command(BaseCommand):
log
.
warning
(
'Migrating Course Groups...'
)
log
.
warning
(
'Migrating Course Groups...'
)
course_groups
=
api_models
.
CourseGroupRelationship
.
objects
.
all
()
course_groups
=
api_models
.
CourseGroupRelationship
.
objects
.
all
()
for
cg
in
course_groups
:
for
cg
in
course_groups
:
current_course_id
=
cg
.
course_id
cg
.
course_id
=
_migrate_course_id
(
cg
.
course_id
)
oldstyle_course_id
=
current_course_id
.
replace
(
"slashes:"
,
""
)
oldstyle_course_id
=
oldstyle_course_id
.
replace
(
"+"
,
"/"
)
cg
.
course_id
=
oldstyle_course_id
cg
.
save
()
cg
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Migrating Course Content Groups...'
)
log
.
warning
(
'Migrating Course Content Groups...'
)
course_content_groups
=
api_models
.
CourseContentGroupRelationship
.
objects
.
all
()
course_content_groups
=
api_models
.
CourseContentGroupRelationship
.
objects
.
all
()
for
ccg
in
course_content_groups
:
for
ccg
in
course_content_groups
:
current_course_id
=
ccg
.
course_id
ccg
.
course_id
=
_migrate_course_id
(
ccg
.
course_id
)
oldstyle_course_id
=
current_course_id
.
replace
(
"slashes:"
,
""
)
ccg
.
content_id
=
_migrate_content_id
(
ccg
.
content_id
)
oldstyle_course_id
=
oldstyle_course_id
.
replace
(
"+"
,
"/"
)
ccg
.
course_id
=
oldstyle_course_id
current_content_id
=
ccg
.
content_id
oldstyle_content_id
=
current_content_id
.
replace
(
"slashes:"
,
""
)
oldstyle_content_id
=
oldstyle_content_id
.
replace
(
"+"
,
"/"
)
ccg
.
content_id
=
oldstyle_content_id
ccg
.
save
()
ccg
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Migrating Course Module Completions...'
)
log
.
warning
(
'Migrating Course Module Completions...'
)
course_module_completions
=
api_models
.
CourseModuleCompletion
.
objects
.
all
()
course_module_completions
=
api_models
.
CourseModuleCompletion
.
objects
.
all
()
for
cmc
in
course_module_completions
:
for
cmc
in
course_module_completions
:
current_course_id
=
cmc
.
course_id
cmc
.
course_id
=
_migrate_course_id
(
cmc
.
course_id
)
oldstyle_course_id
=
current_course_id
.
replace
(
"slashes:"
,
""
)
cmc
.
content_id
=
_migrate_content_id
(
cmc
.
content_id
)
oldstyle_course_id
=
oldstyle_course_id
.
replace
(
"+"
,
"/"
)
cmc
.
course_id
=
oldstyle_course_id
current_content_id
=
cmc
.
content_id
oldstyle_content_id
=
current_content_id
.
replace
(
"slashes:"
,
""
)
oldstyle_content_id
=
oldstyle_content_id
.
replace
(
"+"
,
"/"
)
cmc
.
content_id
=
oldstyle_content_id
if
cmc
.
stage
is
not
None
:
if
cmc
.
stage
is
not
None
:
current_stage
=
cmc
.
stage
cmc
.
stage
=
_migrate_content_id
(
cmc
.
stage
)
oldstyle_stage
=
current_stage
.
replace
(
"slashes:"
,
""
)
cmc
.
save
()
oldstyle_stage
=
oldstyle_stage
.
replace
(
"+"
,
"/"
)
cmc
.
stage
=
oldstyle_stage
cmc
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
lms/djangoapps/api_manager/management/commands/tests/test_migrate_courseids_v2.py
View file @
6aeb6d47
...
@@ -20,42 +20,15 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
...
@@ -20,42 +20,15 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
(
self
.
bad_style_course_id
=
"slashes:old+style+id"
start
=
datetime
(
2014
,
6
,
16
,
14
,
30
),
self
.
good_style_course_id
=
"old/style/id"
end
=
datetime
(
2015
,
1
,
16
)
self
.
bad_style_content_id
=
"location:old+style+id+chapter+1234567890"
)
self
.
good_style_content_id
=
"i4x://old/style/chapter/1234567890"
self
.
test_data
=
'<html>{}</html>'
.
format
(
str
(
uuid
.
uuid4
()))
self
.
bad_style_course_id2
=
"course-v1:old2+style2+id2"
self
.
chapter
=
ItemFactory
.
create
(
self
.
good_style_course_id2
=
"old2/style2/id2"
category
=
"chapter"
,
self
.
bad_style_content_id2
=
"location:old2+style2+id2+chapter2+1234567890"
parent_location
=
self
.
course
.
location
,
self
.
good_style_content_id2
=
"i4x://old2/style2/chapter2/1234567890"
data
=
self
.
test_data
,
due
=
datetime
(
2014
,
5
,
16
,
14
,
30
),
display_name
=
"Overview"
)
self
.
old_style_course_id
=
self
.
course
.
id
.
to_deprecated_string
()
self
.
new_style_course_id
=
unicode
(
self
.
course
.
id
)
self
.
old_style_content_id
=
self
.
chapter
.
location
.
to_deprecated_string
()
self
.
new_style_content_id
=
unicode
(
self
.
chapter
.
location
)
self
.
course2
=
CourseFactory
.
create
(
org
=
'TEST'
,
start
=
datetime
(
2014
,
6
,
16
,
14
,
30
),
end
=
datetime
(
2015
,
1
,
16
)
)
self
.
chapter2
=
ItemFactory
.
create
(
category
=
"chapter"
,
parent_location
=
self
.
course2
.
location
,
data
=
self
.
test_data
,
due
=
datetime
(
2014
,
5
,
16
,
14
,
30
),
display_name
=
"Overview"
)
self
.
old_style_course_id2
=
self
.
course2
.
id
.
to_deprecated_string
()
self
.
new_style_course_id2
=
unicode
(
self
.
course2
.
id
)
self
.
old_style_content_id2
=
self
.
chapter2
.
location
.
to_deprecated_string
()
self
.
new_style_content_id2
=
unicode
(
self
.
chapter2
.
location
)
def
test_migrate_courseids_v2
(
self
):
def
test_migrate_courseids_v2
(
self
):
...
@@ -66,16 +39,16 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
...
@@ -66,16 +39,16 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
group
=
Group
.
objects
.
create
(
name
=
'Test Group'
)
group
=
Group
.
objects
.
create
(
name
=
'Test Group'
)
group_profile
=
api_models
.
GroupProfile
.
objects
.
create
(
group
=
group
)
group_profile
=
api_models
.
GroupProfile
.
objects
.
create
(
group
=
group
)
course_group
=
api_models
.
CourseGroupRelationship
.
objects
.
create
(
course_id
=
self
.
ol
d_style_course_id
,
group
=
group
)
course_group
=
api_models
.
CourseGroupRelationship
.
objects
.
create
(
course_id
=
self
.
ba
d_style_course_id
,
group
=
group
)
course_content_group
=
api_models
.
CourseContentGroupRelationship
.
objects
.
create
(
course_id
=
self
.
old_style_course_id
,
content_id
=
self
.
ol
d_style_content_id
,
group_profile
=
group_profile
)
course_content_group
=
api_models
.
CourseContentGroupRelationship
.
objects
.
create
(
course_id
=
self
.
bad_style_course_id
,
content_id
=
self
.
ba
d_style_content_id
,
group_profile
=
group_profile
)
course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
create
(
user
=
user
,
course_id
=
self
.
old_style_course_id
,
content_id
=
self
.
ol
d_style_content_id
)
course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
create
(
user
=
user
,
course_id
=
self
.
bad_style_course_id
,
content_id
=
self
.
ba
d_style_content_id
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
group2
=
Group
.
objects
.
create
(
name
=
'Test Group2'
)
group2
=
Group
.
objects
.
create
(
name
=
'Test Group2'
)
group_profile2
=
api_models
.
GroupProfile
.
objects
.
create
(
group
=
group2
)
group_profile2
=
api_models
.
GroupProfile
.
objects
.
create
(
group
=
group2
)
course_group2
=
api_models
.
CourseGroupRelationship
.
objects
.
create
(
course_id
=
self
.
new
_style_course_id2
,
group
=
group2
)
course_group2
=
api_models
.
CourseGroupRelationship
.
objects
.
create
(
course_id
=
self
.
bad
_style_course_id2
,
group
=
group2
)
course_content_group2
=
api_models
.
CourseContentGroupRelationship
.
objects
.
create
(
course_id
=
self
.
new_style_course_id2
,
content_id
=
self
.
new
_style_content_id2
,
group_profile
=
group_profile2
)
course_content_group2
=
api_models
.
CourseContentGroupRelationship
.
objects
.
create
(
course_id
=
self
.
bad_style_course_id2
,
content_id
=
self
.
bad
_style_content_id2
,
group_profile
=
group_profile2
)
course_module_completion2
=
api_models
.
CourseModuleCompletion
.
objects
.
create
(
user
=
user2
,
course_id
=
self
.
new_style_course_id2
,
content_id
=
self
.
new
_style_content_id2
)
course_module_completion2
=
api_models
.
CourseModuleCompletion
.
objects
.
create
(
user
=
user2
,
course_id
=
self
.
bad_style_course_id2
,
content_id
=
self
.
bad_style_content_id2
,
stage
=
self
.
bad
_style_content_id2
)
# Run the data migration
# Run the data migration
...
@@ -84,23 +57,24 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
...
@@ -84,23 +57,24 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
# Confirm that the data has been properly migrated
# Confirm that the data has been properly migrated
updated_course_group
=
api_models
.
CourseGroupRelationship
.
objects
.
get
(
id
=
course_group
.
id
)
updated_course_group
=
api_models
.
CourseGroupRelationship
.
objects
.
get
(
id
=
course_group
.
id
)
self
.
assertEqual
(
updated_course_group
.
course_id
,
self
.
ol
d_style_course_id
)
self
.
assertEqual
(
updated_course_group
.
course_id
,
self
.
goo
d_style_course_id
)
updated_course_group
=
api_models
.
CourseGroupRelationship
.
objects
.
get
(
id
=
course_group2
.
id
)
updated_course_group
=
api_models
.
CourseGroupRelationship
.
objects
.
get
(
id
=
course_group2
.
id
)
self
.
assertEqual
(
updated_course_group
.
course_id
,
self
.
ol
d_style_course_id2
)
self
.
assertEqual
(
updated_course_group
.
course_id
,
self
.
goo
d_style_course_id2
)
print
"Course Group Data Migration Passed"
print
"Course Group Data Migration Passed"
updated_course_content_group
=
api_models
.
CourseContentGroupRelationship
.
objects
.
get
(
id
=
course_content_group
.
id
)
updated_course_content_group
=
api_models
.
CourseContentGroupRelationship
.
objects
.
get
(
id
=
course_content_group
.
id
)
self
.
assertEqual
(
updated_course_content_group
.
course_id
,
self
.
ol
d_style_course_id
)
self
.
assertEqual
(
updated_course_content_group
.
course_id
,
self
.
goo
d_style_course_id
)
self
.
assertEqual
(
updated_course_content_group
.
content_id
,
self
.
ol
d_style_content_id
)
self
.
assertEqual
(
updated_course_content_group
.
content_id
,
self
.
goo
d_style_content_id
)
updated_course_content_group
=
api_models
.
CourseContentGroupRelationship
.
objects
.
get
(
id
=
course_content_group2
.
id
)
updated_course_content_group
=
api_models
.
CourseContentGroupRelationship
.
objects
.
get
(
id
=
course_content_group2
.
id
)
self
.
assertEqual
(
updated_course_content_group
.
course_id
,
self
.
ol
d_style_course_id2
)
self
.
assertEqual
(
updated_course_content_group
.
course_id
,
self
.
goo
d_style_course_id2
)
self
.
assertEqual
(
updated_course_content_group
.
content_id
,
self
.
ol
d_style_content_id2
)
self
.
assertEqual
(
updated_course_content_group
.
content_id
,
self
.
goo
d_style_content_id2
)
print
"Course Content Group Data Migration Passed"
print
"Course Content Group Data Migration Passed"
updated_course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
get
(
id
=
course_module_completion
.
id
)
updated_course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
get
(
id
=
course_module_completion
.
id
)
self
.
assertEqual
(
updated_course_module_completion
.
course_id
,
self
.
ol
d_style_course_id
)
self
.
assertEqual
(
updated_course_module_completion
.
course_id
,
self
.
goo
d_style_course_id
)
self
.
assertEqual
(
updated_course_module_completion
.
content_id
,
self
.
ol
d_style_content_id
)
self
.
assertEqual
(
updated_course_module_completion
.
content_id
,
self
.
goo
d_style_content_id
)
updated_course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
get
(
id
=
course_module_completion2
.
id
)
updated_course_module_completion
=
api_models
.
CourseModuleCompletion
.
objects
.
get
(
id
=
course_module_completion2
.
id
)
self
.
assertEqual
(
updated_course_module_completion
.
course_id
,
self
.
old_style_course_id2
)
self
.
assertEqual
(
updated_course_module_completion
.
course_id
,
self
.
good_style_course_id2
)
self
.
assertEqual
(
updated_course_module_completion
.
content_id
,
self
.
old_style_content_id2
)
self
.
assertEqual
(
updated_course_module_completion
.
content_id
,
self
.
good_style_content_id2
)
self
.
assertEqual
(
updated_course_module_completion
.
stage
,
self
.
good_style_content_id2
)
print
"Course Module Completion Data Migration Passed"
print
"Course Module Completion Data Migration Passed"
lms/djangoapps/gradebook/management/commands/migrate_gradebook_courseids_v2.py
View file @
6aeb6d47
...
@@ -11,6 +11,26 @@ from gradebook import models
...
@@ -11,6 +11,26 @@ from gradebook import models
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
_migrate_course_id
(
old_course_id
):
course_id
=
old_course_id
.
replace
(
"slashes:"
,
""
)
course_id
=
course_id
.
replace
(
"course-v1:"
,
""
)
course_id
=
course_id
.
replace
(
"+"
,
"/"
)
return
course_id
def
_migrate_content_id
(
old_content_id
):
if
"slashes:"
in
old_content_id
or
"course-v1:"
in
old_content_id
:
new_content_id
=
self
.
_migrate_course_id
(
old_content_id
)
else
:
content_id
=
old_content_id
.
replace
(
"location:"
,
""
)
content_components
=
content_id
.
split
(
'+'
)
new_content_id
=
"i4x:/"
for
x
in
range
(
0
,
len
(
content_components
)):
if
x
!=
2
:
new_content_id
=
"{}/{}"
.
format
(
new_content_id
,
content_components
[
x
])
return
new_content_id
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
"""
Migrates legacy course/content identifiers across several models to the new format
Migrates legacy course/content identifiers across several models to the new format
...
@@ -21,19 +41,16 @@ class Command(BaseCommand):
...
@@ -21,19 +41,16 @@ class Command(BaseCommand):
log
.
warning
(
'Migrating Student Gradebook Entries...'
)
log
.
warning
(
'Migrating Student Gradebook Entries...'
)
gradebook_entries
=
models
.
StudentGradebook
.
objects
.
all
()
gradebook_entries
=
models
.
StudentGradebook
.
objects
.
all
()
for
gbe
in
gradebook_entries
:
for
gbe
in
gradebook_entries
:
current_course_id
=
unicode
(
gbe
.
course_id
)
course_id
=
_migrate_course_id
(
unicode
(
gbe
.
course_id
))
oldstyle_course_id
=
current_course_id
.
replace
(
"slashes:"
,
""
)
print
course_id
oldstyle_course_id
=
oldstyle_course_id
.
replace
(
"+"
,
"/"
)
gbe
.
course_id
=
CourseKey
.
from_string
(
course_id
)
gbe
.
course_id
=
CourseKey
.
from_string
(
oldstyle_course_id
)
gbe
.
save
()
gbe
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Migrating Student Gradebook History Entries...'
)
log
.
warning
(
'Migrating Student Gradebook History Entries...'
)
history_entries
=
models
.
StudentGradebookHistory
.
objects
.
all
()
history_entries
=
models
.
StudentGradebookHistory
.
objects
.
all
()
for
he
in
history_entries
:
for
he
in
history_entries
:
current_course_id
=
unicode
(
he
.
course_id
)
course_id
=
_migrate_course_id
(
unicode
(
he
.
course_id
))
oldstyle_course_id
=
current_course_id
.
replace
(
"slashes:"
,
""
)
he
.
course_id
=
CourseKey
.
from_string
(
course_id
)
oldstyle_course_id
=
oldstyle_course_id
.
replace
(
"+"
,
"/"
)
he
.
course_id
=
oldstyle_course_id
he
.
save
()
he
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
lms/djangoapps/gradebook/management/commands/tests/test_migrate_gradebook_courseids_v2.py
View file @
6aeb6d47
...
@@ -20,43 +20,15 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
...
@@ -20,43 +20,15 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
(
self
.
bad_style_course_id
=
"slashes:old+style+id"
start
=
datetime
(
2014
,
6
,
16
,
14
,
30
),
self
.
good_style_course_id
=
"old/style/id"
end
=
datetime
(
2015
,
1
,
16
)
self
.
bad_style_content_id
=
"location:old+style+id+chapter+1234567890"
)
self
.
good_style_content_id
=
"i4x://old/style/chapter/1234567890"
self
.
test_data
=
'<html>{}</html>'
.
format
(
str
(
uuid
.
uuid4
()))
self
.
chapter
=
ItemFactory
.
create
(
category
=
"chapter"
,
parent_location
=
self
.
course
.
location
,
data
=
self
.
test_data
,
due
=
datetime
(
2014
,
5
,
16
,
14
,
30
),
display_name
=
"Overview"
)
self
.
old_style_course_id
=
self
.
course
.
id
.
to_deprecated_string
()
self
.
new_style_course_id
=
unicode
(
self
.
course
.
id
)
self
.
old_style_content_id
=
self
.
chapter
.
location
.
to_deprecated_string
()
self
.
new_style_content_id
=
unicode
(
self
.
chapter
.
location
)
self
.
course2
=
CourseFactory
.
create
(
org
=
'TEST'
,
start
=
datetime
(
2014
,
6
,
16
,
14
,
30
),
end
=
datetime
(
2015
,
1
,
16
)
)
self
.
chapter2
=
ItemFactory
.
create
(
category
=
"chapter"
,
parent_location
=
self
.
course2
.
location
,
data
=
self
.
test_data
,
due
=
datetime
(
2014
,
5
,
16
,
14
,
30
),
display_name
=
"Overview"
)
self
.
old_style_course_id2
=
self
.
course2
.
id
.
to_deprecated_string
()
self
.
new_style_course_id2
=
unicode
(
self
.
course2
.
id
)
self
.
old_style_content_id2
=
self
.
chapter2
.
location
.
to_deprecated_string
()
self
.
new_style_content_id2
=
unicode
(
self
.
chapter2
.
location
)
self
.
bad_style_course_id2
=
"course-v1:old2+style2+id2"
self
.
good_style_course_id2
=
"old2/style2/id2"
self
.
bad_style_content_id2
=
"location:old2+style2+id2+chapter2+1234567890"
self
.
good_style_content_id2
=
"i4x://old2/style2/chapter2/1234567890"
def
test_migrate_courseids
(
self
):
def
test_migrate_courseids
(
self
):
"""
"""
...
@@ -64,10 +36,10 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
...
@@ -64,10 +36,10 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
"""
"""
# Set up the data to be migrated
# Set up the data to be migrated
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
gradebook_entry
=
gradebook_models
.
StudentGradebook
.
objects
.
create
(
user
=
user
,
course_id
=
self
.
new
_style_course_id
,
grade
=
0.85
,
proforma_grade
=
0.74
)
gradebook_entry
=
gradebook_models
.
StudentGradebook
.
objects
.
create
(
user
=
user
,
course_id
=
self
.
bad
_style_course_id
,
grade
=
0.85
,
proforma_grade
=
0.74
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
gradebook_entry2
=
gradebook_models
.
StudentGradebook
.
objects
.
create
(
user
=
user2
,
course_id
=
self
.
new
_style_course_id2
,
grade
=
0.95
,
proforma_grade
=
0.64
)
gradebook_entry2
=
gradebook_models
.
StudentGradebook
.
objects
.
create
(
user
=
user2
,
course_id
=
self
.
bad
_style_course_id2
,
grade
=
0.95
,
proforma_grade
=
0.64
)
# Run the data migration
# Run the data migration
...
@@ -77,13 +49,13 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
...
@@ -77,13 +49,13 @@ class MigrateCourseIdsTests(ModuleStoreTestCase):
# Confirm that the data has been properly migrated
# Confirm that the data has been properly migrated
updated_gradebook_entries
=
gradebook_models
.
StudentGradebook
.
objects
.
get
(
id
=
gradebook_entry
.
id
)
updated_gradebook_entries
=
gradebook_models
.
StudentGradebook
.
objects
.
get
(
id
=
gradebook_entry
.
id
)
updated_gradebook_entry
=
gradebook_models
.
StudentGradebook
.
objects
.
get
(
id
=
gradebook_entry2
.
id
)
updated_gradebook_entry
=
gradebook_models
.
StudentGradebook
.
objects
.
get
(
id
=
gradebook_entry2
.
id
)
self
.
assertEqual
(
unicode
(
updated_gradebook_entry
.
course_id
),
self
.
ol
d_style_course_id2
)
self
.
assertEqual
(
unicode
(
updated_gradebook_entry
.
course_id
),
self
.
goo
d_style_course_id2
)
print
"Student Gradebook Data Migration Passed"
print
"Student Gradebook Data Migration Passed"
updated_history_entries
=
gradebook_models
.
StudentGradebookHistory
.
objects
.
filter
(
user
=
user
.
id
)
updated_history_entries
=
gradebook_models
.
StudentGradebookHistory
.
objects
.
filter
(
user
=
user
.
id
)
for
entry
in
updated_history_entries
:
for
entry
in
updated_history_entries
:
self
.
assertEqual
(
unicode
(
entry
.
course_id
),
self
.
ol
d_style_course_id
)
self
.
assertEqual
(
unicode
(
entry
.
course_id
),
self
.
goo
d_style_course_id
)
updated_history_entries
=
gradebook_models
.
StudentGradebookHistory
.
objects
.
filter
(
user
=
user2
.
id
)
updated_history_entries
=
gradebook_models
.
StudentGradebookHistory
.
objects
.
filter
(
user
=
user2
.
id
)
for
entry
in
updated_history_entries
:
for
entry
in
updated_history_entries
:
self
.
assertEqual
(
unicode
(
entry
.
course_id
),
self
.
ol
d_style_course_id2
)
self
.
assertEqual
(
unicode
(
entry
.
course_id
),
self
.
goo
d_style_course_id2
)
print
"Student Gradebook History Data Migration Passed"
print
"Student Gradebook History Data Migration Passed"
lms/djangoapps/projects/management/commands/migrate_project_courseids_v2.py
View file @
6aeb6d47
...
@@ -9,6 +9,27 @@ from projects.models import Project, WorkgroupReview, WorkgroupPeerReview, Workg
...
@@ -9,6 +9,27 @@ from projects.models import Project, WorkgroupReview, WorkgroupPeerReview, Workg
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
_migrate_course_id
(
old_course_id
):
course_id
=
old_course_id
.
replace
(
"slashes:"
,
""
)
course_id
=
course_id
.
replace
(
"course-v1:"
,
""
)
course_id
=
course_id
.
replace
(
"+"
,
"/"
)
return
course_id
def
_migrate_content_id
(
old_content_id
):
if
"slashes:"
in
old_content_id
or
"course-v1:"
in
old_content_id
:
new_content_id
=
self
.
_migrate_course_id
(
old_content_id
)
else
:
content_id
=
old_content_id
.
replace
(
"location:"
,
""
)
content_components
=
content_id
.
split
(
'+'
)
new_content_id
=
"i4x:/"
for
x
in
range
(
0
,
len
(
content_components
)):
if
x
!=
2
:
new_content_id
=
"{}/{}"
.
format
(
new_content_id
,
content_components
[
x
])
return
new_content_id
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
"""
Migrates legacy course/content identifiers across several models to the new format
Migrates legacy course/content identifiers across several models to the new format
...
@@ -19,15 +40,8 @@ class Command(BaseCommand):
...
@@ -19,15 +40,8 @@ class Command(BaseCommand):
log
.
warning
(
'Migrating Projects...'
)
log
.
warning
(
'Migrating Projects...'
)
projects
=
Project
.
objects
.
all
()
projects
=
Project
.
objects
.
all
()
for
project
in
projects
:
for
project
in
projects
:
current_course_id
=
project
.
course_id
project
.
course_id
=
_migrate_course_id
(
project
.
course_id
)
oldstyle_course_id
=
current_course_id
.
replace
(
"slashes:"
,
""
)
project
.
content_id
=
_migrate_content_id
(
project
.
content_id
)
oldstyle_course_id
=
oldstyle_course_id
.
replace
(
"+"
,
"/"
)
project
.
course_id
=
oldstyle_course_id
current_content_id
=
project
.
content_id
oldstyle_content_id
=
current_content_id
.
replace
(
"slashes:"
,
""
)
oldstyle_content_id
=
oldstyle_content_id
.
replace
(
"+"
,
"/"
)
project
.
content_id
=
oldstyle_content_id
project
.
save
()
project
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
...
@@ -35,21 +49,15 @@ class Command(BaseCommand):
...
@@ -35,21 +49,15 @@ class Command(BaseCommand):
workgroup_reviews
=
WorkgroupReview
.
objects
.
all
()
workgroup_reviews
=
WorkgroupReview
.
objects
.
all
()
for
wr
in
workgroup_reviews
:
for
wr
in
workgroup_reviews
:
if
wr
.
content_id
is
not
None
:
if
wr
.
content_id
is
not
None
:
current_content_id
=
wr
.
content_id
wr
.
content_id
=
_migrate_content_id
(
wr
.
content_id
)
oldstyle_content_id
=
current_content_id
.
replace
(
"slashes:"
,
""
)
oldstyle_content_id
=
oldstyle_content_id
.
replace
(
"+"
,
"/"
)
wr
.
content_id
=
oldstyle_content_id
wr
.
save
()
wr
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Migrating Workgroup Peer Reviews...'
)
log
.
warning
(
'Migrating Workgroup Peer Reviews...'
)
workgroup_peer_reviews
=
WorkgroupPeerReview
.
objects
.
all
()
workgroup_peer_reviews
=
WorkgroupPeerReview
.
objects
.
all
()
for
wpr
in
workgroup_reviews
:
for
wpr
in
workgroup_
peer_
reviews
:
if
wpr
.
content_id
is
not
None
:
if
wpr
.
content_id
is
not
None
:
current_content_id
=
wpr
.
content_id
wpr
.
content_id
=
_migrate_content_id
(
wpr
.
content_id
)
oldstyle_content_id
=
current_content_id
.
replace
(
"slashes:"
,
""
)
oldstyle_content_id
=
oldstyle_content_id
.
replace
(
"+"
,
"/"
)
wpr
.
content_id
=
oldstyle_content_id
wpr
.
save
()
wpr
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
...
@@ -57,9 +65,6 @@ class Command(BaseCommand):
...
@@ -57,9 +65,6 @@ class Command(BaseCommand):
workgroup_submission_reviews
=
WorkgroupSubmissionReview
.
objects
.
all
()
workgroup_submission_reviews
=
WorkgroupSubmissionReview
.
objects
.
all
()
for
wsr
in
workgroup_submission_reviews
:
for
wsr
in
workgroup_submission_reviews
:
if
wsr
.
content_id
is
not
None
:
if
wsr
.
content_id
is
not
None
:
current_content_id
=
wsr
.
content_id
wsr
.
content_id
=
_migrate_content_id
(
wsr
.
content_id
)
oldstyle_content_id
=
current_content_id
.
replace
(
"slashes:"
,
""
)
oldstyle_content_id
=
oldstyle_content_id
.
replace
(
"+"
,
"/"
)
wsr
.
content_id
=
oldstyle_content_id
wsr
.
save
()
wsr
.
save
()
log
.
warning
(
'Complete!'
)
log
.
warning
(
'Complete!'
)
lms/djangoapps/projects/management/commands/tests/test_migrate_project_courseids_v2.py
View file @
6aeb6d47
...
@@ -20,42 +20,15 @@ class MigrateCourseIdsTests(TestCase):
...
@@ -20,42 +20,15 @@ class MigrateCourseIdsTests(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
(
self
.
bad_style_course_id
=
"slashes:old+style+id"
start
=
datetime
(
2014
,
6
,
16
,
14
,
30
),
self
.
good_style_course_id
=
"old/style/id"
end
=
datetime
(
2015
,
1
,
16
)
self
.
bad_style_content_id
=
"location:old+style+id+chapter+1234567890"
)
self
.
good_style_content_id
=
"i4x://old/style/chapter/1234567890"
self
.
test_data
=
'<html>{}</html>'
.
format
(
str
(
uuid
.
uuid4
()))
self
.
bad_style_course_id2
=
"course-v1:old2+style2+id2"
self
.
chapter
=
ItemFactory
.
create
(
self
.
good_style_course_id2
=
"old2/style2/id2"
category
=
"chapter"
,
self
.
bad_style_content_id2
=
"location:old2+style2+id2+chapter2+1234567890"
parent_location
=
self
.
course
.
location
,
self
.
good_style_content_id2
=
"i4x://old2/style2/chapter2/1234567890"
data
=
self
.
test_data
,
due
=
datetime
(
2014
,
5
,
16
,
14
,
30
),
display_name
=
"Overview"
)
self
.
old_style_course_id
=
self
.
course
.
id
.
to_deprecated_string
()
self
.
new_style_course_id
=
unicode
(
self
.
course
.
id
)
self
.
old_style_content_id
=
self
.
chapter
.
location
.
to_deprecated_string
()
self
.
new_style_content_id
=
unicode
(
self
.
chapter
.
location
)
self
.
course2
=
CourseFactory
.
create
(
org
=
'TEST'
,
start
=
datetime
(
2014
,
6
,
16
,
14
,
30
),
end
=
datetime
(
2015
,
1
,
16
)
)
self
.
chapter2
=
ItemFactory
.
create
(
category
=
"chapter"
,
parent_location
=
self
.
course2
.
location
,
data
=
self
.
test_data
,
due
=
datetime
(
2014
,
5
,
16
,
14
,
30
),
display_name
=
"Overview"
)
self
.
old_style_course_id2
=
self
.
course2
.
id
.
to_deprecated_string
()
self
.
new_style_course_id2
=
unicode
(
self
.
course2
.
id
)
self
.
old_style_content_id2
=
self
.
chapter2
.
location
.
to_deprecated_string
()
self
.
new_style_content_id2
=
unicode
(
self
.
chapter2
.
location
)
def
test_migrate_project_courseids_v2
(
self
):
def
test_migrate_project_courseids_v2
(
self
):
...
@@ -65,21 +38,21 @@ class MigrateCourseIdsTests(TestCase):
...
@@ -65,21 +38,21 @@ class MigrateCourseIdsTests(TestCase):
# Set up the data to be migrated
# Set up the data to be migrated
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
user
=
User
.
objects
.
create
(
email
=
'testuser@edx.org'
,
username
=
'testuser'
,
password
=
'testpassword'
,
is_active
=
True
)
reviewer
=
User
.
objects
.
create
(
email
=
'testreviewer@edx.org'
,
username
=
'testreviewer'
,
password
=
'testpassword'
,
is_active
=
True
)
reviewer
=
User
.
objects
.
create
(
email
=
'testreviewer@edx.org'
,
username
=
'testreviewer'
,
password
=
'testpassword'
,
is_active
=
True
)
project
=
Project
.
objects
.
create
(
course_id
=
self
.
old_style_course_id
,
content_id
=
self
.
ol
d_style_content_id
)
project
=
Project
.
objects
.
create
(
course_id
=
self
.
bad_style_course_id
,
content_id
=
self
.
ba
d_style_content_id
)
workgroup
=
Workgroup
.
objects
.
create
(
name
=
'Test Workgroup'
,
project
=
project
)
workgroup
=
Workgroup
.
objects
.
create
(
name
=
'Test Workgroup'
,
project
=
project
)
workgroup_review
=
WorkgroupReview
.
objects
.
create
(
workgroup
=
workgroup
,
content_id
=
self
.
ol
d_style_content_id
)
workgroup_review
=
WorkgroupReview
.
objects
.
create
(
workgroup
=
workgroup
,
content_id
=
self
.
ba
d_style_content_id
)
workgroup_peer_review
=
WorkgroupPeerReview
.
objects
.
create
(
workgroup
=
workgroup
,
user
=
user
,
reviewer
=
reviewer
,
question
=
"Question?"
,
answer
=
"Answer!"
,
content_id
=
self
.
new
_style_content_id
)
workgroup_peer_review
=
WorkgroupPeerReview
.
objects
.
create
(
workgroup
=
workgroup
,
user
=
user
,
reviewer
=
reviewer
,
question
=
"Question?"
,
answer
=
"Answer!"
,
content_id
=
self
.
bad
_style_content_id
)
workgroup_submission
=
WorkgroupSubmission
.
objects
.
create
(
workgroup
=
workgroup
,
user
=
user
)
workgroup_submission
=
WorkgroupSubmission
.
objects
.
create
(
workgroup
=
workgroup
,
user
=
user
)
workgroup_submission_review
=
WorkgroupSubmissionReview
.
objects
.
create
(
submission
=
workgroup_submission
,
content_id
=
self
.
ol
d_style_content_id
)
workgroup_submission_review
=
WorkgroupSubmissionReview
.
objects
.
create
(
submission
=
workgroup_submission
,
content_id
=
self
.
ba
d_style_content_id
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
user2
=
User
.
objects
.
create
(
email
=
'testuser2@edx.org'
,
username
=
'testuser2'
,
password
=
'testpassword2'
,
is_active
=
True
)
reviewer2
=
User
.
objects
.
create
(
email
=
'testreviewer2@edx.org'
,
username
=
'testreviewer2'
,
password
=
'testpassword'
,
is_active
=
True
)
reviewer2
=
User
.
objects
.
create
(
email
=
'testreviewer2@edx.org'
,
username
=
'testreviewer2'
,
password
=
'testpassword'
,
is_active
=
True
)
project2
=
Project
.
objects
.
create
(
course_id
=
self
.
new_style_course_id2
,
content_id
=
self
.
new
_style_content_id2
)
project2
=
Project
.
objects
.
create
(
course_id
=
self
.
bad_style_course_id2
,
content_id
=
self
.
bad
_style_content_id2
)
workgroup2
=
Workgroup
.
objects
.
create
(
name
=
'Test Workgroup2'
,
project
=
project2
)
workgroup2
=
Workgroup
.
objects
.
create
(
name
=
'Test Workgroup2'
,
project
=
project2
)
workgroup_review2
=
WorkgroupReview
.
objects
.
create
(
workgroup
=
workgroup2
,
content_id
=
self
.
new
_style_content_id2
)
workgroup_review2
=
WorkgroupReview
.
objects
.
create
(
workgroup
=
workgroup2
,
content_id
=
self
.
bad
_style_content_id2
)
workgroup_peer_review2
=
WorkgroupPeerReview
.
objects
.
create
(
workgroup
=
workgroup2
,
user
=
user2
,
reviewer
=
reviewer2
,
question
=
"Question?"
,
answer
=
"Answer!"
,
content_id
=
self
.
new
_style_content_id2
)
workgroup_peer_review2
=
WorkgroupPeerReview
.
objects
.
create
(
workgroup
=
workgroup2
,
user
=
user2
,
reviewer
=
reviewer2
,
question
=
"Question?"
,
answer
=
"Answer!"
,
content_id
=
self
.
bad
_style_content_id2
)
workgroup_submission2
=
WorkgroupSubmission
.
objects
.
create
(
workgroup
=
workgroup2
,
user
=
user2
)
workgroup_submission2
=
WorkgroupSubmission
.
objects
.
create
(
workgroup
=
workgroup2
,
user
=
user2
)
workgroup_submission_review2
=
WorkgroupSubmissionReview
.
objects
.
create
(
submission
=
workgroup_submission2
,
content_id
=
self
.
new
_style_content_id2
)
workgroup_submission_review2
=
WorkgroupSubmissionReview
.
objects
.
create
(
submission
=
workgroup_submission2
,
content_id
=
self
.
bad
_style_content_id2
)
# Run the data migration
# Run the data migration
...
@@ -88,27 +61,27 @@ class MigrateCourseIdsTests(TestCase):
...
@@ -88,27 +61,27 @@ class MigrateCourseIdsTests(TestCase):
# Confirm that the data has been properly migrated
# Confirm that the data has been properly migrated
updated_project
=
Project
.
objects
.
get
(
id
=
project
.
id
)
updated_project
=
Project
.
objects
.
get
(
id
=
project
.
id
)
self
.
assertEqual
(
updated_project
.
course_id
,
self
.
ol
d_style_course_id
)
self
.
assertEqual
(
updated_project
.
course_id
,
self
.
goo
d_style_course_id
)
self
.
assertEqual
(
updated_project
.
content_id
,
self
.
ol
d_style_content_id
)
self
.
assertEqual
(
updated_project
.
content_id
,
self
.
goo
d_style_content_id
)
updated_project
=
Project
.
objects
.
get
(
id
=
project2
.
id
)
updated_project
=
Project
.
objects
.
get
(
id
=
project2
.
id
)
self
.
assertEqual
(
updated_project
.
course_id
,
self
.
ol
d_style_course_id2
)
self
.
assertEqual
(
updated_project
.
course_id
,
self
.
goo
d_style_course_id2
)
self
.
assertEqual
(
updated_project
.
content_id
,
self
.
ol
d_style_content_id2
)
self
.
assertEqual
(
updated_project
.
content_id
,
self
.
goo
d_style_content_id2
)
print
"Project Data Migration Passed"
print
"Project Data Migration Passed"
updated_workgroup_review
=
WorkgroupReview
.
objects
.
get
(
id
=
workgroup_review
.
id
)
updated_workgroup_review
=
WorkgroupReview
.
objects
.
get
(
id
=
workgroup_review
.
id
)
self
.
assertEqual
(
updated_workgroup_review
.
content_id
,
self
.
ol
d_style_content_id
)
self
.
assertEqual
(
updated_workgroup_review
.
content_id
,
self
.
goo
d_style_content_id
)
updated_workgroup_review
=
WorkgroupReview
.
objects
.
get
(
id
=
workgroup_review2
.
id
)
updated_workgroup_review
=
WorkgroupReview
.
objects
.
get
(
id
=
workgroup_review2
.
id
)
self
.
assertEqual
(
updated_workgroup_review
.
content_id
,
self
.
ol
d_style_content_id2
)
self
.
assertEqual
(
updated_workgroup_review
.
content_id
,
self
.
goo
d_style_content_id2
)
print
"Workgroup Review Data Migration Passed"
print
"Workgroup Review Data Migration Passed"
updated_workgroup_peer_review
=
WorkgroupPeerReview
.
objects
.
get
(
id
=
workgroup_peer_review
.
id
)
updated_workgroup_peer_review
=
WorkgroupPeerReview
.
objects
.
get
(
id
=
workgroup_peer_review
.
id
)
self
.
assertEqual
(
updated_workgroup_peer_review
.
content_id
,
self
.
ol
d_style_content_id
)
self
.
assertEqual
(
updated_workgroup_peer_review
.
content_id
,
self
.
goo
d_style_content_id
)
updated_workgroup_peer_review
=
WorkgroupPeerReview
.
objects
.
get
(
id
=
workgroup_peer_review2
.
id
)
updated_workgroup_peer_review
=
WorkgroupPeerReview
.
objects
.
get
(
id
=
workgroup_peer_review2
.
id
)
self
.
assertEqual
(
updated_workgroup_peer_review
.
content_id
,
self
.
ol
d_style_content_id2
)
self
.
assertEqual
(
updated_workgroup_peer_review
.
content_id
,
self
.
goo
d_style_content_id2
)
print
"Workgroup Peer Review Data Migration Passed"
print
"Workgroup Peer Review Data Migration Passed"
updated_workgroup_submission_review
=
WorkgroupSubmissionReview
.
objects
.
get
(
id
=
workgroup_submission_review
.
id
)
updated_workgroup_submission_review
=
WorkgroupSubmissionReview
.
objects
.
get
(
id
=
workgroup_submission_review
.
id
)
self
.
assertEqual
(
updated_workgroup_submission_review
.
content_id
,
self
.
ol
d_style_content_id
)
self
.
assertEqual
(
updated_workgroup_submission_review
.
content_id
,
self
.
goo
d_style_content_id
)
updated_workgroup_submission_review
=
WorkgroupSubmissionReview
.
objects
.
get
(
id
=
workgroup_submission_review2
.
id
)
updated_workgroup_submission_review
=
WorkgroupSubmissionReview
.
objects
.
get
(
id
=
workgroup_submission_review2
.
id
)
self
.
assertEqual
(
updated_workgroup_submission_review
.
content_id
,
self
.
ol
d_style_content_id2
)
self
.
assertEqual
(
updated_workgroup_submission_review
.
content_id
,
self
.
goo
d_style_content_id2
)
print
"Workgroup Submission Review Data Migration Passed"
print
"Workgroup Submission Review Data Migration Passed"
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