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
ac6f84ff
Commit
ac6f84ff
authored
Jan 30, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow url submissions instead of images
parent
99ecc784
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
common/lib/xmodule/xmodule/open_ended_image_submission.py
+15
-5
common/lib/xmodule/xmodule/openendedchild.py
+20
-1
No files found.
common/lib/xmodule/xmodule/open_ended_image_submission.py
View file @
ac6f84ff
...
@@ -11,15 +11,15 @@ from boto.s3.key import Key
...
@@ -11,15 +11,15 @@ from boto.s3.key import Key
from
django.conf
import
settings
from
django.conf
import
settings
import
pickle
import
pickle
import
logging
import
logging
import
re
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
#Domains where any image linked to can be trusted to have acceptable content.
#Domains where any image linked to can be trusted to have acceptable content.
TRUSTED_IMAGE_DOMAINS
=
[
TRUSTED_IMAGE_DOMAINS
=
[
'wikipedia.com'
,
'wikipedia'
,
'wikipedia.net'
,
'edxuploads.s3.amazonaws.com'
,
'wikipedia.org'
,
'wikimedia'
,
'edxuploads.s3.amazonaws.com'
]
]
#Suffixes that are allowed in image urls
#Suffixes that are allowed in image urls
...
@@ -156,9 +156,19 @@ class URLProperties(object):
...
@@ -156,9 +156,19 @@ class URLProperties(object):
Runs all available url tests
Runs all available url tests
@return: True if URL passes tests, false if not.
@return: True if URL passes tests, false if not.
"""
"""
url_is_okay
=
self
.
check_suffix
()
and
self
.
check_if_parses
()
url_is_okay
=
self
.
check_suffix
()
and
self
.
check_if_parses
()
and
self
.
check_domain
()
return
url_is_okay
return
url_is_okay
def
check_domain
(
self
):
"""
Checks to see if url is from a trusted domain
"""
success
=
False
for
domain
in
TRUSTED_IMAGE_DOMAINS
:
if
domain
in
self
.
url_string
:
success
=
True
return
success
return
success
def
run_url_tests
(
url_string
):
def
run_url_tests
(
url_string
):
"""
"""
...
...
common/lib/xmodule/xmodule/openendedchild.py
View file @
ac6f84ff
...
@@ -329,14 +329,33 @@ class OpenEndedChild(object):
...
@@ -329,14 +329,33 @@ class OpenEndedChild(object):
return
image_template
return
image_template
def
append_image_to_student_answer
(
self
,
get_data
):
def
append_image_to_student_answer
(
self
,
get_data
):
overall_success
=
False
if
not
self
.
accept_file_upload
:
if
not
self
.
accept_file_upload
:
return
True
,
get_data
return
True
,
get_data
success
,
has_file_to_upload
,
image_tag
=
self
.
check_for_image_and_upload
(
get_data
)
success
,
has_file_to_upload
,
image_tag
=
self
.
check_for_image_and_upload
(
get_data
)
if
success
and
has_file_to_upload
:
if
success
and
has_file_to_upload
:
get_data
[
'student_answer'
]
+=
image_tag
get_data
[
'student_answer'
]
+=
image_tag
overall_success
=
(
success
and
has_file_to_upload
)
else
:
success
,
get_data
[
'student_answer'
]
=
self
.
check_for_url_in_text
(
get_data
[
'student_answer'
])
overall_success
=
success
return
success
,
get_data
def
check_for_url_in_text
(
self
,
string
):
success
=
False
links
=
re
.
findall
(
r'(https?://\S+)'
,
string
)
if
len
(
links
)
>
0
:
for
link
in
links
:
success
=
open_ended_image_submission
.
run_url_tests
(
link
)
if
not
success
:
string
=
re
.
sub
(
link
,
''
,
string
)
else
:
success
=
True
return
success
,
string
return
(
success
and
has_file_to_upload
),
get_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