Skip to content

Commit

Permalink
Merge branch 'dev' into fix/error-in-alerce-alert-cone-search
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 authored Oct 3, 2023
2 parents 19fd373 + 82891fa commit 7b46aa4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions tom_dataproducts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,30 @@ def get_success_url(self):
referer = urlparse(referer).path if referer else '/'
return referer

def delete(self, request, *args, **kwargs):
def form_valid(self, form):
"""
Method that handles DELETE requests for this view. First deletes all ``ReducedDatum`` objects associated with
the ``DataProduct``, then deletes the ``DataProduct``.
Method that handles DELETE requests for this view. It performs the following actions in order:
1. Deletes all ``ReducedDatum`` objects associated with the ``DataProduct``.
2. Deletes the file referenced by the ``DataProduct``.
3. Deletes the ``DataProduct`` object from the database.
:param request: Django POST request object
:type request: HttpRequest
:param form: Django form instance containing the data for the DELETE request.
:type form: django.forms.Form
:return: HttpResponseRedirect to the success URL.
:rtype: HttpResponseRedirect
"""
ReducedDatum.objects.filter(data_product=self.get_object()).delete()
self.get_object().data.delete()
return super().delete(request, *args, **kwargs)
# Fetch the DataProduct object
data_product = self.get_object()

# Delete associated ReducedDatum objects
ReducedDatum.objects.filter(data_product=data_product).delete()

# Delete the file reference.
data_product.data.delete()
# Delete the `DataProduct` object from the database.
data_product.delete()

return HttpResponseRedirect(self.get_success_url())

def get_context_data(self, *args, **kwargs):
"""
Expand Down
2 changes: 1 addition & 1 deletion tom_setup/management/commands/tom_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_target_type(self):
'2': 'NON_SIDEREAL'
}
options_str = ['{}) {}'.format(key, target_type) for key, target_type in allowed_types.items()]
prompt = 'Which target type will your project use? {} '.format(self.style.WARNING(", ".join(options_str)))
prompt = 'Which target type should be used as default? {} '.format(self.style.WARNING(", ".join(options_str)))
target_type = input(prompt)
try:
self.context['TARGET_TYPE'] = allowed_types[target_type]
Expand Down

0 comments on commit 7b46aa4

Please sign in to comment.