Commit 9c5fe056 by Vik Paruchuri

Update reqs for pillow, work on file uploads

parent 4d1f9d2e
......@@ -39,6 +39,7 @@ MAX_SCORE = 1
MAX_SCORE_ALLOWED = 3
IS_SCORED=False
UPLOAD_IMAGE = False
class CombinedOpenEndedModule(XModule):
"""
......@@ -141,6 +142,7 @@ class CombinedOpenEndedModule(XModule):
self.allow_reset = instance_state.get('ready_to_reset', False)
self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS))
self.is_scored = (self.metadata.get('is_graded', IS_SCORED)=="True")
self.upload_image = (self.metadata.get('upload_image', UPLOAD_IMAGE)=="True")
log.debug(self.metadata.get('is_graded', IS_SCORED))
......@@ -173,7 +175,8 @@ class CombinedOpenEndedModule(XModule):
'max_attempts': self.max_attempts,
'prompt': definition['prompt'],
'rubric': definition['rubric'],
'display_name': self.display_name
'display_name': self.display_name,
'accept_file_upload' : self.upload_image,
}
self.task_xml = definition['task_xml']
......@@ -672,4 +675,4 @@ class CombinedOpenEndedDescriptor(XmlDescriptor, EditingDescriptor):
for child in ['task']:
add_child(child)
return elt
return elt
\ No newline at end of file
......@@ -44,6 +44,7 @@ class @CombinedOpenEnded
@skip_button = @$('.skip-button')
@skip_button.click @skip_post_assessment
@file_upload_area = @$('.file-upload')
@open_ended_child= @$('.open-ended-child')
@find_assessment_elements()
......@@ -298,3 +299,6 @@ class @CombinedOpenEnded
location.reload()
else
window.queuePollerID = window.setTimeout(@poll, 10000)
setup_file_upload: =>
@file_upload_area.html('<input type="file" class="file">')
\ No newline at end of file
from PIL import Image
import urlparse
import requests
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from django.conf import settings
import pickle
TRUSTED_IMAGE_DOMAINS = [
'wikipedia.com',
......@@ -91,11 +96,12 @@ def upload_to_s3(string_to_upload, keyname):
'''
try:
conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
bucketname = str(AWS_STORAGE_BUCKET_NAME)
bucketname = str(settings.AWS_STORAGE_BUCKET_NAME)
bucket = conn.create_bucket(bucketname.lower())
k = Key(bucket)
k.key = keyname
k.set_metadata("Content-Type", 'images/png')
k.set_contents_from_string(string_to_upload)
public_url = k.generate_url(60*60*24*365) # URL timeout in seconds.
......@@ -103,6 +109,13 @@ def upload_to_s3(string_to_upload, keyname):
except:
return False, "Could not connect to S3."
def get_from_s3(s3_public_url):
r = requests.get(s3_public_url, timeout=2)
data=r.text
return data
def convert_image_to_string(image):
return image.tostring()
......@@ -602,6 +602,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
'msg': post_assessment,
'child_type': 'openended',
'correct': correct,
'accept_file_upload' : self.accept_file_upload,
}
html = system.render_template('open_ended.html', context)
return html
......
......@@ -96,6 +96,7 @@ class OpenEndedChild(object):
self.prompt = static_data['prompt']
self.rubric = static_data['rubric']
self.display_name = static_data['display_name']
self.accept_file_upload = static_data['accept_file_upload']
# Used for progress / grading. Currently get credit just for
# completion (doesn't matter if you self-assessed correct/incorrect).
......@@ -273,5 +274,13 @@ class OpenEndedChild(object):
correctness = 'correct' if self.is_submission_correct(score) else 'incorrect'
return correctness
def should_request_image(self):
"""
@return:
"""
pass
......@@ -80,6 +80,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
'state': self.state,
'allow_reset': self._allow_reset(),
'child_type': 'selfassessment',
'accept_file_upload' : self.accept_file_upload,
}
html = system.render_template('self_assessment_prompt.html', context)
......
......@@ -22,6 +22,8 @@
% endif
</div>
<div class="file-upload"></div>
<input type="button" value="Submit" class="submit-button" name="show"/>
<input name="skip" class="skip-button" type="button" value="Skip Post-Assessment"/>
......
......@@ -16,6 +16,7 @@
<div class="hint-wrapper">${initial_hint}</div>
<div class="message-wrapper">${initial_message}</div>
<div class="file-upload"></div>
<input type="button" value="Submit" class="submit-button" name="show"/>
</section>
......@@ -48,7 +48,6 @@ sorl-thumbnail==11.12
networkx==1.7
pygraphviz==1.1
-r repo-requirements.txt
pil==1.1.7
nltk==2.0.4
django-debug-toolbar-mongo
dogstatsd-python==0.2.1
......@@ -59,3 +58,4 @@ Shapely==1.2.16
ipython==0.13.1
xmltodict==0.4.1
paramiko==1.9.0
pillow
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment