Esempio n. 1
0
def _static_dir(file_path, version=None):
    if version:
        version = '?v=%s' % _get_version()
    else:
        version = ''
    return '%s/client/%s%s' % (settings.get_host_url(
        webapp2.get_request().host), file_path, version)
Esempio n. 2
0
 def process_image(value, i, values):
     config = self._process_config
     new_value = value
     gs_object_name = new_value.gs_object_name
     new_gs_object_name = new_value.gs_object_name
     if config.get('copy'):
         new_value = copy.deepcopy(value)
         new_gs_object_name = '%s_%s' % (new_value.gs_object_name,
                                         config.get('copy_name'))
     blob_key = None
     # @note No try block is implemented here. This code is no longer forgiving.
     # If any of the images fail to process, everything is lost/reverted, because one or more images:
     # - are no longer existant in the cloudstorage / .read();
     # - are not valid / not image exception;
     # - failed to resize / resize could not be done;
     # - failed to create gs key / blobstore failed for some reason;
     # - failed to create get_serving_url / serving url service failed for some reason;
     # - failed to write to cloudstorage / cloudstorage failed for some reason.
     if settings.DEVELOPMENT_SERVER:
         blob = urlfetch.fetch('%s/_ah/gcs%s' %
                               (settings.get_host_url('localhost:9982'),
                                gs_object_name[3:]))
         blob = blob.content
     else:
         readonly_blob = cloudstorage.open(gs_object_name[3:], 'r')
         blob = readonly_blob.read()
         readonly_blob.close()
     image = images.Image(image_data=blob)
     if config.get('transform'):
         image.resize(config.get('width'),
                      config.get('height'),
                      crop_to_fit=config.get('crop_to_fit', False),
                      crop_offset_x=config.get('crop_offset_x', 0.0),
                      crop_offset_y=config.get('crop_offset_y', 0.0))
         blob = yield image.execute_transforms_async(
             output_encoding=image.format)
     new_value.proportion = float(image.width) / float(image.height)
     new_value.size = len(blob)
     writable_blob = cloudstorage.open(
         new_gs_object_name[3:],
         'w',
         content_type=new_value.content_type)
     writable_blob.write(blob)
     writable_blob.close()
     if gs_object_name != new_gs_object_name:
         new_value.gs_object_name = new_gs_object_name
         blob_key = yield blobstore.create_gs_key_async(
             new_gs_object_name)
         new_value.image = blobstore.BlobKey(blob_key)
         new_value.serving_url = None
     values[i] = new_value
     raise Return(True)
Esempio n. 3
0
def absolute_url(path):
    host = webapp2.get_request().host
    if settings.NOTIFICATION_HOSTNAME:
        host = settings.NOTIFICATION_HOSTNAME
    return '%s/%s' % (settings.get_host_url(host), path)
Esempio n. 4
0
def api_model_meta():
    request = webapp2.get_request()
    return settings.get_host_url(request.host) + '/api/model_meta'
Esempio n. 5
0
def api_endpoint():
    request = webapp2.get_request()
    return settings.get_host_url(request.host) + '/api/endpoint'