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
4133155a
Commit
4133155a
authored
Dec 08, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update CourseDetails support for Course About information
parent
bb53c03e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
15 deletions
+21
-15
openedx/core/djangoapps/models/course_details.py
+6
-10
openedx/core/djangoapps/models/tests/test_course_details.py
+15
-5
No files found.
openedx/core/djangoapps/models/course_details.py
View file @
4133155a
...
...
@@ -60,10 +60,13 @@ class CourseDetails(object):
self
.
self_paced
=
None
@classmethod
def
_
fetch_about_attribute
(
cls
,
course_key
,
attribute
):
def
fetch_about_attribute
(
cls
,
course_key
,
attribute
):
"""
Retrieve an attribute from a course's "about" info
"""
if
attribute
not
in
ABOUT_ATTRIBUTES
+
[
'video'
]:
raise
ValueError
(
"'{0}' is not a valid course about attribute."
.
format
(
attribute
))
usage_key
=
course_key
.
make_usage_key
(
'about'
,
attribute
)
try
:
value
=
modulestore
()
.
get_item
(
usage_key
)
.
data
...
...
@@ -96,7 +99,7 @@ class CourseDetails(object):
course_details
.
intro_video
=
cls
.
fetch_youtube_video_id
(
course_key
)
for
attribute
in
ABOUT_ATTRIBUTES
:
value
=
cls
.
_
fetch_about_attribute
(
course_key
,
attribute
)
value
=
cls
.
fetch_about_attribute
(
course_key
,
attribute
)
if
value
is
not
None
:
setattr
(
course_details
,
attribute
,
value
)
...
...
@@ -107,7 +110,7 @@ class CourseDetails(object):
"""
Returns the course about video ID.
"""
raw_video
=
cls
.
_
fetch_about_attribute
(
course_key
,
'video'
)
raw_video
=
cls
.
fetch_about_attribute
(
course_key
,
'video'
)
if
raw_video
:
return
cls
.
parse_video_tag
(
raw_video
)
...
...
@@ -121,13 +124,6 @@ class CourseDetails(object):
return
"http://www.youtube.com/watch?v={0}"
.
format
(
video_id
)
@classmethod
def
fetch_effort
(
cls
,
course_key
):
"""
Returns the hours per week of effort for the course.
"""
return
cls
.
_fetch_about_attribute
(
course_key
,
'effort'
)
@classmethod
def
update_about_item
(
cls
,
course
,
about_key
,
data
,
user_id
,
store
=
None
):
"""
Update the about item with the new data blob. If data is None,
...
...
openedx/core/djangoapps/models/tests/test_course_details.py
View file @
4133155a
...
...
@@ -3,6 +3,7 @@ Tests for CourseDetails
"""
import
datetime
import
ddt
from
django.utils.timezone
import
UTC
from
xmodule.modulestore
import
ModuleStoreEnum
...
...
@@ -10,9 +11,10 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
openedx.core.djangoapps.self_paced.models
import
SelfPacedConfiguration
from
openedx.core.djangoapps.models.course_details
import
CourseDetails
from
openedx.core.djangoapps.models.course_details
import
CourseDetails
,
ABOUT_ATTRIBUTES
@ddt.ddt
class
CourseDetailsTestCase
(
ModuleStoreTestCase
):
"""
Tests the first course settings page (course dates, overview, etc.).
...
...
@@ -111,11 +113,19 @@ class CourseDetailsTestCase(ModuleStoreTestCase):
)
self
.
assertFalse
(
updated_details
.
self_paced
)
def
test_fetch_effort
(
self
):
effort_value
=
'test_hours_of_effort'
@ddt.data
(
*
ABOUT_ATTRIBUTES
)
def
test_fetch_about_attribute
(
self
,
attribute_name
):
attribute_value
=
'test_value'
with
self
.
store
.
branch_setting
(
ModuleStoreEnum
.
Branch
.
draft_preferred
,
self
.
course
.
id
):
CourseDetails
.
update_about_item
(
self
.
course
,
'effort'
,
effort_value
,
self
.
user
.
id
)
self
.
assertEqual
(
CourseDetails
.
fetch_effort
(
self
.
course
.
id
),
effort_value
)
CourseDetails
.
update_about_item
(
self
.
course
,
attribute_name
,
attribute_value
,
self
.
user
.
id
)
self
.
assertEqual
(
CourseDetails
.
fetch_about_attribute
(
self
.
course
.
id
,
attribute_name
),
attribute_value
)
def
test_fetch_about_attribute_error
(
self
):
attribute_name
=
'not_an_about_attribute'
with
self
.
store
.
branch_setting
(
ModuleStoreEnum
.
Branch
.
draft_preferred
,
self
.
course
.
id
):
CourseDetails
.
update_about_item
(
self
.
course
,
attribute_name
,
'test_value'
,
self
.
user
.
id
)
with
self
.
assertRaises
(
ValueError
):
CourseDetails
.
fetch_about_attribute
(
self
.
course
.
id
,
attribute_name
)
def
test_fetch_video
(
self
):
video_value
=
'test_video_id'
...
...
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