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
d2b4a6ea
Commit
d2b4a6ea
authored
Dec 05, 2014
by
Sarina Canelake
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5874 from stvstnfrd/up/course/about
Create helper function to remove duplicate code
parents
50152abb
04b97a3a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
30 deletions
+30
-30
cms/djangoapps/models/settings/course_details.py
+30
-30
No files found.
cms/djangoapps/models/settings/course_details.py
View file @
d2b4a6ea
...
@@ -11,6 +11,16 @@ from models.settings import course_grading
...
@@ -11,6 +11,16 @@ from models.settings import course_grading
from
xmodule.fields
import
Date
from
xmodule.fields
import
Date
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
# This list represents the attribute keys for a course's 'about' info.
# Note: The 'video' attribute is intentionally excluded as it must be
# handled separately; its value maps to an alternate key name.
ABOUT_ATTRIBUTES
=
[
'syllabus'
,
'short_description'
,
'overview'
,
'effort'
,
]
class
CourseDetails
(
object
):
class
CourseDetails
(
object
):
def
__init__
(
self
,
org
,
course_id
,
run
):
def
__init__
(
self
,
org
,
course_id
,
run
):
...
@@ -31,6 +41,18 @@ class CourseDetails(object):
...
@@ -31,6 +41,18 @@ class CourseDetails(object):
self
.
course_image_asset_path
=
""
# URL of the course image
self
.
course_image_asset_path
=
""
# URL of the course image
@classmethod
@classmethod
def
_fetch_about_attribute
(
cls
,
course_key
,
attribute
):
"""
Retrieve an attribute from a course's "about" info
"""
usage_key
=
course_key
.
make_usage_key
(
'about'
,
attribute
)
try
:
value
=
modulestore
()
.
get_item
(
usage_key
)
.
data
except
ItemNotFoundError
:
value
=
None
return
value
@classmethod
def
fetch
(
cls
,
course_key
):
def
fetch
(
cls
,
course_key
):
"""
"""
Fetch the course details for the given course from persistence and return a CourseDetails model.
Fetch the course details for the given course from persistence and return a CourseDetails model.
...
@@ -45,36 +67,14 @@ class CourseDetails(object):
...
@@ -45,36 +67,14 @@ class CourseDetails(object):
course_details
.
course_image_name
=
descriptor
.
course_image
course_details
.
course_image_name
=
descriptor
.
course_image
course_details
.
course_image_asset_path
=
course_image_url
(
descriptor
)
course_details
.
course_image_asset_path
=
course_image_url
(
descriptor
)
temploc
=
course_key
.
make_usage_key
(
'about'
,
'syllabus'
)
for
attribute
in
ABOUT_ATTRIBUTES
:
try
:
value
=
cls
.
_fetch_about_attribute
(
course_key
,
attribute
)
course_details
.
syllabus
=
modulestore
()
.
get_item
(
temploc
)
.
data
if
value
is
not
None
:
except
ItemNotFoundError
:
setattr
(
course_details
,
attribute
,
value
)
pass
temploc
=
course_key
.
make_usage_key
(
'about'
,
'short_description'
)
try
:
course_details
.
short_description
=
modulestore
()
.
get_item
(
temploc
)
.
data
except
ItemNotFoundError
:
pass
temploc
=
course_key
.
make_usage_key
(
'about'
,
'overview'
)
try
:
course_details
.
overview
=
modulestore
()
.
get_item
(
temploc
)
.
data
except
ItemNotFoundError
:
pass
temploc
=
course_key
.
make_usage_key
(
'about'
,
'effort'
)
raw_video
=
cls
.
_fetch_about_attribute
(
course_key
,
'video'
)
try
:
if
raw_video
:
course_details
.
effort
=
modulestore
()
.
get_item
(
temploc
)
.
data
except
ItemNotFoundError
:
pass
temploc
=
course_key
.
make_usage_key
(
'about'
,
'video'
)
try
:
raw_video
=
modulestore
()
.
get_item
(
temploc
)
.
data
course_details
.
intro_video
=
CourseDetails
.
parse_video_tag
(
raw_video
)
course_details
.
intro_video
=
CourseDetails
.
parse_video_tag
(
raw_video
)
except
ItemNotFoundError
:
pass
return
course_details
return
course_details
...
@@ -160,8 +160,8 @@ class CourseDetails(object):
...
@@ -160,8 +160,8 @@ class CourseDetails(object):
# NOTE: below auto writes to the db w/o verifying that any of the fields actually changed
# NOTE: below auto writes to the db w/o verifying that any of the fields actually changed
# to make faster, could compare against db or could have client send over a list of which fields changed.
# to make faster, could compare against db or could have client send over a list of which fields changed.
for
a
bout_type
in
[
'syllabus'
,
'overview'
,
'effort'
,
'short_description'
]
:
for
a
ttribute
in
ABOUT_ATTRIBUTES
:
cls
.
update_about_item
(
course_key
,
a
bout_type
,
jsondict
[
about_typ
e
],
descriptor
,
user
)
cls
.
update_about_item
(
course_key
,
a
ttribute
,
jsondict
[
attribut
e
],
descriptor
,
user
)
recomposed_video_tag
=
CourseDetails
.
recompose_video_tag
(
jsondict
[
'intro_video'
])
recomposed_video_tag
=
CourseDetails
.
recompose_video_tag
(
jsondict
[
'intro_video'
])
cls
.
update_about_item
(
course_key
,
'video'
,
recomposed_video_tag
,
descriptor
,
user
)
cls
.
update_about_item
(
course_key
,
'video'
,
recomposed_video_tag
,
descriptor
,
user
)
...
...
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