def generate_name(self, obj, file_data): filename = self.namegen(obj, file_data) if not self.relative_path: return filename return urljoin(self.relative_path, filename)
def download(self, path=None): """ Removing static from urls. """ if not self.can_download: abort(404) base_path, directory, path = self._normalize_path(path) # backward compatibility with base_url base_url = self.get_base_url() if base_url: base_url = urljoin(self.get_url('.index'), base_url) if path[:7] == 'static/': path = path[7:] return redirect(urljoin(base_url, path)) return send_file(directory)
def get_url(self, field): if field.thumbnail_size: filename = field.thumbnail_fn(field.data) else: filename = field.data if field.url_relative_path: filename = urljoin(field.url_relative_path, filename) return field.data
def get_url(self, field): if field.thumbnail_size: filename = field.thumbnail_fn(field.data) else: filename = field.data if field.url_relative_path: filename = urljoin(field.url_relative_path, filename) return url_for(field.endpoint, filename=filename)
def download(self, path=None): """ Download view method. :param path: File path. """ if not self.can_download: abort(404) base_path, directory, path = self._normalize_path(path) # backward compatibility with base_url base_url = self.get_base_url() if base_url: base_url = urljoin(url_for('.index'), base_url) return redirect(urljoin(base_url, path)) return send_file(directory)
def download(self, path=None): """ Download view method. :param path: File path. """ if not self.can_download: abort(404) base_path, directory, path = self._normalize_path(path) # backward compatibility with base_url base_url = self.get_base_url() if base_url: base_url = urljoin(self.get_url('.index'), base_url) return redirect(urljoin(base_url, path)) return send_file(directory)
def _get_file_url(self, path): """ Return static file url :param path: Static file path """ if self.is_file_editable(path): return url_for(".edit", path=path) else: base_url = self.get_base_url() return urljoin(base_url, path)
def get_url(self, field): if op.isfile(op.join(field.base_path, field.data)): return super(S3ImageUploadInput, self).get_url(field) if field.thumbnail_size: filename = field.thumbnail_fn(field.data) else: filename = field.data if field.url_relative_path: filename = urljoin(field.url_relative_path, filename) return url_for_s3(bucket_name=field.bucket_name, filename=filename)
def get_url(self, field): if op.isfile(op.join(field.base_path, field.data)): return super(S3ImageUploadInput, self).get_url(field) if field.thumbnail_size: filename = field.thumbnail_fn(field.data) else: filename = field.data if field.url_relative_path: filename = urljoin(field.url_relative_path, filename) return url_for_s3('static', bucket_name=field.bucket_name, filename=filename)
def is_safe_url(target): ref_url = urlparse(request.host_url) test_url = urlparse(urljoin(request.host_url, target)) return (test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc)