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 get_attributes(self, field): for item in ast.literal_eval(field.data): filename = item if field.url_relative_path: filename = urljoin(field.url_relative_path, filename) yield get_url(field.endpoint, filename=filename), item
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 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_view'), base_url) return redirect(urljoin(quote(base_url), quote(path))) return self.storage.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 get_url(field.endpoint, filename=filename)
def get_url(self, field): # overriding the default get_url method. if field.thumbnail_size: filename = field.thumbnail_fn(field.data) else: filename = field.data return urljoin(field.url_relative_path, filename)
def is_safe_url(target): # prevent urls starting with "javascript:" target = target.strip() target_info = urlparse(target) target_scheme = target_info.scheme if target_scheme and target_scheme not in VALID_SCHEMES: return False ref_url = urlparse(request.host_url) test_url = urlparse(urljoin(request.host_url, target)) return ref_url.netloc == test_url.netloc
def get_url(self, field): from flask_admin.helpers import get_url from flask_admin._compat import urljoin 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 get_url(field.endpoint, path=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(field.endpoint, bucket_name=field.bucket_name, filename=filename)
def is_safe_url(target): # prevent urls like "\\www.google.com" # some browser will change \\ to // (eg: Chrome) # refs https://stackoverflow.com/questions/10438008 target = target.replace('\\', '/') # handle cases like "j a v a s c r i p t:" target = _substitute_whitespace('', target) # Chrome and FireFox "fix" more than two slashes into two after protocol target = _fix_multiple_slashes(lambda m: m.group(1), target, 1) # prevent urls starting with "javascript:" target_info = urlparse(target) target_scheme = target_info.scheme if target_scheme and target_scheme not in VALID_SCHEMES: return False ref_url = urlparse(request.host_url) test_url = urlparse(urljoin(request.host_url, target)) return ref_url.netloc == test_url.netloc
def get_attributes(self, field): filename = field.data if field.url_relative_path: filename = urljoin(field.url_relative_path, filename) yield filename, field.data
def get_url(self, field): filename = field.thumbnail_fn(field.data) return urljoin(field.url_relative_path, 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)