(self, request, project_pk=None)
| 931 | parser_classes = (parsers.MultiPartParser, parsers.JSONParser, parsers.FormParser,) |
| 932 | |
| 933 | def post(self, request, project_pk=None): |
| 934 | project = get_and_check_project(request, project_pk, ('change_project',)) |
| 935 | |
| 936 | tmp_upload_dir = get_external_import_tmpdir(request) |
| 937 | task_name = request.data.get('name', _('Imported Task')) |
| 938 | |
| 939 | # Quick assets validation (this should be fast) |
| 940 | try: |
| 941 | asset_count = 0 |
| 942 | for asset_type in EXTERNAL_ASSET_FILES: |
| 943 | asset_file_candidates = EXTERNAL_ASSET_FILES[asset_type] |
| 944 | for asset_file in asset_file_candidates: |
| 945 | src_path = os.path.join(tmp_upload_dir, asset_file) |
| 946 | if os.path.isfile(src_path): |
| 947 | if asset_type == "orthophoto": |
| 948 | with rasterio.open(src_path, "r") as f: |
| 949 | if f.crs is None: |
| 950 | raise exceptions.ValidationError(detail=_("GeoTIFF must have a valid CRS")) |
| 951 | |
| 952 | if asset_type in ["dsm", "dtm"]: |
| 953 | with rasterio.open(src_path, "r") as f: |
| 954 | if f.crs is None: |
| 955 | raise exceptions.ValidationError(detail=_("GeoTIFF must have a valid CRS")) |
| 956 | if f.count > 2: |
| 957 | raise exceptions.ValidationError(detail=_("Elevation model must have at most 2 band")) |
| 958 | |
| 959 | if asset_type == "pointcloud": |
| 960 | with open(src_path, "rb") as f: |
| 961 | magic = f.read(4) |
| 962 | if magic != b"LASF": |
| 963 | raise exceptions.ValidationError(detail=_("Point cloud must be a valid LAZ/LAS file")) |
| 964 | |
| 965 | if asset_type == "texturedmodel": |
| 966 | with open(src_path, "rb") as f: |
| 967 | magic = f.read(4) |
| 968 | if magic != b"glTF": |
| 969 | raise exceptions.ValidationError(detail=_("Textured model must be a valid GLB file")) |
| 970 | asset_count += 1 |
| 971 | |
| 972 | if asset_count == 0: |
| 973 | raise exceptions.ValidationError(detail=_("No assets uploaded")) |
| 974 | |
| 975 | with transaction.atomic(): |
| 976 | task = models.Task.objects.create(project=project, |
| 977 | auto_processing_node=False, |
| 978 | name=task_name, |
| 979 | import_url="file://external", |
| 980 | status=status_codes.RUNNING, |
| 981 | pending_action=pending_actions.IMPORT) |
| 982 | task.create_task_directories() |
| 983 | |
| 984 | for asset_candidates in EXTERNAL_ASSET_FILES.values(): |
| 985 | for asset in asset_candidates: |
| 986 | src_path = os.path.join(tmp_upload_dir, asset) |
| 987 | if os.path.isfile(src_path): |
| 988 | dst_path = task.get_asset_download_path(asset) |
| 989 | dst_dir = os.path.dirname(dst_path) |
| 990 | os.makedirs(dst_dir, exist_ok=True) |
nothing calls this directly
no test coverage detected