|
4 | 4 | """ |
5 | 5 |
|
6 | 6 | import logging |
| 7 | +import typing |
7 | 8 |
|
8 | 9 | from django.core.management.base import BaseCommand |
| 10 | +from django.db import models |
9 | 11 |
|
10 | 12 | from ami.exports import by_capture |
11 | 13 | from ami.exports.base import write_export |
|
16 | 18 | class Command(BaseCommand): |
17 | 19 | help = "Export data by capture" |
18 | 20 |
|
19 | | - def handle(self, *args, **options): |
20 | | - # for i, batch in enumerate(by_capture.get_data_in_batches()) |
21 | | - # # print(f"Processing batch {batch}") |
22 | | - # print(f"Processing batch {i}") |
| 21 | + def add_arguments(self, parser) -> None: |
| 22 | + parser.add_argument( |
| 23 | + "--project-id", |
| 24 | + type=int, |
| 25 | + required=True, |
| 26 | + help="Project ID to export data from", |
| 27 | + ) |
| 28 | + parser.add_argument( |
| 29 | + "--collection-ids", |
| 30 | + type=int, |
| 31 | + nargs="+", |
| 32 | + required=False, |
| 33 | + default=[], |
| 34 | + help="Collection IDs to export data from (space-separated list)", |
| 35 | + ) |
| 36 | + |
| 37 | + def handle(self, *args, **options) -> None: |
| 38 | + project_id: int = options["project_id"] |
| 39 | + collection_ids: list[int] = options["collection_ids"] |
| 40 | + |
| 41 | + qs = by_capture.get_queryset().filter(occurrence__project=project_id) |
| 42 | + if collection_ids: |
| 43 | + qs = qs.filter(source_image__collections__in=collection_ids) |
23 | 44 |
|
24 | 45 | fname = write_export( |
25 | 46 | "detections_by_determination_and_capture", |
26 | 47 | Serializer=by_capture.DetectionsByDeterminationAndCaptureTabularSerializer, |
27 | | - QuerySet=by_capture.get_queryset() |
28 | | - .filter(occurrence__project=85) |
29 | | - .filter(source_image__collections__in=[82, 79]), |
30 | | - # .filter(source_image__collections__in=[82]), |
| 48 | + QuerySet=typing.cast(models.QuerySet, qs), |
31 | 49 | ) |
32 | 50 | # get full path to the file |
33 | 51 | print(f"Exported to {fname}") |
|
0 commit comments