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
a48a392e
Commit
a48a392e
authored
Nov 28, 2012
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trying to get scss back
parent
a68dee97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
41 deletions
+39
-41
cms/djangoapps/contentstore/course_info_model.py
+7
-6
cms/djangoapps/contentstore/utils.py
+13
-0
cms/djangoapps/contentstore/views.py
+7
-24
common/djangoapps/models/settings/course_details.py
+12
-11
No files found.
cms/djangoapps/contentstore/course_info_model.py
View file @
a48a392e
...
...
@@ -4,6 +4,7 @@ from xmodule.modulestore.django import modulestore
from
lxml
import
etree
import
re
from
django.http
import
HttpResponseBadRequest
from
contentstore.utils
import
get_modulestore
## TODO store as array of { date, content } and override course_info_module.definition_from_xml
## This should be in a class which inherits from XmlDescriptor
...
...
@@ -13,10 +14,10 @@ def get_course_updates(location):
[{id : location.url() + idx to make unique, date : string, content : html string}]
"""
try
:
course_updates
=
modulestore
(
'direct'
)
.
get_item
(
location
)
course_updates
=
get_modulestore
(
location
)
.
get_item
(
location
)
except
ItemNotFoundError
:
template
=
Location
([
'i4x'
,
'edx'
,
"templates"
,
'course_info'
,
"Empty"
])
course_updates
=
modulestore
(
'direct'
)
.
clone_item
(
template
,
Location
(
location
))
course_updates
=
get_modulestore
(
location
)
.
clone_item
(
template
,
Location
(
location
))
# current db rep: {"_id" : locationjson, "definition" : { "data" : "<ol>[<li><h2>date</h2>content</li>]</ol>"} "metadata" : ignored}
location_base
=
course_updates
.
location
.
url
()
...
...
@@ -53,7 +54,7 @@ def update_course_updates(location, update, passed_id=None):
into the html structure.
"""
try
:
course_updates
=
modulestore
(
'direct'
)
.
get_item
(
location
)
course_updates
=
get_modulestore
(
location
)
.
get_item
(
location
)
except
ItemNotFoundError
:
return
HttpResponseBadRequest
...
...
@@ -99,7 +100,7 @@ def update_course_updates(location, update, passed_id=None):
# update db record
course_updates
.
definition
[
'data'
]
=
etree
.
tostring
(
course_html_parsed
)
modulestore
(
'direct'
)
.
update_item
(
location
,
course_updates
.
definition
[
'data'
])
get_modulestore
(
location
)
.
update_item
(
location
,
course_updates
.
definition
[
'data'
])
return
{
"id"
:
passed_id
,
"date"
:
update
[
'date'
],
...
...
@@ -114,7 +115,7 @@ def delete_course_update(location, update, passed_id):
return
HttpResponseBadRequest
try
:
course_updates
=
modulestore
(
'direct'
)
.
get_item
(
location
)
course_updates
=
get_modulestore
(
location
)
.
get_item
(
location
)
except
ItemNotFoundError
:
return
HttpResponseBadRequest
...
...
@@ -133,7 +134,7 @@ def delete_course_update(location, update, passed_id):
# update db record
course_updates
.
definition
[
'data'
]
=
etree
.
tostring
(
course_html_parsed
)
store
=
modulestore
(
'direct'
)
store
=
get_modulestore
(
location
)
store
.
update_item
(
location
,
course_updates
.
definition
[
'data'
])
return
get_course_updates
(
location
)
...
...
cms/djangoapps/contentstore/utils.py
View file @
a48a392e
...
...
@@ -3,6 +3,19 @@ from xmodule.modulestore import Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
DIRECT_ONLY_CATEGORIES
=
[
'course'
,
'chapter'
,
'sequential'
,
'about'
,
'static_tab'
,
'course_info'
]
def
get_modulestore
(
location
):
"""
Returns the correct modulestore to use for modifying the specified location
"""
if
not
isinstance
(
location
,
Location
):
location
=
Location
(
location
)
if
location
.
category
in
DIRECT_ONLY_CATEGORIES
:
return
modulestore
(
'direct'
)
else
:
return
modulestore
()
def
get_course_location_for_item
(
location
):
'''
...
...
cms/djangoapps/contentstore/views.py
View file @
a48a392e
...
...
@@ -46,36 +46,19 @@ import time
from
contentstore
import
course_info_model
from
models.settings.course_details
import
CourseDetails
from
models.settings.course_details
import
CourseDetailsEncoder
from
contentstore.utils
import
get_modulestore
# to install PIL on MacOSX: 'easy_install http://dist.repoze.org/PIL-1.1.6.tar.gz'
log
=
logging
.
getLogger
(
__name__
)
COMPONENT_TYPES
=
[
'customtag'
,
'discussion'
,
'html'
,
'problem'
,
'video'
]
DIRECT_ONLY_CATEGORIES
=
[
'course'
,
'chapter'
,
'sequential'
,
'about'
,
'static_tab'
,
'course_info'
]
# cdodge: these are categories which should not be parented, they are detached from the hierarchy
DETACHED_CATEGORIES
=
[
'about'
,
'static_tab'
,
'course_info'
]
def
_modulestore
(
location
):
"""
Returns the correct modulestore to use for modifying the specified location
"""
if
location
.
category
in
DIRECT_ONLY_CATEGORIES
:
return
modulestore
(
'direct'
)
else
:
return
modulestore
()
# ==== Public views ==================================================
@ensure_csrf_cookie
...
...
@@ -543,7 +526,7 @@ def delete_item(request):
item
=
modulestore
()
.
get_item
(
item_location
)
store
=
_modulestore
(
item_loc
)
store
=
get
_modulestore
(
item_loc
)
# @TODO: this probably leaves draft items dangling. My preferance would be for the semantic to be
...
...
@@ -574,7 +557,7 @@ def save_item(request):
if
not
has_access
(
request
.
user
,
item_location
):
raise
PermissionDenied
()
store
=
_modulestore
(
Location
(
item_location
));
store
=
get
_modulestore
(
Location
(
item_location
));
if
request
.
POST
.
get
(
'data'
)
is
not
None
:
data
=
request
.
POST
[
'data'
]
...
...
@@ -677,10 +660,10 @@ def clone_item(request):
if
not
has_access
(
request
.
user
,
parent_location
):
raise
PermissionDenied
()
parent
=
_modulestore
(
template
)
.
get_item
(
parent_location
)
parent
=
get
_modulestore
(
template
)
.
get_item
(
parent_location
)
dest_location
=
parent_location
.
_replace
(
category
=
template
.
category
,
name
=
uuid4
()
.
hex
)
new_item
=
_modulestore
(
template
)
.
clone_item
(
template
,
dest_location
)
new_item
=
get
_modulestore
(
template
)
.
clone_item
(
template
,
dest_location
)
# TODO: This needs to be deleted when we have proper storage for static content
new_item
.
metadata
[
'data_dir'
]
=
parent
.
metadata
[
'data_dir'
]
...
...
@@ -689,10 +672,10 @@ def clone_item(request):
if
display_name
is
not
None
:
new_item
.
metadata
[
'display_name'
]
=
display_name
_modulestore
(
template
)
.
update_metadata
(
new_item
.
location
.
url
(),
new_item
.
own_metadata
)
get
_modulestore
(
template
)
.
update_metadata
(
new_item
.
location
.
url
(),
new_item
.
own_metadata
)
if
new_item
.
location
.
category
not
in
DETACHED_CATEGORIES
:
_modulestore
(
parent
.
location
)
.
update_children
(
parent_location
,
parent
.
definition
.
get
(
'children'
,
[])
+
[
new_item
.
location
.
url
()])
get
_modulestore
(
parent
.
location
)
.
update_children
(
parent_location
,
parent
.
definition
.
get
(
'children'
,
[])
+
[
new_item
.
location
.
url
()])
return
HttpResponse
(
json
.
dumps
({
'id'
:
dest_location
.
url
()}))
...
...
common/djangoapps/models/settings/course_details.py
View file @
a48a392e
...
...
@@ -5,6 +5,7 @@ import json
from
json.encoder
import
JSONEncoder
import
time
from
util.converters
import
jsdate_to_time
,
time_to_date
from
contentstore.utils
import
get_modulestore
class
CourseDetails
:
def
__init__
(
self
,
location
):
...
...
@@ -28,7 +29,7 @@ class CourseDetails:
course
=
cls
(
course_location
)
descriptor
=
modulestore
(
'direct'
)
.
get_item
(
course_location
)
descriptor
=
get_modulestore
(
course_location
)
.
get_item
(
course_location
)
course
.
start_date
=
descriptor
.
start
course
.
end_date
=
descriptor
.
end
...
...
@@ -37,25 +38,25 @@ class CourseDetails:
temploc
=
course_location
.
_replace
(
category
=
'about'
,
name
=
'syllabus'
)
try
:
course
.
syllabus
=
modulestore
(
'direct'
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
course
.
syllabus
=
get_modulestore
(
temploc
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
except
ItemNotFoundError
:
pass
temploc
=
temploc
.
_replace
(
name
=
'overview'
)
try
:
course
.
overview
=
modulestore
(
'direct'
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
course
.
overview
=
get_modulestore
(
temploc
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
except
ItemNotFoundError
:
pass
temploc
=
temploc
.
_replace
(
name
=
'effort'
)
try
:
course
.
effort
=
modulestore
(
'direct'
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
course
.
effort
=
get_modulestore
(
temploc
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
except
ItemNotFoundError
:
pass
temploc
=
temploc
.
_replace
(
name
=
'video'
)
try
:
course
.
intro_video
=
modulestore
(
'direct'
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
course
.
intro_video
=
get_modulestore
(
temploc
)
.
get_item
(
temploc
)
.
definition
[
'data'
]
except
ItemNotFoundError
:
pass
...
...
@@ -69,7 +70,7 @@ class CourseDetails:
## TODO make it an error for this to be undefined & for it to not be retrievable from modulestore
course_location
=
jsondict
[
'course_location'
]
## Will probably want to cache the inflight courses because every blur generates an update
descriptor
=
modulestore
(
'direct'
)
.
get_item
(
course_location
)
descriptor
=
get_modulestore
(
course_location
)
.
get_item
(
course_location
)
dirty
=
False
...
...
@@ -110,21 +111,21 @@ class CourseDetails:
descriptor
.
enrollment_end
=
converted
if
dirty
:
modulestore
(
'direct'
)
.
update_metadata
(
course_location
,
descriptor
.
metadata
)
get_modulestore
(
course_location
)
.
update_metadata
(
course_location
,
descriptor
.
metadata
)
# 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.
temploc
=
Location
(
course_location
)
.
_replace
(
category
=
'about'
,
name
=
'syllabus'
)
modulestore
(
'direct'
)
.
update_item
(
temploc
,
jsondict
[
'syllabus'
])
get_modulestore
(
temploc
)
.
update_item
(
temploc
,
jsondict
[
'syllabus'
])
temploc
=
temploc
.
_replace
(
name
=
'overview'
)
modulestore
(
'direct'
)
.
update_item
(
temploc
,
jsondict
[
'overview'
])
get_modulestore
(
temploc
)
.
update_item
(
temploc
,
jsondict
[
'overview'
])
temploc
=
temploc
.
_replace
(
name
=
'effort'
)
modulestore
(
'direct'
)
.
update_item
(
temploc
,
jsondict
[
'effort'
])
get_modulestore
(
temploc
)
.
update_item
(
temploc
,
jsondict
[
'effort'
])
temploc
=
temploc
.
_replace
(
name
=
'video'
)
modulestore
(
'direct'
)
.
update_item
(
temploc
,
jsondict
[
'intro_video'
])
get_modulestore
(
temploc
)
.
update_item
(
temploc
,
jsondict
[
'intro_video'
])
# Could just generate and return a course obj w/o doing any db reads, but I put the reads in as a means to confirm
...
...
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