def _rewrite_event_asset_url(event, url): """Rewrite URLs of assets such as event images. Only assets contained within the event will be taken into account """ scheme, netloc, path, qs, anchor = urlsplit(url) netloc = netloc or current_app.config['SERVER_NAME'] scheme = scheme or 'https' # internal URLs (same server) if netloc == current_app.config['SERVER_NAME']: # this piece of Flask magic finds the endpoint that corresponds to # the URL and checks that it points to an image belonging to this event endpoint_info = endpoint_for_url(path) if endpoint_info: endpoint, data = endpoint_info if endpoint == 'event_images.image_display' and int( data['confId']) == event.id: image_file = ImageFile.get(data['image_id']) if image_file and image_file.event == event: return f'images/{image_file.id}-{image_file.filename}', image_file # if the URL is not internal or just not an image, # we embed the contents using a data URI data_uri = _create_data_uri(urlunsplit((scheme, netloc, path, qs, '')), urlsplit(path)[-1]) return data_uri, None
def _rewrite_event_asset_url(event, url): """Rewrite URLs of assets such as event images. Only assets contained within the event will be taken into account """ scheme, netloc, path, qs, anchor = urlparse.urlsplit(url) netloc = netloc or current_app.config['SERVER_NAME'] scheme = scheme or 'https' # internal URLs (same server) if netloc == current_app.config['SERVER_NAME']: # this piece of Flask magic finds the endpoint that corresponds to # the URL and checks that it points to an image belonging to this event endpoint_info = endpoint_for_url(path) if endpoint_info: endpoint, data = endpoint_info if endpoint == 'event_images.image_display' and int(data['confId']) == event.id: image_file = ImageFile.get(data['image_id']) if image_file and image_file.event == event: return 'images/{}-{}'.format(image_file.id, image_file.filename), image_file # if the URL is not internal or just not an image, # we embed the contents using a data URI data_uri = _create_data_uri(urlparse.urlunsplit((scheme, netloc, path, qs, '')), urlparse.urlsplit(path)[-1]) return data_uri, None