MCPcopy
hub / github.com/WebODM/WebODM / post

Method post

coreplugins/dronedb/api_views.py:164–209  ·  view source on GitHub ↗
(self, request, project_pk=None, pk=None)

Source from the content-addressed store, hash-verified

162
163class 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
211def import_files(task_id, carrier):
212 import requests

Callers

nothing calls this directly

Calls 15

get_files_listMethod · 0.95
parse_urlFunction · 0.90
DroneDBClass · 0.90
get_current_pluginFunction · 0.90
run_function_asyncFunction · 0.90
get_settingsFunction · 0.85
update_tokenFunction · 0.85
is_validFunction · 0.85
to_web_protocolFunction · 0.85
get_and_check_taskMethod · 0.80
get_global_data_storeMethod · 0.80
set_jsonMethod · 0.80

Tested by

no test coverage detected