-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add observation deletion functionality.
- Implement unified method for deleting observations and associated data products. - Resolve bug preventing deletion of thumbnails. - Introduce new template for observation deletion process.
- Loading branch information
Showing
7 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Union | ||
|
||
from tom_dataproducts.models import DataProduct, ReducedDatum | ||
from tom_observations.models import ObservationRecord | ||
|
||
|
||
def delete_associated_data_products(record_or_product: Union[ObservationRecord, DataProduct]) -> None: | ||
""" | ||
Utility function to delete associated DataProducts or a single DataProduct. | ||
Parameters | ||
---------- | ||
record_or_product : Union[ObservationRecord, DataProduct] | ||
The ObservationRecord object to find associated DataProducts, | ||
or a single DataProduct to be deleted. | ||
""" | ||
if isinstance(record_or_product, ObservationRecord): | ||
query = DataProduct.objects.filter(observation_record=record_or_product) | ||
elif isinstance(record_or_product, DataProduct): | ||
query = [record_or_product] | ||
else: | ||
raise ValueError("Invalid argument type. Must be ObservationRecord or DataProduct.") | ||
|
||
for data_product in query: | ||
# Delete associated ReducedDatum objects. | ||
ReducedDatum.objects.filter(data_product=data_product).delete() | ||
|
||
# Delete the file from the disk. | ||
data_product.data.delete() | ||
|
||
# Delete thumbnail from the disk. | ||
data_product.thumbnail.delete() | ||
|
||
# Delete the `DataProduct` object from the database. | ||
data_product.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tom_observations/templates/tom_observations/observationrecord_confirm_delete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends 'tom_common/base.html' %} | ||
{% load bootstrap4 %} | ||
{% block title %}Confirm delete{% endblock %} | ||
{% block content %} | ||
<h3>Confirm Delete</h3> | ||
<form method="post">{% csrf_token %} | ||
<p>Are you sure you want to delete observation ID {{ object.observation_id }} for target {{ object }}"?</p> | ||
{% buttons %} | ||
<button type="submit" class="btn btn-danger">Confirm</button> | ||
{% endbuttons %} | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters