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
d6947f1d
Commit
d6947f1d
authored
Jan 30, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper image submission, error handling
parent
bae898ed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
14 deletions
+17
-14
common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee
+5
-5
common/lib/xmodule/xmodule/open_ended_image_submission.py
+2
-1
common/lib/xmodule/xmodule/openendedchild.py
+10
-8
No files found.
common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee
View file @
d6947f1d
...
@@ -183,16 +183,16 @@ class @CombinedOpenEnded
...
@@ -183,16 +183,16 @@ class @CombinedOpenEnded
files
=
""
files
=
""
if
@
can_upload_files
==
true
if
@
can_upload_files
==
true
files
=
$
(
'.file-upload-box'
)[
0
].
files
[
0
]
files
=
$
(
'.file-upload-box'
)[
0
].
files
[
0
]
if
files
.
size
>
max_filesize
if
files
!=
undefined
@
can_upload_files
=
false
if
files
.
size
>
max_filesize
files
=
""
@
can_upload_files
=
false
files
=
""
fd
=
new
FormData
()
fd
=
new
FormData
()
fd
.
append
(
'student_answer'
,
@
answer_area
.
val
())
fd
.
append
(
'student_answer'
,
@
answer_area
.
val
())
fd
.
append
(
'student_file'
,
files
)
fd
.
append
(
'student_file'
,
files
)
fd
.
append
(
'can_upload_files'
,
files
)
fd
.
append
(
'can_upload_files'
,
@
can_upload_
files
)
#data = {'student_answer' : @answer_area.val(), 'file_value' : file_value, 'file_id' : file_id}
settings
=
settings
=
type
:
"POST"
type
:
"POST"
data
:
fd
data
:
fd
...
...
common/lib/xmodule/xmodule/open_ended_image_submission.py
View file @
d6947f1d
...
@@ -12,7 +12,8 @@ log=logging.getLogger(__name__)
...
@@ -12,7 +12,8 @@ log=logging.getLogger(__name__)
TRUSTED_IMAGE_DOMAINS
=
[
TRUSTED_IMAGE_DOMAINS
=
[
'wikipedia.com'
,
'wikipedia.com'
,
'wikipedia.net'
,
'wikipedia.net'
,
'wikipedia.org'
'wikipedia.org'
,
'edxuploads.s3.amazonaws.com'
]
]
ALLOWABLE_IMAGE_SUFFIXES
=
[
ALLOWABLE_IMAGE_SUFFIXES
=
[
...
...
common/lib/xmodule/xmodule/openendedchild.py
View file @
d6947f1d
...
@@ -5,7 +5,7 @@ import json
...
@@ -5,7 +5,7 @@ import json
import
logging
import
logging
from
lxml
import
etree
from
lxml
import
etree
from
lxml.html
import
rewrite_links
from
lxml.html
import
rewrite_links
from
lxml.html.clean
import
Cleaner
from
lxml.html.clean
import
Cleaner
,
autolink_html
from
path
import
path
from
path
import
path
import
os
import
os
import
sys
import
sys
...
@@ -139,8 +139,9 @@ class OpenEndedChild(object):
...
@@ -139,8 +139,9 @@ class OpenEndedChild(object):
@staticmethod
@staticmethod
def
sanitize_html
(
answer
):
def
sanitize_html
(
answer
):
try
:
try
:
cleaner
=
Cleaner
(
style
=
True
,
links
=
True
,
add_nofollow
=
False
,
page_structure
=
True
,
safe_attrs_only
=
False
,
allow_tags
=
[
"img"
,
"a"
])
cleaner
=
Cleaner
(
style
=
True
,
links
=
True
,
add_nofollow
=
False
,
page_structure
=
True
,
safe_attrs_only
=
False
,
allow_tags
=
[
"img"
,
"a"
]
,
host_whitelist
=
open_ended_image_submission
.
TRUSTED_IMAGE_DOMAINS
)
clean_html
=
cleaner
.
clean_html
(
answer
)
clean_html
=
cleaner
.
clean_html
(
answer
)
autolink_html
=
autolink_html
(
clean_html
)
clean_html
=
re
.
sub
(
r'</p>$'
,
''
,
re
.
sub
(
r'^<p>'
,
''
,
clean_html
))
clean_html
=
re
.
sub
(
r'</p>$'
,
''
,
re
.
sub
(
r'^<p>'
,
''
,
clean_html
))
except
:
except
:
clean_html
=
answer
clean_html
=
answer
...
@@ -311,12 +312,13 @@ class OpenEndedChild(object):
...
@@ -311,12 +312,13 @@ class OpenEndedChild(object):
error
=
False
error
=
False
image_tag
=
""
image_tag
=
""
if
'can_upload_files'
in
get_data
:
if
'can_upload_files'
in
get_data
:
file
=
get_data
[
'student_file'
][
0
]
if
get_data
[
'can_upload_files'
]
==
'true'
:
success
,
s3_public_url
=
self
.
upload_image_to_s3
(
file
)
file
=
get_data
[
'student_file'
][
0
]
if
success
:
success
,
s3_public_url
=
self
.
upload_image_to_s3
(
file
)
image_tag
=
self
.
generate_image_tag_from_url
(
s3_public_url
,
file
.
name
)
if
success
:
error
=
not
success
image_tag
=
self
.
generate_image_tag_from_url
(
s3_public_url
,
file
.
name
)
return
success
,
error
,
image_tag
error
=
not
success
return
success
,
error
,
image_tag
def
generate_image_tag_from_url
(
self
,
s3_public_url
,
image_name
):
def
generate_image_tag_from_url
(
self
,
s3_public_url
,
image_name
):
image_template
=
"""
image_template
=
"""
...
...
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