(self, request, project_pk=None, pk=None)
| 162 | |
| 163 | class ImportDatasetTaskView(TaskView): |
| 164 | def post(self, request, project_pk=None, pk=None): |
| 165 | |
| 166 | task = self.get_and_check_task(request, pk) |
| 167 | |
| 168 | # Read form data |
| 169 | ddb_url = request.data.get('ddb_url', None) |
| 170 | |
| 171 | if ddb_url == None: |
| 172 | return Response({'error': 'DroneDB url must be set.'}, status=status.HTTP_400_BAD_REQUEST) |
| 173 | |
| 174 | registry_url, orgSlug, dsSlug, folder = parse_url(ddb_url).values() |
| 175 | |
| 176 | _, username, password, token = get_settings(request) |
| 177 | ddb = DroneDB(registry_url, username, password, token, lambda token: update_token(request, token)) |
| 178 | |
| 179 | # Get the files from the folder |
| 180 | rawfiles = ddb.get_files_list(orgSlug, dsSlug, folder) |
| 181 | files = [file for file in rawfiles if is_valid(file['path'])] |
| 182 | |
| 183 | # Verify that the folder url is valid |
| 184 | if len(files) == 0: |
| 185 | return Response({'error': 'Empty dataset or folder.'}, status=status.HTTP_400_BAD_REQUEST) |
| 186 | |
| 187 | # Update the task with the new information |
| 188 | task.console += "Importing {} images...\n".format(len(files)) |
| 189 | task.images_count = len(files) |
| 190 | task.pending_action = pending_actions.IMPORT |
| 191 | task.save() |
| 192 | |
| 193 | # Associate the folder url with the project and task |
| 194 | combined_id = "{}_{}".format(project_pk, pk) |
| 195 | |
| 196 | datastore = get_current_plugin().get_global_data_store() |
| 197 | datastore.set_json(combined_id, { |
| 198 | "ddbUrl": ddb_url, |
| 199 | "token": ddb.token, |
| 200 | "ddbWebUrl": "{}/r/{}/{}/{}".format(to_web_protocol(registry_url), orgSlug, dsSlug, folder.rstrip('/')) |
| 201 | }) |
| 202 | |
| 203 | #ddb.refresh_token() |
| 204 | |
| 205 | # Start importing the files in the background |
| 206 | serialized = {'token': ddb.token, 'files': files} |
| 207 | run_function_async(import_files, task.id, serialized) |
| 208 | |
| 209 | return Response({}, status=status.HTTP_200_OK) |
| 210 | |
| 211 | def import_files(task_id, carrier): |
| 212 | import requests |
nothing calls this directly
no test coverage detected