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
012d8107
Commit
012d8107
authored
Jan 30, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get image upload, check for issues, upload to S3
parent
0c0a8971
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
6 deletions
+38
-6
common/lib/xmodule/xmodule/open_ended_image_submission.py
+5
-1
common/lib/xmodule/xmodule/open_ended_module.py
+1
-0
common/lib/xmodule/xmodule/openendedchild.py
+31
-5
common/lib/xmodule/xmodule/self_assessment_module.py
+1
-0
No files found.
common/lib/xmodule/xmodule/open_ended_image_submission.py
View file @
012d8107
...
...
@@ -18,6 +18,7 @@ ALLOWABLE_IMAGE_SUFFIXES = [
'gif'
]
MAX_ALLOWED_IMAGE_DIM
=
400
MAX_IMAGE_DIM
=
150
MAX_COLORS_TO_COUNT
=
16
MAX_COLORS
=
5
...
...
@@ -26,6 +27,9 @@ class ImageProperties(object):
def
__init__
(
self
,
image
):
self
.
image
=
image
image_size
=
self
.
image
.
size
self
.
image_too_large
=
False
if
image_size
[
0
]
>
MAX_ALLOWED_IMAGE_DIM
or
image_size
[
1
]
>
MAX_ALLOWED_IMAGE_DIM
:
self
.
image_too_large
=
True
if
image_size
[
0
]
>
MAX_IMAGE_DIM
or
image_size
[
1
]
>
MAX_IMAGE_DIM
:
self
.
image
=
self
.
image
.
resize
((
MAX_IMAGE_DIM
,
MAX_IMAGE_DIM
))
self
.
image_size
=
self
.
image
.
size
...
...
@@ -50,7 +54,7 @@ class ImageProperties(object):
return
is_okay
def
run_tests
(
self
):
image_is_okay
=
self
.
count_colors
()
and
self
.
get_skin_ratio
()
image_is_okay
=
self
.
count_colors
()
and
self
.
get_skin_ratio
()
and
not
self
.
image_too_large
return
image_is_okay
class
URLProperties
(
object
):
...
...
common/lib/xmodule/xmodule/open_ended_module.py
View file @
012d8107
...
...
@@ -553,6 +553,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
return
self
.
out_of_sync_error
(
get
)
# add new history element with answer and empty score and hint.
get
=
self
.
append_image_to_student_answer
(
get
)
self
.
new_history_entry
(
get
[
'student_answer'
])
get
[
'student_answer'
]
=
OpenEndedModule
.
sanitize_html
(
get
[
'student_answer'
])
self
.
send_to_grader
(
get
[
'student_answer'
],
system
)
...
...
common/lib/xmodule/xmodule/openendedchild.py
View file @
012d8107
...
...
@@ -283,25 +283,51 @@ class OpenEndedChild(object):
@return:
"""
success
=
False
image
=
Image
.
open
(
image_data
)
s3_public_url
=
""
try
:
image
=
Image
.
open
(
image_data
)
image_ok
=
open_ended_image_submission
.
run_image_tests
(
image
)
success
=
True
except
:
pass
log
.
exception
(
"Could not create image and check it."
)
if
success
:
image_key
=
image_data
.
name
+
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
try
:
success
,
public_url
=
open_ended_image_submission
.
upload_to_s3
(
image_data
,
image_key
)
success
=
True
except
:
pass
success
=
False
log
.
exception
(
"Could not upload image to S3."
)
log
.
debug
(
s3_public_url
)
return
success
,
s3_public_url
def
check_for_image_and_upload
(
self
,
get_data
):
success
=
False
error
=
False
image_tag
=
""
if
'can_upload_files'
in
get_data
:
file
=
get_data
[
'student_file'
]
success
,
s3_public_url
=
self
.
upload_image_to_s3
(
file
)
if
success
:
image_tag
=
self
.
generate_image_tag_from_url
(
s3_public_url
,
file
.
name
)
error
=
not
success
return
success
,
error
,
image_tag
def
generate_image_tag_from_url
(
self
,
s3_public_url
,
image_name
):
image_template
=
"""
<img src="{0}">{1}</img>
"""
.
format
(
s3_public_url
,
image_name
)
return
image_template
def
append_image_to_student_answer
(
self
,
get_data
):
success
,
error
,
image_tag
=
self
.
check_for_image_and_upload
(
get_data
)
if
success
and
not
error
:
get_data
[
'student_answer'
]
+=
image_tag
return
get_data
...
...
common/lib/xmodule/xmodule/self_assessment_module.py
View file @
012d8107
...
...
@@ -203,6 +203,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
return
self
.
out_of_sync_error
(
get
)
# add new history element with answer and empty score and hint.
get
=
self
.
append_image_to_student_answer
(
get
)
self
.
new_history_entry
(
get
[
'student_answer'
])
self
.
change_state
(
self
.
ASSESSING
)
...
...
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