def set_image(self, url): opener = urllib2.build_opener() try: response = opener.open(url) self.widgets['image'].url = url self.widgets['image'].value = ImageValueType( data=response.read(), filename=url.split('/')[-1]) self.request['form.widgets.image.action'] = u'load' except: pass
def handle_image(self, data): url = self.widgets['url'].value action = self.request.get('form.widgets.image.action', None) if action == 'load': json_data = self.get_data( url, maxwidth=None, maxheight=None, format='json') if json_data.get('thumbnail_url'): opener = urllib2.build_opener() try: response = opener.open(json_data.get('thumbnail_url')) data['image'] = ImageValueType(data=response.read(), filename=json_data.get('thumbnail_url').split('/')[-1]) except: pass