django-to-galaxy 0.7.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. django_to_galaxy/__init__.py +1 -0
  2. django_to_galaxy/admin/__init__.py +13 -0
  3. django_to_galaxy/admin/galaxy_element.py +6 -0
  4. django_to_galaxy/admin/galaxy_instance.py +26 -0
  5. django_to_galaxy/admin/galaxy_output_file.py +79 -0
  6. django_to_galaxy/admin/galaxy_user.py +183 -0
  7. django_to_galaxy/admin/history.py +91 -0
  8. django_to_galaxy/admin/invocation.py +154 -0
  9. django_to_galaxy/admin/tag.py +17 -0
  10. django_to_galaxy/admin/utils.py +116 -0
  11. django_to_galaxy/admin/workflow.py +131 -0
  12. django_to_galaxy/api/__init__.py +0 -0
  13. django_to_galaxy/api/serializers/asymetricslugrelatedfield.py +31 -0
  14. django_to_galaxy/api/serializers/create_dataset_collection.py +118 -0
  15. django_to_galaxy/api/serializers/create_history.py +6 -0
  16. django_to_galaxy/api/serializers/galaxy_instance.py +10 -0
  17. django_to_galaxy/api/serializers/galaxy_output_file.py +17 -0
  18. django_to_galaxy/api/serializers/galaxy_user.py +20 -0
  19. django_to_galaxy/api/serializers/history.py +17 -0
  20. django_to_galaxy/api/serializers/invocation.py +22 -0
  21. django_to_galaxy/api/serializers/invoke_workflow.py +24 -0
  22. django_to_galaxy/api/serializers/upload_to_history.py +25 -0
  23. django_to_galaxy/api/serializers/workflow.py +41 -0
  24. django_to_galaxy/api/urls.py +53 -0
  25. django_to_galaxy/api/views/create_dataset_collection.py +461 -0
  26. django_to_galaxy/api/views/create_history.py +23 -0
  27. django_to_galaxy/api/views/galaxy_instance.py +13 -0
  28. django_to_galaxy/api/views/galaxy_output_file.py +15 -0
  29. django_to_galaxy/api/views/galaxy_user.py +13 -0
  30. django_to_galaxy/api/views/history.py +14 -0
  31. django_to_galaxy/api/views/invocation.py +45 -0
  32. django_to_galaxy/api/views/invoke_workflow.py +181 -0
  33. django_to_galaxy/api/views/upload_to_history.py +78 -0
  34. django_to_galaxy/api/views/workflow.py +14 -0
  35. django_to_galaxy/apps.py +6 -0
  36. django_to_galaxy/migrations/0001_new_initial.py +171 -0
  37. django_to_galaxy/migrations/0002_rename_state_history_galaxy_state_and_more.py +37 -0
  38. django_to_galaxy/migrations/0003_invocation_create_time.py +20 -0
  39. django_to_galaxy/migrations/0004_alter_galaxyuser_email_galaxyoutputfile.py +46 -0
  40. django_to_galaxy/migrations/0005_alter_galaxyoutputfile_invocation_and_more.py +37 -0
  41. django_to_galaxy/migrations/0006_tag_history_tags_workflow_tags.py +42 -0
  42. django_to_galaxy/migrations/0007_format_alter_history_tags_alter_workflow_tags_and_more.py +63 -0
  43. django_to_galaxy/migrations/0008_workflowinput_label.py +21 -0
  44. django_to_galaxy/migrations/0009_galaxyoutputfile_unique_galaxy_id_per_invocation.py +20 -0
  45. django_to_galaxy/migrations/0010_workflow__is_meta_workflow__step_jobs_count.py +23 -0
  46. django_to_galaxy/migrations/0011_rename__step_jobs_count_workflow__step_count_and_more.py +23 -0
  47. django_to_galaxy/migrations/0012_workflowinput_collection_type_and_more.py +136 -0
  48. django_to_galaxy/migrations/__init__.py +0 -0
  49. django_to_galaxy/models/__init__.py +8 -0
  50. django_to_galaxy/models/accepted_input.py +139 -0
  51. django_to_galaxy/models/galaxy_element.py +52 -0
  52. django_to_galaxy/models/galaxy_instance.py +29 -0
  53. django_to_galaxy/models/galaxy_output_file.py +53 -0
  54. django_to_galaxy/models/galaxy_user.py +94 -0
  55. django_to_galaxy/models/history.py +73 -0
  56. django_to_galaxy/models/invocation.py +251 -0
  57. django_to_galaxy/models/workflow.py +440 -0
  58. django_to_galaxy/schemas/__init__.py +0 -0
  59. django_to_galaxy/schemas/dataset.py +16 -0
  60. django_to_galaxy/settings.py +8 -0
  61. django_to_galaxy/templates/admin/import_workflows.html +89 -0
  62. django_to_galaxy/urls.py +3 -0
  63. django_to_galaxy/utils.py +61 -0
  64. django_to_galaxy/version.py +3 -0
  65. django_to_galaxy-0.7.0.0.dist-info/METADATA +17 -0
  66. django_to_galaxy-0.7.0.0.dist-info/RECORD +68 -0
  67. django_to_galaxy-0.7.0.0.dist-info/WHEEL +4 -0
  68. django_to_galaxy-0.7.0.0.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,461 @@
1
+ from django.core.exceptions import ObjectDoesNotExist
2
+ from drf_yasg.utils import swagger_auto_schema
3
+ from drf_yasg import openapi
4
+ from rest_framework.response import Response
5
+
6
+ from rest_framework.generics import GenericAPIView
7
+ from rest_framework.status import HTTP_404_NOT_FOUND
8
+
9
+ from django_to_galaxy.models import History
10
+ from django_to_galaxy.api.serializers.create_dataset_collection import (
11
+ CollectionListSerializer,
12
+ CollectionListPairedSerializer,
13
+ CollectionPairedSerializer,
14
+ )
15
+
16
+ from bioblend import ConnectionError
17
+
18
+ example_payload_list = {
19
+ "200": openapi.Response(
20
+ description="Dataset collection created successfully.",
21
+ examples={
22
+ "application/json": {
23
+ "summary": "Example payload",
24
+ "description": "An example of a payload to create a dataset collection.",
25
+ "value": {
26
+ "history_id": 1,
27
+ "collection_name": "My Dataset Collection",
28
+ "elements_names": ["dataset1", "dataset2"],
29
+ "elements_ids": ["f4b5e6d8a9c0b1e2", "a1b2c3d4e5f60708"],
30
+ },
31
+ }
32
+ },
33
+ )
34
+ }
35
+
36
+ example_payload_list_paired = {
37
+ "200": openapi.Response(
38
+ description="Dataset collection created successfully.",
39
+ examples={
40
+ "application/json": {
41
+ "summary": "Example payload",
42
+ "description": "An example of a payload to create a paired dataset collection.",
43
+ "value": {
44
+ "history_id": 1,
45
+ "collection_name": "My Paired Collection",
46
+ "pairs_names": ["pair1", "pair2"],
47
+ "first_elements_ids": ["id1", "id2"],
48
+ "second_elements_ids": ["id3", "id4"],
49
+ },
50
+ }
51
+ },
52
+ )
53
+ }
54
+
55
+ example_payload_paired = {
56
+ "200": openapi.Response(
57
+ description="Dataset collection created successfully.",
58
+ examples={
59
+ "application/json": {
60
+ "summary": "Example payload",
61
+ "description": "An example of a payload to create a paired dataset collection.",
62
+ "value": {
63
+ "history_id": 1,
64
+ "collection_name": "My Paired Collection",
65
+ "first_element_id": "id1",
66
+ "second_element_id": "id2",
67
+ },
68
+ }
69
+ },
70
+ )
71
+ }
72
+
73
+
74
+ class CreateDatasetListCollectionView(GenericAPIView):
75
+ """
76
+ API endpoint to create a dataset collection (list) in a Galaxy history.
77
+
78
+ - POST: Creates a dataset collection in a specified Galaxy history.
79
+ - Serializer: CollectionListSerializer
80
+ - Returns: JSON response with collection details or connection errors.
81
+ """
82
+
83
+ serializer_class = CollectionListSerializer
84
+
85
+ @swagger_auto_schema(
86
+ operation_description="Create a dataset collection with dataset of an Galaxy history.",
87
+ operation_summary="Create a dataset collection with dataset of an Galaxy history.",
88
+ tags=["collections"],
89
+ responses=example_payload_list,
90
+ request_body=openapi.Schema(
91
+ type=openapi.TYPE_OBJECT,
92
+ properties={
93
+ "history_id": openapi.Schema(type=openapi.TYPE_INTEGER, example=1),
94
+ "collection_name": openapi.Schema(
95
+ type=openapi.TYPE_STRING, example="My Dataset Collection"
96
+ ),
97
+ "elements_names": openapi.Schema(
98
+ type=openapi.TYPE_ARRAY,
99
+ items=openapi.Items(type=openapi.TYPE_STRING),
100
+ example=["dataset1", "dataset2"],
101
+ ),
102
+ "elements_ids": openapi.Schema(
103
+ type=openapi.TYPE_ARRAY,
104
+ items=openapi.Items(type=openapi.TYPE_STRING),
105
+ example=["f4b5e6d8a9c0b1e2", "a1b2c3d4e5f60708"],
106
+ ),
107
+ },
108
+ required=[
109
+ "history_id",
110
+ "collection_name",
111
+ "elements_names",
112
+ "elements_ids",
113
+ ],
114
+ ),
115
+ )
116
+ def post(self, request):
117
+ serializer_class = self.get_serializer_class()
118
+ serializer = serializer_class(data=request.data, context={"request": request})
119
+ serializer.is_valid(raise_exception=True)
120
+ data = serializer.data
121
+ # Retrieve history
122
+ try:
123
+ history = History.objects.get(id=data["history_id"])
124
+ except ObjectDoesNotExist:
125
+ return Response(
126
+ {
127
+ "message": (
128
+ "Galaxy history with id ",
129
+ f"<{data['history_id']}> not found!",
130
+ )
131
+ },
132
+ status=HTTP_404_NOT_FOUND,
133
+ )
134
+ # Collect ConnectionError exceptions
135
+ connection_errors = []
136
+ datasets = []
137
+ # Check each dataset id
138
+ for i in range(len(data.get("elements_names", []))):
139
+ try:
140
+ dataset = history.galaxy_owner.obj_gi.gi.datasets.show_dataset(
141
+ data["elements_ids"][i]
142
+ )
143
+ datasets.append(dataset)
144
+ except ConnectionError as e:
145
+ connection_errors.append(
146
+ {
147
+ "index": i,
148
+ "type": "elements_ids",
149
+ "id": data["elements_ids"][i],
150
+ "error": str(e),
151
+ }
152
+ )
153
+ datasets.append(None)
154
+
155
+ # If any errors, return them as final response
156
+ if connection_errors:
157
+ return Response({"connection_errors": connection_errors}, status=400)
158
+
159
+ # Retrieve file & file path
160
+ collection_datamap = {
161
+ "name": data["collection_name"],
162
+ "collection_type": "list",
163
+ "element_identifiers": [],
164
+ }
165
+
166
+ for i in range(len(data.get("elements_names", []))):
167
+ if datasets[i] is not None:
168
+ collection_datamap["element_identifiers"].append(
169
+ {
170
+ "name": data["elements_names"][i],
171
+ "src": "hda",
172
+ "id": data["elements_ids"][i],
173
+ }
174
+ )
175
+ try:
176
+ history_association = history.galaxy_history.create_dataset_collection(
177
+ collection_description=collection_datamap
178
+ )
179
+ except ConnectionError as e:
180
+ connection_errors.append(
181
+ {"type": "create_dataset_collection", "error": str(e)}
182
+ )
183
+ return Response({"connection_errors": connection_errors}, status=400)
184
+
185
+ message = (
186
+ "Collection of list of dataset has "
187
+ f"been created to Galaxy History <{str(history)}>"
188
+ )
189
+ return Response(
190
+ {
191
+ "message": message,
192
+ "history_association_id": history_association.id,
193
+ "history_id": history.id,
194
+ }
195
+ )
196
+
197
+
198
+ class CreateDatasetListPairedCollectionView(GenericAPIView):
199
+ """
200
+ API endpoint to create a paired dataset collection (list:paired) in a Galaxy history.
201
+
202
+ - POST: Creates a paired dataset collection in a specified Galaxy history.
203
+ - Serializer: CollectionListPairedSerializer
204
+ - Returns: JSON response with collection details or connection errors.
205
+ """
206
+
207
+ serializer_class = CollectionListPairedSerializer
208
+
209
+ @swagger_auto_schema(
210
+ operation_description=(
211
+ "Create a paired dataset collection " "(list:paired) in a Galaxy history."
212
+ ),
213
+ operation_summary="Create a paired dataset collection (list:paired) in a Galaxy history.",
214
+ tags=["collections"],
215
+ responses=example_payload_list_paired,
216
+ request_body=openapi.Schema(
217
+ type=openapi.TYPE_OBJECT,
218
+ properties={
219
+ "history_id": openapi.Schema(type=openapi.TYPE_INTEGER, example=1),
220
+ "collection_name": openapi.Schema(
221
+ type=openapi.TYPE_STRING, example="My Paired Collection"
222
+ ),
223
+ "pairs_names": openapi.Schema(
224
+ type=openapi.TYPE_ARRAY,
225
+ items=openapi.Items(type=openapi.TYPE_STRING),
226
+ example=["pair1", "pair2"],
227
+ ),
228
+ "first_elements_ids": openapi.Schema(
229
+ type=openapi.TYPE_ARRAY,
230
+ items=openapi.Items(type=openapi.TYPE_STRING),
231
+ example=["id1", "id2"],
232
+ ),
233
+ "second_elements_ids": openapi.Schema(
234
+ type=openapi.TYPE_ARRAY,
235
+ items=openapi.Items(type=openapi.TYPE_STRING),
236
+ example=["id3", "id4"],
237
+ ),
238
+ },
239
+ required=[
240
+ "history_id",
241
+ "collection_name",
242
+ "pairs_names",
243
+ "first_elements_ids",
244
+ "second_elements_ids",
245
+ ],
246
+ ),
247
+ )
248
+ def post(self, request):
249
+ serializer_class = self.get_serializer_class()
250
+ serializer = serializer_class(data=request.data, context={"request": request})
251
+ serializer.is_valid(raise_exception=True)
252
+ data = serializer.data
253
+ # Retrieve history
254
+ try:
255
+ history = History.objects.get(id=data["history_id"])
256
+ except ObjectDoesNotExist:
257
+ return Response(
258
+ {
259
+ "message": (
260
+ "Galaxy history with id ",
261
+ f"<{data['history_id']}> not found!",
262
+ )
263
+ },
264
+ status=HTTP_404_NOT_FOUND,
265
+ )
266
+ # Collect ConnectionError exceptions
267
+ connection_errors = []
268
+ first_datasets = []
269
+ second_datasets = []
270
+ # Check each dataset id
271
+ for i in range(len(data.get("pairs_names", []))):
272
+ try:
273
+ first_dataset = history.galaxy_owner.obj_gi.gi.datasets.show_dataset(
274
+ data["first_elements_ids"][i]
275
+ )
276
+ first_datasets.append(first_dataset)
277
+ except ConnectionError as e:
278
+ connection_errors.append(
279
+ {
280
+ "index": i,
281
+ "type": "first_elements_ids",
282
+ "id": data["first_elements_ids"][i],
283
+ "error": str(e),
284
+ }
285
+ )
286
+ first_datasets.append(None)
287
+ try:
288
+ second_dataset = history.galaxy_owner.obj_gi.gi.datasets.show_dataset(
289
+ data["second_elements_ids"][i]
290
+ )
291
+ second_datasets.append(second_dataset)
292
+ except ConnectionError as e:
293
+ connection_errors.append(
294
+ {
295
+ "index": i,
296
+ "type": "second_elements_ids",
297
+ "id": data["second_elements_ids"][i],
298
+ "error": str(e),
299
+ }
300
+ )
301
+ second_datasets.append(None)
302
+
303
+ # If any errors, return them as final response
304
+ if connection_errors:
305
+ return Response({"connection_errors": connection_errors}, status=400)
306
+
307
+ # Retrieve file & file path
308
+ collection_datamap = {
309
+ "name": data["collection_name"],
310
+ "collection_type": "list:paired",
311
+ "element_identifiers": [],
312
+ }
313
+
314
+ for i in range(len(data.get("pairs_names", []))):
315
+ if first_datasets[i] is not None and second_datasets[i] is not None:
316
+ collection_datamap["element_identifiers"].append(
317
+ {
318
+ "name": data["pairs_names"][i],
319
+ "src": "new_collection",
320
+ "collection_type": "paired",
321
+ "element_identifiers": [
322
+ {
323
+ "name": "forward",
324
+ "src": "hda",
325
+ "id": data["first_elements_ids"][i],
326
+ },
327
+ {
328
+ "name": "reverse",
329
+ "src": "hda",
330
+ "id": data["second_elements_ids"][i],
331
+ },
332
+ ],
333
+ }
334
+ )
335
+
336
+ try:
337
+ history_association = history.galaxy_history.create_dataset_collection(
338
+ collection_description=collection_datamap
339
+ )
340
+ except ConnectionError as e:
341
+ connection_errors.append(
342
+ {"type": "create_dataset_collection", "error": str(e)}
343
+ )
344
+ return Response({"connection_errors": connection_errors}, status=400)
345
+
346
+ message = (
347
+ "Collection of paired dataset has been "
348
+ f"created to Galaxy History <{str(history)}>"
349
+ )
350
+ return Response(
351
+ {
352
+ "message": message,
353
+ "history_association_id": history_association.id,
354
+ "history_id": history.id,
355
+ }
356
+ )
357
+
358
+
359
+ class CreateDatasetPairedCollectionView(GenericAPIView):
360
+ """
361
+ API endpoint to create a paired dataset collection in a Galaxy history.
362
+
363
+ - POST: Creates a paired dataset collection in a specified Galaxy history.
364
+ - Serializer: CollectionPairedSerializer
365
+ - Returns: JSON response with collection details or connection errors.
366
+ """
367
+
368
+ serializer_class = CollectionPairedSerializer
369
+
370
+ @swagger_auto_schema(
371
+ operation_description="Create a paired dataset collection in a Galaxy history.",
372
+ operation_summary="Create a paired dataset collection in a Galaxy history.",
373
+ tags=["collections"],
374
+ responses=example_payload_paired,
375
+ request_body=openapi.Schema(
376
+ type=openapi.TYPE_OBJECT,
377
+ properties={
378
+ "history_id": openapi.Schema(type=openapi.TYPE_INTEGER, example=1),
379
+ "collection_name": openapi.Schema(
380
+ type=openapi.TYPE_STRING, example="My Paired Collection"
381
+ ),
382
+ "first_element_id": openapi.Schema(
383
+ type=openapi.TYPE_STRING, example="id1"
384
+ ),
385
+ "second_element_id": openapi.Schema(
386
+ type=openapi.TYPE_STRING, example="id2"
387
+ ),
388
+ },
389
+ required=[
390
+ "history_id",
391
+ "collection_name",
392
+ "first_element_id",
393
+ "second_element_id",
394
+ ],
395
+ ),
396
+ )
397
+ def post(self, request):
398
+ serializer_class = self.get_serializer_class()
399
+ serializer = serializer_class(data=request.data, context={"request": request})
400
+ serializer.is_valid(raise_exception=True)
401
+ data = serializer.data
402
+ # Retrieve history
403
+ try:
404
+ history = History.objects.get(id=data["history_id"])
405
+ except ObjectDoesNotExist:
406
+ return Response(
407
+ {
408
+ "message": (
409
+ "Galaxy history with id ",
410
+ f"<{data['history_id']}> not found!",
411
+ )
412
+ },
413
+ status=HTTP_404_NOT_FOUND,
414
+ )
415
+
416
+ # Check each dataset id
417
+ try:
418
+ history.galaxy_owner.obj_gi.gi.datasets.show_dataset(
419
+ data["first_element_id"]
420
+ )
421
+ except ConnectionError:
422
+ return Response({"message": "first_element_id is not valid"}, status=400)
423
+
424
+ try:
425
+ history.galaxy_owner.obj_gi.gi.datasets.show_dataset(
426
+ data["second_element_id"]
427
+ )
428
+ except ConnectionError:
429
+ return Response({"message": "second_element_id is not valid"}, status=400)
430
+
431
+ # Retrieve file & file path
432
+ collection_datamap = {
433
+ "name": data["collection_name"],
434
+ "collection_type": "paired",
435
+ "element_identifiers": [
436
+ {"name": "forward", "src": "hda", "id": data["first_element_id"]},
437
+ {"name": "reverse", "src": "hda", "id": data["second_element_id"]},
438
+ ],
439
+ }
440
+
441
+ try:
442
+ history_association = history.galaxy_history.create_dataset_collection(
443
+ collection_description=collection_datamap
444
+ )
445
+ except ConnectionError as e:
446
+ return Response(
447
+ {"message": str(e)},
448
+ status=400,
449
+ )
450
+ message = (
451
+ "Collection of paired dataset has been "
452
+ f"created to Galaxy History <{str(history)}>"
453
+ )
454
+
455
+ return Response(
456
+ {
457
+ "message": message,
458
+ "history_association_id": history_association.id,
459
+ "history_id": history.id,
460
+ }
461
+ )
@@ -0,0 +1,23 @@
1
+ from drf_yasg.utils import swagger_auto_schema
2
+ from rest_framework.response import Response
3
+ from rest_framework.generics import RetrieveAPIView
4
+
5
+ from django_to_galaxy.models import GalaxyUser
6
+ from django_to_galaxy.api.serializers.create_history import HistoryCreatedSerializer
7
+
8
+
9
+ class CreateHistoryView(RetrieveAPIView):
10
+ queryset = GalaxyUser.objects.all()
11
+ serializer_class = None
12
+
13
+ @swagger_auto_schema(
14
+ operation_description="Create history from a user.",
15
+ operation_summary="Create history from a user.",
16
+ tags=["galaxy_users"],
17
+ responses={200: HistoryCreatedSerializer},
18
+ )
19
+ def get(self, request, *args, **kwargs):
20
+ instance = self.get_object()
21
+ history = instance.create_history()
22
+ message = f"{str(history)} for {str(instance)} has been successfully created."
23
+ return Response(data={"message": message, "history_id": history.id})
@@ -0,0 +1,13 @@
1
+ from rest_framework import viewsets
2
+
3
+ from django_to_galaxy.models.galaxy_instance import GalaxyInstance
4
+ from django_to_galaxy.api.serializers.galaxy_instance import GalaxyInstanceSerializer
5
+
6
+
7
+ class GalaxyInstanceViewSet(viewsets.ModelViewSet):
8
+ """
9
+ API endpoint that allows different galaxy instances to be viewed and edited.
10
+ """
11
+
12
+ queryset = GalaxyInstance.objects.all()
13
+ serializer_class = GalaxyInstanceSerializer
@@ -0,0 +1,15 @@
1
+ from rest_framework import viewsets
2
+
3
+ from django_to_galaxy.models.galaxy_output_file import GalaxyOutputFile
4
+ from django_to_galaxy.api.serializers.galaxy_output_file import (
5
+ GalaxyOutputFileSerializer,
6
+ )
7
+
8
+
9
+ class GalaxyOutputFileViewSet(viewsets.ReadOnlyModelViewSet):
10
+ """
11
+ API endpoint that allows histories to be viewed.
12
+ """
13
+
14
+ queryset = GalaxyOutputFile.objects.all()
15
+ serializer_class = GalaxyOutputFileSerializer
@@ -0,0 +1,13 @@
1
+ from rest_framework import viewsets
2
+
3
+ from django_to_galaxy.models.galaxy_user import GalaxyUser
4
+ from django_to_galaxy.api.serializers.galaxy_user import GalaxyUserSerializer
5
+
6
+
7
+ class GalaxyUserViewSet(viewsets.ModelViewSet):
8
+ """
9
+ API endpoint that allows galaxy users to be viewed and edited.
10
+ """
11
+
12
+ queryset = GalaxyUser.objects.select_related("galaxy_instance")
13
+ serializer_class = GalaxyUserSerializer
@@ -0,0 +1,14 @@
1
+ from rest_framework import viewsets
2
+
3
+ from django_to_galaxy.models.history import History
4
+ from django_to_galaxy.api.serializers.history import HistorySerializer
5
+
6
+
7
+ class HistoryViewSet(viewsets.ReadOnlyModelViewSet):
8
+ """
9
+ API endpoint that allows histories to be viewed.
10
+ """
11
+
12
+ queryset = History.objects.all()
13
+ lookup_field = "galaxy_id"
14
+ serializer_class = HistorySerializer
@@ -0,0 +1,45 @@
1
+ from drf_yasg.utils import swagger_auto_schema
2
+ from rest_framework import viewsets
3
+ from rest_framework.response import Response
4
+ from rest_framework.generics import RetrieveAPIView
5
+
6
+ from django_to_galaxy.models.invocation import Invocation
7
+ from django_to_galaxy.api.serializers.invocation import (
8
+ InvocationSerializer,
9
+ UpdateOutputFilesResponseSerializer,
10
+ )
11
+
12
+
13
+ class InvocationViewSet(viewsets.ReadOnlyModelViewSet):
14
+ """
15
+ API endpoint that allows histories to be viewed.
16
+ """
17
+
18
+ queryset = Invocation.objects.all()
19
+ serializer_class = InvocationSerializer
20
+
21
+
22
+ class UpdateOutputFilesView(RetrieveAPIView):
23
+ queryset = Invocation.objects.all()
24
+ serializer_class = UpdateOutputFilesResponseSerializer
25
+
26
+ @swagger_auto_schema(
27
+ operation_description="Update output files from an invocation.",
28
+ operation_summary="Update output files from an invocation.",
29
+ tags=["invocations"],
30
+ responses={200: UpdateOutputFilesResponseSerializer},
31
+ )
32
+ def get(self, request, *args, **kwargs):
33
+ instance = self.get_object()
34
+ instance.update_output_files()
35
+ output_files = instance.output_files.all()
36
+ message = (
37
+ f"output file(s) ({len(output_files)}) for {str(instance)}"
38
+ " have been successfully updated."
39
+ )
40
+ return Response(
41
+ data={
42
+ "message": message,
43
+ "galaxy_output_file_ids": [f.id for f in output_files],
44
+ }
45
+ )