pull/1086/head
Piero Toffanin 2021-11-04 15:14:48 -04:00
rodzic c5fc89f61a
commit 7401bf6e1d
5 zmienionych plików z 15 dodań i 10 usunięć

Wyświetl plik

@ -55,4 +55,7 @@ def hex2rgb(hex_color, with_alpha=False):
return tuple((255, 255, 255))
def get_asset_download_filename(task, asset):
return re.sub(r'[^0-9a-zA-Z-_]+', '', task.name.replace(" ", "-").replace("/", "-")) + "-" + asset
name = task.name
if name is None: name = ""
return re.sub(r'[^0-9a-zA-Z-_]+', '', name.replace(" ", "-").replace("/", "-")) + ("-" if name else "") + asset

Wyświetl plik

@ -347,6 +347,9 @@ def download_file_stream(request, stream, content_disposition, download_filename
response['Content-Type'] = mimetypes.guess_type(download_filename)[0] or "application/zip"
response['Content-Disposition'] = "{}; filename={}".format(content_disposition, download_filename)
# For testing
response['_stream'] = 'yes'
return response

Wyświetl plik

@ -504,6 +504,9 @@ class Export(TaskNestedView):
epsg = int(epsg)
except ValueError:
raise exceptions.ValidationError(_("Invalid EPSG code: %(value)s") % {'value': epsg})
if (formula and not bands) or (not formula and bands):
raise exceptions.ValidationError(_("Both formula and bands parameters are required"))
if formula and bands:
try:

Wyświetl plik

@ -456,6 +456,8 @@ class Task(models.Model):
if 'deferred_path' in value and 'deferred_compress_dir' in value:
zip_dir = self.assets_path(value['deferred_compress_dir'])
paths = [{'n': os.path.relpath(os.path.join(dp, f), zip_dir), 'fs': os.path.join(dp, f)} for dp, dn, filenames in os.walk(zip_dir) for f in filenames]
if len(paths) == 0:
raise FileNotFoundError("No files available for download")
return zipfly.ZipStream(paths), True
else:
raise FileNotFoundError("{} is not a valid asset (invalid dict values)".format(asset))

Wyświetl plik

@ -274,7 +274,7 @@ class TestApiTask(BootTransactionTestCase):
# Cannot download assets (they don't exist yet)
for asset in list(task.ASSETS_MAP.keys()):
res = client.get("/api/projects/{}/tasks/{}/download/{}".format(project.id, task.id, asset))
self.assertTrue(res.status_code == status.HTTP_404_NOT_FOUND)
self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)
# Cannot access raw assets (they don't exist yet)
res = client.get("/api/projects/{}/tasks/{}/assets/odm_orthophoto/odm_orthophoto.tif".format(project.id, task.id))
@ -362,7 +362,6 @@ class TestApiTask(BootTransactionTestCase):
# Can download assets
for asset in list(task.ASSETS_MAP.keys()):
res = client.get("/api/projects/{}/tasks/{}/download/{}".format(project.id, task.id, asset))
print("DOWLOAD: " + asset)
self.assertEqual(res.status_code, status.HTTP_200_OK)
# We can stream downloads
@ -375,13 +374,8 @@ class TestApiTask(BootTransactionTestCase):
self.assertTrue(valid_cogeo(task.assets_path(task.ASSETS_MAP["dsm.tif"])))
self.assertTrue(valid_cogeo(task.assets_path(task.ASSETS_MAP["dtm.tif"])))
# A textured mesh archive file should exist
self.assertTrue(os.path.exists(task.assets_path(task.ASSETS_MAP["textured_model.zip"]["deferred_path"])))
# Tiles archives should have been created
self.assertTrue(os.path.exists(task.assets_path(task.ASSETS_MAP["dsm_tiles.zip"]["deferred_path"])))
self.assertTrue(os.path.exists(task.assets_path(task.ASSETS_MAP["dtm_tiles.zip"]["deferred_path"])))
self.assertTrue(os.path.exists(task.assets_path(task.ASSETS_MAP["orthophoto_tiles.zip"]["deferred_path"])))
# A textured mesh archive file should not exist (it's generated on the fly)
self.assertFalse(os.path.exists(task.assets_path(task.ASSETS_MAP["textured_model.zip"]["deferred_path"])))
# Can download raw assets
res = client.get("/api/projects/{}/tasks/{}/assets/odm_orthophoto/odm_orthophoto.tif".format(project.id, task.id))