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
759898b8
Commit
759898b8
authored
Apr 17, 2014
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
7c581d06
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
lms/djangoapps/api_manager/courses_urls.py
+1
-0
lms/djangoapps/api_manager/courses_views.py
+68
-0
No files found.
lms/djangoapps/api_manager/courses_urls.py
View file @
759898b8
...
...
@@ -12,5 +12,6 @@ urlpatterns = patterns(
url
(
r'^(?P<course_id>[a-zA-Z0-9/_:]+)/modules/*$'
,
'modules_list'
),
url
(
r'^(?P<course_id>[a-zA-Z0-9/_:]+)/groups/(?P<group_id>[0-9]+)$'
,
'courses_groups_detail'
),
url
(
r'^(?P<course_id>[a-zA-Z0-9/_:]+)/groups/*$'
,
'courses_groups_list'
),
url
(
r'^(?P<course_id>[a-zA-Z0-9/_:]+)/about$'
,
'course_about'
),
url
(
r'^(?P<course_id>[a-zA-Z0-9/_:]+)$'
,
'courses_detail'
),
)
lms/djangoapps/api_manager/courses_views.py
View file @
759898b8
...
...
@@ -2,6 +2,8 @@
from
django.contrib.auth.models
import
Group
from
django.core.exceptions
import
ObjectDoesNotExist
from
lxml
import
etree
from
StringIO
import
StringIO
from
rest_framework
import
status
from
rest_framework.decorators
import
api_view
,
permission_classes
...
...
@@ -12,6 +14,7 @@ from api_manager.models import CourseGroupRelationship
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
courseware.courses
import
get_course_about_section
def
_generate_base_uri
(
request
):
"""
...
...
@@ -295,3 +298,68 @@ def courses_groups_detail(request, course_id, group_id):
except
ObjectDoesNotExist
:
pass
return
Response
({},
status
=
status
.
HTTP_204_NO_CONTENT
)
def
_parse_about_html
(
html
):
"""
Helper method to break up the course about HTML into components
"""
result
=
{}
parser
=
etree
.
HTMLParser
()
tree
=
etree
.
parse
(
StringIO
(
html
),
parser
)
sections
=
tree
.
findall
(
'/body/section'
)
result
=
[]
for
section
in
sections
:
section_class
=
section
.
get
(
'class'
)
if
section_class
:
section_data
=
{}
section_data
[
'name'
]
=
section_class
section_data
[
'articles'
]
=
[]
articles
=
section
.
findall
(
'article'
)
if
articles
:
for
article
in
articles
:
article_class
=
article
.
get
(
'class'
)
if
article_class
:
article_data
=
{}
article_data
[
'name'
]
=
article_class
article_data
[
'body'
]
=
etree
.
tostring
(
article
)
section_data
[
'articles'
]
.
append
(
article_data
)
else
:
section_data
[
'body'
]
=
etree
.
tostring
(
section
)
result
.
append
(
section_data
)
return
result
@api_view
([
'GET'
])
@permission_classes
((
ApiKeyHeaderPermission
,))
def
course_about
(
request
,
course_id
):
"""
GET retrieves the course overview module, which - in MongoDB - is stored with the following
naming convention {"_id.org":"i4x", "_id.course":<course_num>, "_id.category":"about", "_id.name":"overview"}
"""
store
=
modulestore
()
response_data
=
{}
try
:
course_module
=
store
.
get_course
(
course_id
)
if
not
course_module
:
return
Response
({},
status
=
status
.
HTTP_404_NOT_FOUND
)
overview
=
get_course_about_section
(
course_module
,
'overview'
)
short_description
=
get_course_about_section
(
course_module
,
'short_description'
)
response_data
[
'sections'
]
=
_parse_about_html
(
overview
)
response_data
[
'overview_html'
]
=
overview
response_data
[
'short_description'
]
=
short_description
except
InvalidLocationError
:
return
Response
({},
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
response_data
)
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