Skip to content

Commit

Permalink
Merge branch 'dev' into fix/add_None_grating_for_Floyds
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 authored Oct 4, 2023
2 parents 2072a6e + 4ca74b0 commit db7726b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ updates:
open-pull-requests-limit: 10
target-branch: dev
reviewers:
- dmcollom
- jchate6
- phycodurus
13 changes: 10 additions & 3 deletions tom_alerts/brokers/alerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,25 @@ def _clean_parameters(self, parameters):
def _request_alerts(self, parameters):
payload = self._clean_parameters(parameters)
logger.log(msg=f'Fetching alerts from ALeRCE with payload {payload}', level=logging.INFO)
args = urlencode(self._clean_parameters(parameters))
args = urlencode(payload)
response = requests.get(f'{ALERCE_SEARCH_URL}/objects/?count=false&{args}')
response.raise_for_status()
return response.json()

def fetch_alerts(self, parameters):
"""
Loop through pages of ALeRCE alerts until we reach the maximum pages requested.
This simply concatenates all alerts from n pages into a single iterable to be returned.
"""
response = self._request_alerts(parameters)
alerts = response['items']
broker_feedback = ''
if len(alerts) > 0 and response['page'] < parameters.get('max_pages', 1):
parameters['page'] = response.get('page') + 1
current_page = parameters.get('page', 1)
if len(alerts) > 0 and current_page < parameters.get('max_pages', 1):
# make new request for the next page. (by recursion)
parameters['page'] = current_page + 1
alerts += self.fetch_alerts(parameters)[0]
# Bottom out of recursion and return accumulated alerts
return iter(alerts), broker_feedback

def fetch_alert(self, id):
Expand Down
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 db7726b

Please sign in to comment.