Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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-ora2
Commits
94559a0f
Commit
94559a0f
authored
Oct 19, 2015
by
Andy Armstrong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support loading unbundled JavaScript in debug mode
parent
f753b878
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
11 deletions
+42
-11
openassessment/xblock/openassessmentblock.py
+29
-6
openassessment/xblock/studio_mixin.py
+13
-5
No files found.
openassessment/xblock/openassessmentblock.py
View file @
94559a0f
...
...
@@ -4,10 +4,12 @@ import copy
import
datetime
as
dt
import
json
import
logging
import
os
import
pkg_resources
import
pytz
from
django.conf
import
settings
from
django.template.context
import
Context
from
django.template.loader
import
get_template
from
webob
import
Response
...
...
@@ -16,6 +18,7 @@ from lazy import lazy
from
xblock.core
import
XBlock
from
xblock.fields
import
List
,
Scope
,
String
,
Boolean
,
Integer
from
xblock.fragment
import
Fragment
from
openassessment.xblock.grade_mixin
import
GradeMixin
from
openassessment.xblock.leaderboard_mixin
import
LeaderboardMixin
from
openassessment.xblock.defaults
import
*
# pylint: disable=wildcard-import, unused-wildcard-import
...
...
@@ -256,6 +259,18 @@ class OpenAssessmentBlock(
)
return
student_item_dict
def
add_javascript_files
(
self
,
fragment
,
item
):
"""
Add all the JavaScript files from a directory to the specified fragment
"""
if
pkg_resources
.
resource_isdir
(
__name__
,
item
):
for
child_item
in
pkg_resources
.
resource_listdir
(
__name__
,
item
):
path
=
os
.
path
.
join
(
item
,
child_item
)
if
not
pkg_resources
.
resource_isdir
(
__name__
,
path
):
fragment
.
add_javascript_url
(
self
.
runtime
.
local_resource_url
(
self
,
path
))
else
:
fragment
.
add_javascript_url
(
self
.
runtime
.
local_resource_url
(
self
,
item
))
def
student_view
(
self
,
context
=
None
):
"""The main view of OpenAssessmentBlock, displayed when viewing courses.
...
...
@@ -290,17 +305,25 @@ class OpenAssessmentBlock(
}
template
=
get_template
(
"openassessmentblock/oa_base.html"
)
context
=
Context
(
context_dict
)
frag
=
Fragment
(
template
.
render
(
context
))
frag
ment
=
Fragment
(
template
.
render
(
context
))
i18n_service
=
self
.
runtime
.
service
(
self
,
'i18n'
)
if
hasattr
(
i18n_service
,
'get_language_bidi'
)
and
i18n_service
.
get_language_bidi
():
frag
.
add_css
(
load
(
"static/css/openassessment-rtl.css"
))
css_url
=
"static/css/openassessment-rtl.css"
else
:
frag
.
add_css
(
load
(
"static/css/openassessment-ltr.css"
))
css_url
=
"static/css/openassessment-ltr.css"
frag
.
add_javascript
(
load
(
"static/js/openassessment-lms.min.js"
))
frag
.
initialize_js
(
'OpenAssessmentBlock'
)
return
frag
if
settings
.
DEBUG
:
fragment
.
add_css_url
(
self
.
runtime
.
local_resource_url
(
self
,
css_url
))
self
.
add_javascript_files
(
fragment
,
"static/js/src/oa_shared.js"
)
self
.
add_javascript_files
(
fragment
,
"static/js/src/oa_server.js"
)
self
.
add_javascript_files
(
fragment
,
"static/js/src/lms"
)
else
:
# TODO: load CSS and JavaScript as URLs once they can be served by the CDN
fragment
.
add_css
(
load
(
css_url
))
fragment
.
add_javascript
(
load
(
"static/js/openassessment-lms.min.js"
))
fragment
.
initialize_js
(
'OpenAssessmentBlock'
)
return
fragment
@property
...
...
openassessment/xblock/studio_mixin.py
View file @
94559a0f
...
...
@@ -5,20 +5,22 @@ import copy
import
logging
import
pkg_resources
from
uuid
import
uuid4
from
xml
import
UpdateFromXmlError
from
django.conf
import
settings
from
django.template
import
Context
from
django.template.loader
import
get_template
from
voluptuous
import
MultipleInvalid
from
xblock.core
import
XBlock
from
xblock.fields
import
List
,
Scope
from
xblock.fragment
import
Fragment
from
openassessment.xblock.defaults
import
DEFAULT_EDITOR_ASSESSMENTS_ORDER
,
DEFAULT_RUBRIC_FEEDBACK_TEXT
from
openassessment.xblock.validation
import
validator
from
openassessment.xblock.data_conversion
import
create_rubric_dict
,
make_django_template_key
,
update_assessments_format
from
openassessment.xblock.schema
import
EDITOR_UPDATE_SCHEMA
from
openassessment.xblock.resolve_dates
import
resolve_dates
from
openassessment.xblock.xml
import
serialize_examples_to_xml_str
,
parse_examples_from_xml_str
from
xml
import
UpdateFromXmlError
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -63,10 +65,16 @@ class StudioMixin(object):
rendered_template
=
get_template
(
'openassessmentblock/edit/oa_edit.html'
)
.
render
(
Context
(
self
.
editor_context
()))
frag
=
Fragment
(
rendered_template
)
frag
.
add_javascript
(
pkg_resources
.
resource_string
(
__name__
,
"static/js/openassessment-studio.min.js"
))
frag
.
initialize_js
(
'OpenAssessmentEditor'
)
return
frag
fragment
=
Fragment
(
rendered_template
)
if
settings
.
DEBUG
:
self
.
add_javascript_files
(
fragment
,
"static/js/src/oa_shared.js"
)
self
.
add_javascript_files
(
fragment
,
"static/js/src/oa_server.js"
)
self
.
add_javascript_files
(
fragment
,
"static/js/src/studio"
)
else
:
# TODO: switch to add_javascript_url once XBlock resources are loaded from the CDN
fragment
.
add_javascript
(
pkg_resources
.
resource_string
(
__name__
,
"static/js/openassessment-studio.min.js"
))
fragment
.
initialize_js
(
'OpenAssessmentEditor'
)
return
fragment
def
editor_context
(
self
):
"""
...
...
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