Commit 79113756 by Vik Paruchuri

Add in ability to submit an image URL

parent ac6f84ff
...@@ -4,7 +4,7 @@ to send them to S3. ...@@ -4,7 +4,7 @@ to send them to S3.
""" """
from PIL import Image from PIL import Image
import urlparse from urlparse import urlparse
import requests import requests
from boto.s3.connection import S3Connection from boto.s3.connection import S3Connection
from boto.s3.key import Key from boto.s3.key import Key
...@@ -26,7 +26,8 @@ TRUSTED_IMAGE_DOMAINS = [ ...@@ -26,7 +26,8 @@ TRUSTED_IMAGE_DOMAINS = [
ALLOWABLE_IMAGE_SUFFIXES = [ ALLOWABLE_IMAGE_SUFFIXES = [
'jpg', 'jpg',
'png', 'png',
'gif' 'gif',
'jpeg'
] ]
#Maximum allowed dimensions (x and y) for an uploaded image #Maximum allowed dimensions (x and y) for an uploaded image
...@@ -132,7 +133,7 @@ class URLProperties(object): ...@@ -132,7 +133,7 @@ class URLProperties(object):
""" """
success = False success = False
try: try:
self.parsed_url = urlparse.urlparse(url_string) self.parsed_url = urlparse(self.url_string)
success = True success = True
except: except:
pass pass
...@@ -157,6 +158,10 @@ class URLProperties(object): ...@@ -157,6 +158,10 @@ class URLProperties(object):
@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() and self.check_domain() url_is_okay = self.check_suffix() and self.check_if_parses() and self.check_domain()
log.debug(self.url_string)
log.debug("Suffix : {0}".format(self.check_suffix()))
log.debug("Parses:{0}".format(self.check_if_parses()))
log.debug("Check Domain:{0}".format(self.check_domain()))
return url_is_okay return url_is_okay
def check_domain(self): def check_domain(self):
......
...@@ -341,7 +341,7 @@ class OpenEndedChild(object): ...@@ -341,7 +341,7 @@ class OpenEndedChild(object):
success, get_data['student_answer'] = self.check_for_url_in_text(get_data['student_answer']) success, get_data['student_answer'] = self.check_for_url_in_text(get_data['student_answer'])
overall_success = success overall_success = success
return success, get_data return overall_success, get_data
def check_for_url_in_text(self, string): def check_for_url_in_text(self, string):
success = False success = False
...@@ -352,6 +352,7 @@ class OpenEndedChild(object): ...@@ -352,6 +352,7 @@ class OpenEndedChild(object):
if not success: if not success:
string = re.sub(link, '', string) string = re.sub(link, '', string)
else: else:
string = re.sub(link, self.generate_image_tag_from_url(link,link), string)
success = True success = True
return success, string return success, string
......
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